Esempio n. 1
0
def test_lowpass(Simulator, plt, seed):
    dt = 1e-3
    tau = 0.03

    t, x, yhat = run_synapse(Simulator, seed, Lowpass(tau), dt=dt)
    y = filt(x, tau, dt=dt)

    assert allclose(t, y, yhat, delay=dt, plt=plt)
Esempio n. 2
0
def test_lowpass(Simulator, plt, seed):
    dt = 1e-3
    tau = 0.03

    t, x, yhat = run_synapse(Simulator, seed, Lowpass(tau), dt=dt)
    y = filt(x, tau, dt=dt)

    assert allclose(t, y, yhat, delay=dt, plt=plt)
Esempio n. 3
0
def test_filtfilt(plt, rng):
    dt = 1e-3
    tend = 3.
    t = dt * np.arange(tend / dt)
    nt = len(t)

    tau = 0.03

    u = rng.normal(size=nt)
    x = filt(u, tau, dt=dt)
    x = filt(x[::-1], tau, x0=x[-1], dt=dt)[::-1]
    y = filtfilt(u, tau, dt=dt)

    plt.plot(t, x)
    plt.plot(t, y, '--')

    assert np.allclose(x, y)
Esempio n. 4
0
def test_decoders(Simulator, plt, seed):
    dt = 1e-3
    tau = 0.01

    t, x, yhat = run_synapse(Simulator, seed, Lowpass(tau), dt=dt, n_neurons=100)

    y = filt(x, tau, dt=dt)
    assert allclose(t, y, yhat, delay=dt, plt=plt)
Esempio n. 5
0
def test_filtfilt(plt, rng):
    dt = 1e-3
    tend = 3.
    t = dt * np.arange(tend / dt)
    nt = len(t)

    tau = 0.03

    u = rng.normal(size=nt)
    x = filt(u, tau, dt=dt)
    x = filt(x[::-1], tau, x0=x[-1], dt=dt)[::-1]
    y = filtfilt(u, tau, dt=dt)

    plt.plot(t, x)
    plt.plot(t, y, '--')

    assert np.allclose(x, y)
Esempio n. 6
0
def test_alpha(Simulator, plt, seed):
    dt = 1e-3
    tau = 0.03
    num, den = [1], [tau**2, 2*tau, 1]

    t, x, yhat = run_synapse(Simulator, seed, Alpha(tau), dt=dt)
    y = filt(x, LinearFilter(num, den), dt=dt)

    assert allclose(t, y, yhat, delay=dt, atol=5e-6, plt=plt)
Esempio n. 7
0
def test_lti_lowpass(rng, plt):
    dt = 1e-3
    tend = 3.
    t = dt * np.arange(tend / dt)
    nt = len(t)

    tau = 1e-2
    lti = LinearFilter([1], [tau, 1])

    u = rng.normal(size=(nt, 10))
    x = filt(u, tau, dt=dt)
    y = filt(u, lti, dt=dt)

    plt.plot(t, x[:, 0], label="Lowpass")
    plt.plot(t, y[:, 0], label="LTI")
    plt.legend(loc="best")

    assert np.allclose(x, y)
Esempio n. 8
0
def test_lti_lowpass(rng, plt):
    dt = 1e-3
    tend = 3.
    t = dt * np.arange(tend / dt)
    nt = len(t)

    tau = 1e-2
    lti = LinearFilter([1], [tau, 1])

    u = rng.normal(size=(nt, 10))
    x = filt(u, tau, dt=dt)
    y = filt(u, lti, dt=dt)

    plt.plot(t, x[:, 0], label="Lowpass")
    plt.plot(t, y[:, 0], label="LTI")
    plt.legend(loc="best")

    assert np.allclose(x, y)
Esempio n. 9
0
def test_decoders(Simulator, plt, seed):
    dt = 1e-3
    tau = 0.01

    t, x, yhat = run_synapse(
        Simulator, seed, Lowpass(tau), dt=dt, n_neurons=100)

    y = filt(x, tau, dt=dt)
    assert allclose(t, y, yhat, delay=dt, plt=plt)
