Ejemplo n.º 1
0
def test_1():
    x = generate_AR1(0.95, 1, 50**2 + 25, random_state=0)
    val = integrated_autocorr5(x, size='sqrt')[0]

    r.assign('x', x)
    ref = r('(bm(x)$se)^2 * length(x) / var(x)')[0]
    np.testing.assert_almost_equal(val, ref)
Ejemplo n.º 2
0
def test_1():
    x = generate_AR1(0.95, 1, 50**2+25, random_state=0)
    val = integrated_autocorr5(x, size='sqrt')[0]

    r.assign('x', x)
    ref = r('(bm(x)$se)^2 * length(x) / var(x)')[0]
    np.testing.assert_almost_equal(val, ref)
Ejemplo n.º 3
0
def test_1():
    x = generate_AR1(0.95, 1, 50**2 + 25, random_state=0)
    x2 = np.vstack((x, x)).T

    t1 = integrated_autocorr6(x)
    t2 = integrated_autocorr6(x2)
    assert t2.shape == (2, )
    assert t2[0] == t1 and t2[1] == t1[0]
Ejemplo n.º 4
0
def test_1():
    x = generate_AR1(0.95, 1, 50 ** 2 + 25, random_state=0)
    x2 = np.vstack((x, x)).T

    t1 = integrated_autocorr6(x)
    t2 = integrated_autocorr6(x2)
    assert t2.shape == (2,)
    assert t2[0] == t1 and t2[1] == t1[0]
Ejemplo n.º 5
0
def test_1():
    y = generate_AR1(0.95, 1, 10000)
    tau = integrated_autocorr3(y)

    r.assign('x', y)
    r('popvar = (var(x)*(nrow(x)-1)/nrow(x))')
    r('init = initseq(x)')
    tau_ref = r('initseq(x)$var.pos / popvar')[0]
    print(tau, tau_ref)
    np.testing.assert_array_almost_equal(tau, tau_ref)
Ejemplo n.º 6
0
def test_1():
    y = generate_AR1(0.95, 1, 10000)
    tau = integrated_autocorr3(y)

    r.assign('x', y)
    r('popvar = (var(x)*(nrow(x)-1)/nrow(x))')
    r('init = initseq(x)')
    tau_ref = r('initseq(x)$var.pos / popvar')[0]
    print(tau, tau_ref)
    np.testing.assert_array_almost_equal(tau, tau_ref)
Ejemplo n.º 7
0
def test_2():
    x = generate_AR1(0.95, 1, 50**2+25, random_state=0)
    x2 = np.vstack((x, x)).T
    val = integrated_autocorr5(x2, size='sqrt')
    assert val.shape == (2,)
    assert val[0] == val[1]
Ejemplo n.º 8
0
def test_2():
    y = generate_AR1(0.95, 1, 10000)
    y2 = np.vstack((y, y)).T
    tau = integrated_autocorr3(y2)
    assert tau.shape == (2, )
    assert tau[0] == tau[1]
Ejemplo n.º 9
0
def test_2():
    y = generate_AR1(0.95, 1, 10000)
    y2 = np.vstack((y, y)).T
    tau = integrated_autocorr3(y2)
    assert tau.shape == (2,)
    assert tau[0] == tau[1]
Ejemplo n.º 10
0
TRUE = 2 / (1 - PHI) - 1
n_steps = 1000000
grid = np.logspace(2, np.log10(n_steps), 10)

tau1 = []
tau2 = []
tau3 = []
tau4 = []
tau5 = []
tau6 = []

n_trials = 10
for i in range(n_trials):
    y = generate_AR1(phi=PHI,
                     sigma=1,
                     n_steps=n_steps,
                     c=0,
                     y0=0,
                     random_state=None)

    tau1.append([integrated_autocorr1(y[:n]) for n in grid])
    tau2.append([integrated_autocorr2(y[:n]) for n in grid])
    tau3.append([integrated_autocorr3(y[:n]) for n in grid])
    tau4.append([integrated_autocorr4(y[:n]) for n in grid])
    tau5.append([integrated_autocorr5(y[:n]) for n in grid])
    tau6.append([integrated_autocorr6(y[:n]) for n in grid])

pp.errorbar(grid,
            y=np.mean(tau1, axis=0),
            yerr=np.std(tau1, axis=0),
            c='b',
            label='tau 1')
Ejemplo n.º 11
0
def test_2():
    y = generate_AR1(phi=0.98, sigma=1, n_steps=1000, c=0, y0=0)
    y2 = np.vstack((y, y)).T
    val = integrated_autocorr4(y2)
    print(val)
Ejemplo n.º 12
0
def test_1():
    for i in range(10):
        y = generate_AR1(phi=0.98, sigma=1, n_steps=10000, c=0, y0=0)
        val = integrated_autocorr4(y)
        rval = integrated_autocorr4r(y)
        np.testing.assert_almost_equal(val, rval, decimal=2)
Ejemplo n.º 13
0
def setup():
    global SAMPLES
    SAMPLES = generate_AR1(PHI, 1, 10000, random_state=0).reshape(-1,1)
Ejemplo n.º 14
0
#      = 2/(1-phi) - 1
PHI = 0.98
TRUE = 2/(1-PHI) - 1
n_steps = 1000000
grid = np.logspace(2, np.log10(n_steps), 10)

tau1 = []
tau2 = []
tau3 = []
tau4 = []
tau5 = []
tau6 = []

n_trials = 10
for i in range(n_trials):
    y = generate_AR1(phi=PHI, sigma=1, n_steps=n_steps, c=0, y0=0, random_state=None)

    tau1.append([integrated_autocorr1(y[:n]) for n in grid])
    tau2.append([integrated_autocorr2(y[:n]) for n in grid])
    tau3.append([integrated_autocorr3(y[:n]) for n in grid])
    tau4.append([integrated_autocorr4(y[:n]) for n in grid])
    tau5.append([integrated_autocorr5(y[:n]) for n in grid])
    tau6.append([integrated_autocorr6(y[:n]) for n in grid])

pp.errorbar(grid, y=np.mean(tau1, axis=0), yerr=np.std(tau1, axis=0), c='b',    label='tau 1')
pp.errorbar(grid-1, y=np.mean(tau2, axis=0), yerr=np.std(tau2, axis=0), c='r',    label='tau 2')
pp.errorbar(grid-5, y=np.mean(tau3, axis=0), yerr=np.std(tau3, axis=0), c='g',    label='tau 3')
pp.errorbar(grid-10, y=np.mean(tau4, axis=0), yerr=np.std(tau4, axis=0), c='gold', label='tau 4')
pp.errorbar(grid-20, y=np.mean(tau5, axis=0), yerr=np.std(tau5, axis=0), c='m',    label='tau 5')
pp.errorbar(grid-30, y=np.mean(tau6, axis=0), yerr=np.std(tau6, axis=0), c='cyan', label='tau 6')
Ejemplo n.º 15
0
def test_2():
    x = generate_AR1(0.95, 1, 50**2 + 25, random_state=0)
    x2 = np.vstack((x, x)).T
    val = integrated_autocorr5(x2, size='sqrt')
    assert val.shape == (2, )
    assert val[0] == val[1]
Ejemplo n.º 16
0
def setup():
    global SAMPLES
    SAMPLES = generate_AR1(PHI, 1, 10000, random_state=0).reshape(-1, 1)