本文整理汇总了Python中nengo.utils.testing.allclose函数的典型用法代码示例。如果您正苦于以下问题:Python allclose函数的具体用法?Python allclose怎么用?Python allclose使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了allclose函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_weights
def test_weights(Simulator, nl):
name = 'test_weights'
n1, n2 = 100, 50
def func(t):
return np.array([np.sin(4 * t), np.cos(12 * t)])
transform = np.array([[0.6, -0.4]])
m = nengo.Model(name, seed=3902)
u = nengo.Node(output=func)
a = nengo.Ensemble(nl(n1), dimensions=2, radius=1.5)
b = nengo.Ensemble(nl(n2), dimensions=1)
bp = nengo.Probe(b)
nengo.Connection(u, a)
nengo.Connection(a, b, transform=transform,
weight_solver=nengo.decoders.lstsq_L2nz)
sim = Simulator(m)
sim.run(2.)
t = sim.trange()
x = func(t).T
y = np.dot(x, transform.T)
z = filtfilt(sim.data[bp], 10, axis=0)
assert allclose(t, y.flatten(), z.flatten(),
plotter=Plotter(Simulator, nl),
filename='test_connection.' + name + '.pdf',
atol=0.1, rtol=0, buf=100, delay=10)
示例2: test_weights
def test_weights(Simulator, nl):
name = 'test_weights'
n1, n2 = 100, 50
def func(t):
return np.array([np.sin(4 * t), np.cos(12 * t)])
transform = np.array([[0.6, -0.4]])
m = nengo.Network(label=name, seed=3902)
with m:
m.config[nengo.Ensemble].neuron_type = nl()
u = nengo.Node(output=func)
a = nengo.Ensemble(n1, dimensions=2, radius=1.5)
b = nengo.Ensemble(n2, dimensions=1)
bp = nengo.Probe(b)
nengo.Connection(u, a)
nengo.Connection(a, b, transform=transform,
solver=LstsqL2(weights=True))
sim = Simulator(m)
sim.run(2.)
t = sim.trange()
x = func(t).T
y = np.dot(x, transform.T)
z = filtfilt(sim.data[bp], 10, axis=0)
assert allclose(t, y.flatten(), z.flatten(),
plotter=Plotter(Simulator, nl),
filename='test_connection.' + name + '.pdf',
atol=0.1, rtol=0, buf=100, delay=10)
示例3: test_weights
def test_weights(Simulator, nl, plt, seed):
n1, n2 = 100, 50
def func(t):
return np.array([np.sin(4 * t), np.cos(12 * t)])
transform = np.array([[0.6, -0.4]])
m = nengo.Network(label='test_weights', seed=seed)
with m:
m.config[nengo.Ensemble].neuron_type = nl()
u = nengo.Node(output=func)
a = nengo.Ensemble(n1, dimensions=2, radius=1.5)
b = nengo.Ensemble(n2, dimensions=1)
bp = nengo.Probe(b)
nengo.Connection(u, a)
nengo.Connection(a, b, transform=transform,
solver=LstsqL2(weights=True))
sim = Simulator(m)
sim.run(1.)
t = sim.trange()
x = func(t).T
y = np.dot(x, transform.T)
z = nengo.synapses.filtfilt(sim.data[bp], 0.005, dt=sim.dt)
assert allclose(t, y, z, atol=0.1, buf=0.1, delay=0.01, plt=plt)
示例4: test_lowpass
def test_lowpass(Simulator, plt, seed):
dt = 1e-3
tau = 0.03
t, x, yhat = run_synapse(Simulator, seed, Lowpass(tau), dt=dt)
y = Lowpass(tau).filt(x, dt=dt, y0=0)
assert allclose(t, y, yhat, delay=dt, plt=plt)
示例5: test_lowpass
def test_lowpass(Simulator, plt):
dt = 1e-3
tau = 0.03
t, x, yhat = run_synapse(Simulator, nengo.synapses.Lowpass(tau), dt=dt)
y = filt(x, tau / dt)
assert allclose(t, y, yhat, delay=dt, plt=plt)
示例6: test_decoders
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)
示例7: test_alpha
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 = LinearFilter(num, den).filt(x, dt=dt, y0=0)
assert allclose(t, y, yhat, delay=dt, atol=5e-6, plt=plt)
示例8: test_lowpass
def test_lowpass(Simulator):
dt = 1e-3
tau = 0.03
t, x, yhat = run_synapse(Simulator, nengo.synapses.Lowpass(tau), dt=dt)
y = filt(x, tau / dt)
assert allclose(t, y.flatten(), yhat.flatten(), delay=1,
plotter=Plotter(Simulator),
filename='test_synapse.test_lowpass.pdf')
示例9: test_decoders
def test_decoders(Simulator, nl):
dt = 1e-3
tau = 0.01
t, x, yhat = run_synapse(
Simulator, nengo.synapses.Lowpass(tau), dt=dt, n_neurons=100)
y = filt(x, tau / dt)
assert allclose(t, y.flatten(), yhat.flatten(), delay=1,
plotter=Plotter(Simulator, nl),
filename='test_synapse.test_decoders.pdf')
示例10: test_scalar
def test_scalar(Simulator, nl, plt, seed):
"""A network that represents sin(t)."""
N = 40
f = lambda t: np.sin(6.3 * t)
m = nengo.Network(label='test_scalar', seed=seed)
with m:
m.config[nengo.Ensemble].neuron_type = nl()
input = nengo.Node(output=f)
A = nengo.Ensemble(N, 1, label='A')
nengo.Connection(input, A)
in_p = nengo.Probe(input, 'output')
A_p = nengo.Probe(A, 'decoded_output', synapse=0.02)
sim = Simulator(m)
sim.run(1.0)
t = sim.trange()
target = f(t)
assert allclose(t, target, sim.data[in_p], rtol=1e-3, atol=1e-5)
assert allclose(t, target, sim.data[A_p], atol=0.1, delay=0.03, plt=plt)
示例11: test_vector
def test_vector(Simulator, nl, plt, seed):
"""A network that represents sin(t), cos(t), cos(t)**2."""
N = 100
f = lambda t: [np.sin(6.3*t), np.cos(6.3*t), np.cos(6.3*t)**2]
m = nengo.Network(label='test_vector', seed=seed)
with m:
m.config[nengo.Ensemble].neuron_type = nl()
input = nengo.Node(output=f)
A = nengo.Ensemble(N * 3, 3, radius=1.5)
nengo.Connection(input, A)
in_p = nengo.Probe(input)
A_p = nengo.Probe(A, synapse=0.03)
sim = Simulator(m)
sim.run(1.0)
t = sim.trange()
target = np.vstack(f(t)).T
assert allclose(t, target, sim.data[in_p], rtol=1e-3, atol=1e-5)
assert allclose(t, target, sim.data[A_p],
plt=plt, atol=0.1, delay=0.03, buf=0.1)
示例12: test_linearfilter
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)
示例13: test_linearfilter
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)
示例14: test_alpha
def test_alpha(Simulator, plt):
dt = 1e-3
tau = 0.03
b, a = [0.00054336, 0.00053142], [1, -1.9344322, 0.93550699]
# ^^^ these coefficients found for tau=0.03 and dt=1e-3
# scipy.signal.cont2discrete(([1], [tau**2, 2*tau, 1]), dt)
# b = [0.00054336283526056767, 0.00053142123234546667]
# a = [1, -1.9344322009640118, 0.93550698503161778]
# ^^^ these coefficients found by the exact algorithm used in Builder
t, x, yhat = run_synapse(Simulator, nengo.synapses.Alpha(tau), dt=dt)
y = lti(x, (b, a))
assert allclose(t, y, yhat, delay=dt, atol=5e-6, plt=plt)
示例15: test_triangle
def test_triangle(Simulator, plt, seed):
dt = 1e-3
tau = 0.03
t, x, ysim = run_synapse(Simulator, seed, Triangle(tau), dt=dt)
yfilt = Triangle(tau).filt(x, dt=dt, y0=0)
# 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)