Пример #1
0
def test_insert_theta():
    tau_in = [0.1, 1.0]
    epdf = exponentials.ExponentialPDF(tau=tau_in)
    theta_in = [0.2, 2., 0.3]
    epdf.theta = theta_in
    print(epdf.theta)
    print(epdf.pars)
    pars_in = [0.2, 2., 0.3, 0.7]
    npt.assert_almost_equal(epdf.pars, pars_in)
Пример #2
0
def test_fixed_pars():
    tau_in = [0.1, 1.0]
    epdf = exponentials.ExponentialPDF(tau=tau_in)
    epdf.fixed[1] = True
    fixed = [False, True, False, True]
    assert fixed == epdf.fixed
    theta_in = [0.2, 0.3]
    epdf.theta = theta_in
    print(epdf.theta)
    print(epdf.pars)
    pars_in = [0.2, 1., 0.3, 0.7]
    npt.assert_almost_equal(epdf.pars, pars_in)
    npt.assert_almost_equal(epdf.theta, theta_in)
Пример #3
0
def test_area_none():
    tau_in = [0.1, 1.0]
    epdf = exponentials.ExponentialPDF(tau=tau_in)
    area = np.ones(2) / 2
    print(epdf.area)
    npt.assert_almost_equal(epdf.area, area)
    pars = np.concatenate((np.asarray(tau_in), area))
    print(epdf.pars)
    npt.assert_almost_equal(epdf.pars, pars)
    print(epdf.fixed)
    fixed = [False, False, False, True]
    assert fixed == epdf.fixed
    print(epdf.theta)
    theta = pars[:-1]
    npt.assert_almost_equal(epdf.theta, theta)
Пример #4
0
def histogram_xlog_ysqrt_data(X,
                              tres,
                              pdf=None,
                              tcrit=None,
                              xlabel='Dwell times'):
    """ Plot dwell time histogram in log x and square root y. """
    xout, yout = prepare_xlog_hist(X, tres)
    fig = plt.figure(figsize=(3, 3))
    ax = fig.add_subplot(111)
    ax.semilogx(xout, np.sqrt(yout))
    ax.set_xlabel(xlabel)
    ax.set_ylabel('sqrt(frequency)')
    t = np.logspace(math.log10(tres), math.log10(2 * max(X)), 512)
    if pdf is None:
        pdf = exponentials.ExponentialPDF([np.mean(X)], [1.0])
    scale = __exponential_scale_factor(X, pdf, tres)
    ax.plot(t, np.sqrt(scale * t * pdf.exp(pdf.theta, t)), '-b')
    for ta, ar in zip(pdf.tau, pdf.area):
        ax.plot(t, np.sqrt(scale * t * (ar / ta) * np.exp(-t / ta)), '--b')

    if tcrit is not None:
        for tc in np.asarray(tcrit):
            ax.axvline(x=tc, color='g')
Пример #5
0
    def setUp(self):
        self.infile = "./tests/intervals.txt"
        self.intervals = np.loadtxt(self.infile)
        self.tau, self.area = [0.036, 1.1], [0.20]
        self.theta = self.tau + self.area
        self.epdf = exponentials.ExponentialPDF(self.tau, self.area)
        self.res = minimize(self.epdf.LL,
                            self.epdf.theta,
                            args=self.intervals,
                            method='Nelder-Mead')

        self.asd = errors.ApproximateSD(self.res.x, self.epdf.LL,
                                        self.intervals)
        #self.hess = asd.hess
        #self.hess = eklib.hessian(self.res.x, self.epdf.LL, self.intervals)
        #self.cov = eklib.covariance_matrix(self.theta, eklib.LLexp, self.intervals)
        #self.cov = asd.covariance
        #self.cov = nplin.inv(self.hess)
        #self.appSD = asd.sd #np.sqrt(self.cov.diagonal())
        #self.corr = asd.correlations #eklib.correlation_matrix(self.cov)
        m = 2.0  # corresponds roughly to 2 SD
        self.likints = errors.LikelihoodIntervals(self.res.x, self.epdf,
                                                  self.intervals, self.asd.sd,
                                                  m)