def test_brownnoise(Simulator, seed, plt): d = 5000 t = 0.5 std = 1.5 process = BrownNoise(dist=Gaussian(0, std)) with nengo.Network() as model: u = nengo.Node(process, size_out=d) up = nengo.Probe(u) with Simulator(model, seed=seed) as sim: sim.run(t) samples = sim.data[up] trange = sim.trange() expected_std = std * np.sqrt(trange) atol = 3.5 * expected_std / np.sqrt(d) plt.subplot(2, 1, 1) plt.title("Five Brown noise signals") plt.plot(trange, samples[:, :5]) plt.subplot(2, 1, 2) plt.ylabel("Standard deviation") plt.plot(trange, np.abs(np.std(samples, axis=1)), label="Actual") plt.plot(trange, expected_std, label="Expected") plt.legend(loc='best') assert np.all(np.abs(np.mean(samples, axis=1)) < atol) assert np.all(np.abs(np.std(samples, axis=1) - expected_std) < atol)
def test_processes(): assert ( repr(WhiteSignal(0.2, 10, rms=0.3)) == "WhiteSignal(period=0.2, high=10, rms=0.3)" ) check_init_args(WhiteNoise, ["dist", "scale"]) check_repr(WhiteNoise(scale=False)) assert repr(WhiteNoise()) == "WhiteNoise()" assert repr(WhiteNoise(scale=False)) == "WhiteNoise(scale=False)" check_init_args(FilteredNoise, ["synapse", "dist", "scale"]) check_repr(FilteredNoise(scale=False)) assert repr(FilteredNoise()) == "FilteredNoise()" assert repr(FilteredNoise(scale=False)) == "FilteredNoise(scale=False)" check_init_args(BrownNoise, ["dist"]) check_repr(BrownNoise()) assert repr(BrownNoise()) == "BrownNoise()" check_init_args(PresentInput, ["inputs", "presentation_time"]) check_repr(PresentInput(inputs=np.array([1.2, 3.4]), presentation_time=5)) assert ( repr(PresentInput((1.2, 3.4), 5)) == "PresentInput(inputs=array([1.2, 3.4]), presentation_time=5)" ) check_init_args(WhiteSignal, ["period", "high", "rms", "y0"]) check_repr(WhiteSignal(period=1.2, high=3.4, rms=5.6, y0=7.8)) assert repr(WhiteSignal(1, 2)) == "WhiteSignal(period=1, high=2)" assert ( repr(WhiteSignal(1.2, 3.4, 5.6, 7.8)) == "WhiteSignal(period=1.2, high=3.4, rms=5.6, y0=7.8)" ) check_init_args(Piecewise, ["data", "interpolation"]) check_repr(Piecewise(data={1: 0.1, 2: 0.2, 3: 0.3})) assert ( repr(Piecewise({1: 0.1, 2: 0.2, 3: 0.3})) == "Piecewise(data={1: array([0.1]), 2: array([0.2]), 3: array([0.3])})" )
def test_brownnoise(rng, plt): d = 5000 t = 0.5 dt = 0.001 std = 1.5 process = BrownNoise(dist=Gaussian(0, std)) samples = process.run(t, d=d, dt=dt, rng=rng) trange = process.trange(t, dt=dt) expected_std = std * np.sqrt(trange) atol = 3.5 * expected_std / np.sqrt(d) plt.subplot(2, 1, 1) plt.title("Five Brown noise signals") plt.plot(trange, samples[:, :5]) plt.subplot(2, 1, 2) plt.ylabel("Standard deviation") plt.plot(trange, np.abs(np.std(samples, axis=1)), label="Actual") plt.plot(trange, expected_std, label="Expected") plt.legend(loc='best') assert np.all(np.abs(np.mean(samples, axis=1)) < atol) assert np.all(np.abs(np.std(samples, axis=1) - expected_std) < atol)
def test_brownnoise(rng, plt): d = 5000 t = 500 dt = 0.001 samples = nengo.processes.sample(t, BrownNoise(), dt=dt, d=d, rng=rng) trange = np.arange(1, t + 1) * dt expected_std = np.sqrt((np.arange(t) + 1) * dt) atol = 3.5 * expected_std / np.sqrt(d) plt.subplot(2, 1, 1) plt.title("Five Brown noise signals") plt.plot(trange, samples[:, :5]) plt.subplot(2, 1, 2) plt.ylabel("Standard deviation") plt.plot(trange, np.abs(np.std(samples, axis=1)), label="Actual") plt.plot(trange, expected_std, label="Expected") plt.legend(loc='best') assert np.all(np.abs(np.mean(samples, axis=1)) < atol) assert np.all(np.abs(np.std(samples, axis=1) - expected_std) < atol)