Esempio n. 10
0
def test_linearfilter(Simulator, plt, seed):
    dt = 1e-3

    # The following num, den are for a 4th order analog Butterworth filter,
    # generated with `scipy.signal.butter(4, 1. / 0.03, analog=True)`
    num = np.array([1234567.90123457])
    den = np.array([1.0, 87.104197658425107, 3793.5706248589954,
                    96782.441842694592, 1234567.9012345686])

    t, x, yhat = run_synapse(Simulator, seed, LinearFilter(num, den), dt=dt)
    y = filt(x, LinearFilter(num, den), dt=dt)

    assert allclose(t, y, yhat, delay=dt, plt=plt)
Esempio n. 11
0
def test_linearfilter(Simulator, plt, seed):
    dt = 1e-3

    # The following num, den are for a 4th order analog Butterworth filter,
    # generated with `scipy.signal.butter(4, 0.2, analog=False)`
    num = np.array([0.00482434, 0.01929737, 0.02894606, 0.01929737, 0.00482434])
    den = np.array([1.0, -2.36951301, 2.31398841, -1.05466541, 0.18737949])

    synapse = LinearFilter(num, den, analog=False)
    t, x, yhat = run_synapse(Simulator, seed, synapse, dt=dt)
    y = filt(x, synapse, dt=dt)

    assert allclose(t, y, yhat, delay=dt, plt=plt)
Esempio n. 12
0
def test_linearfilter(Simulator, plt, seed):
    dt = 1e-3

    # The following num, den are for a 4th order analog Butterworth filter,
    # generated with `scipy.signal.butter(4, 0.2, analog=False)`
    num = np.array(
        [0.00482434, 0.01929737, 0.02894606, 0.01929737, 0.00482434])
    den = np.array([1., -2.36951301, 2.31398841, -1.05466541, 0.18737949])

    synapse = LinearFilter(num, den, analog=False)
    t, x, yhat = run_synapse(Simulator, seed, synapse, dt=dt)
    y = filt(x, synapse, dt=dt)

    assert allclose(t, y, yhat, delay=dt, plt=plt)
Esempio n. 13
0
def test_triangle(Simulator, plt, seed):
    dt = 1e-3
    tau = 0.03

    t, x, ysim = run_synapse(Simulator, seed, Triangle(tau), dt=dt)
    yfilt = filt(x, Triangle(tau), dt=dt)

    # compare with convolved filter
    n_taps = int(round(tau / dt)) + 1
    num = np.arange(n_taps, 0, -1, dtype=float)
    num /= num.sum()
    y = np.convolve(x.ravel(), num)[:len(t)]
    y.shape = (-1, 1)

    assert np.allclose(y, yfilt, rtol=0)
    assert allclose(t, y, ysim, delay=dt, rtol=0, plt=plt)
Esempio n. 14
0
def test_filt(plt, rng):
    dt = 1e-3
    tend = 3.
    t = dt * np.arange(tend / dt)
    nt = len(t)

    tau = 0.1 / dt

    u = rng.normal(size=nt)

    tk = np.arange(0, 30 * tau)
    k = 1. / tau * np.exp(-tk / tau)
    x = np.convolve(u, k, mode='full')[:nt]

    y = filt(u, 0.1, dt=dt)

    plt.plot(t, x)
    plt.plot(t, y, '--')

    assert np.allclose(x, y, atol=1e-3, rtol=1e-2)
Esempio n. 15
0
def test_filt(plt, rng):
    dt = 1e-3
    tend = 3.
    t = dt * np.arange(tend / dt)
    nt = len(t)

    tau = 0.1 / dt

    u = rng.normal(size=nt)

    tk = np.arange(0, 30 * tau)
    k = 1. / tau * np.exp(-tk / tau)
    x = np.convolve(u, k, mode='full')[:nt]

    y = filt(u, 0.1, dt=dt)

    plt.plot(t, x)
    plt.plot(t, y, '--')

    assert np.allclose(x, y, atol=1e-3, rtol=1e-2)