本文整理汇总了Python中nengo.utils.numpy.rmse函数的典型用法代码示例。如果您正苦于以下问题:Python rmse函数的具体用法?Python rmse怎么用?Python rmse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rmse函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_scalar
def test_scalar(Simulator, nl):
"""A network that represents sin(t)."""
N = 30
m = nengo.Network(label='test_scalar', seed=123)
with m:
m.config[nengo.Ensemble].neuron_type = nl()
input = nengo.Node(output=np.sin, label='input')
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(5.0)
with Plotter(Simulator, nl) as plt:
t = sim.trange()
plt.plot(t, sim.data[in_p], label='Input')
plt.plot(t, sim.data[A_p], label='Neuron approximation, pstc=0.02')
plt.legend(loc=0)
plt.savefig('test_ensemble.test_scalar.pdf')
plt.close()
target = np.sin(np.arange(5000) / 1000.)
target.shape = (-1, 1)
logger.debug("Input RMSE: %f", npext.rmse(target, sim.data[in_p]))
logger.debug("A RMSE: %f", npext.rmse(target, sim.data[A_p]))
assert npext.rmse(target, sim.data[in_p]) < 0.001
assert npext.rmse(target, sim.data[A_p]) < 0.1
示例2: test_run
def test_run(Simulator, seed):
rng = np.random.RandomState(seed)
vocab = spa.Vocabulary(16, rng=rng)
with spa.SPA(seed=seed, vocabs=[vocab]) as model:
model.bind = spa.Bind(dimensions=16)
def inputA(t):
if 0 <= t < 0.1:
return 'A'
else:
return 'B'
model.input = spa.Input(bind_A=inputA, bind_B='A')
bind, vocab = model.get_module_output('bind')
with model:
p = nengo.Probe(bind, 'output', synapse=0.03)
sim = Simulator(model)
sim.run(0.2)
error = rmse(vocab.parse("B*A").v, sim.data[p][-1])
assert error < 0.1
error = rmse(vocab.parse("A*A").v, sim.data[p][100])
assert error < 0.1
示例3: test_vector
def test_vector(Simulator, nl):
"""A network that represents sin(t), cos(t), arctan(t)."""
N = 40
m = nengo.Network(label='test_vector', seed=123)
with m:
m.config[nengo.Ensemble].neuron_type = nl()
input = nengo.Node(
output=lambda t: [np.sin(t), np.cos(t), np.arctan(t)])
A = nengo.Ensemble(N * 3, 3, radius=2)
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(5)
with Plotter(Simulator, nl) as plt:
t = sim.trange()
plt.plot(t, sim.data[in_p], label='Input')
plt.plot(t, sim.data[A_p], label='Neuron approximation, pstc=0.02')
plt.legend(loc='best', prop={'size': 10})
plt.savefig('test_ensemble.test_vector.pdf')
plt.close()
target = np.vstack((np.sin(np.arange(5000) / 1000.),
np.cos(np.arange(5000) / 1000.),
np.arctan(np.arange(5000) / 1000.))).T
logger.debug("In RMSE: %f", npext.rmse(target, sim.data[in_p]))
assert npext.rmse(target, sim.data[in_p]) < 0.01
assert npext.rmse(target, sim.data[A_p]) < 0.1
示例4: run_param_set
def run_param_set(self, n_neurons, d, seed, trial):
seed = int(seed)
n_neurons = int(n_neurons)
d = int(d)
rng = np.random.RandomState(seed)
ctx = nengo.spa.SemanticPointer(d, rng)
ctx.make_unitary()
model = nengo.Network(seed=get_seed(rng))
with model:
in_a = nengo.Node(SignalGenerator(self.duration), size_out=d)
in_b = nengo.Node(output=ctx.v)
old_prod = nengo.networks.Product(n_neurons, d)
old_result = nengo.Ensemble(1, 1, neuron_type=nengo.Direct())
nengo.Connection(in_a, old_prod.A)
nengo.Connection(in_b, old_prod.B)
nengo.Connection(
old_prod.output, old_result,
transform=nengo.networks.product.dot_product_transform(d))
prod = spaopt.Product(n_neurons, d)
result = nengo.Ensemble(1, 1, neuron_type=nengo.Direct())
nengo.Connection(in_a, prod.A)
nengo.Connection(in_b, prod.B)
nengo.Connection(
prod.output, result,
transform=nengo.networks.product.dot_product_transform(d))
with nengo.Network() as net:
net.config[nengo.Ensemble].neuron_type = nengo.Direct()
d_prod = nengo.networks.EnsembleArray(2, d, 2)
d_result = nengo.Ensemble(1, 1)
nengo.Connection(in_a, d_prod.input[::2])
nengo.Connection(in_b, d_prod.input[1::2])
nengo.Connection(
d_prod.add_output('dot', lambda x: x[0] * x[1]), d_result,
transform=[d * [1.]])
old_probe = nengo.Probe(old_result, synapse=None)
probe = nengo.Probe(result, synapse=None)
d_probe = nengo.Probe(d_result, synapse=None)
sim = nengo.Simulator(model)
sim.run(self.duration, progress_bar=False)
return {
't': sim.trange(),
'default': rmse(sim.data[old_probe], sim.data[d_probe], axis=1),
'optimized': rmse(sim.data[probe], sim.data[d_probe], axis=1)
}
示例5: test_product
def test_product(Simulator, nl):
N = 80
m = nengo.Network(label='test_product', seed=124)
with m:
m.config[nengo.Ensemble].neuron_type = nl()
sin = nengo.Node(output=np.sin)
cons = nengo.Node(output=-.5)
factors = nengo.Ensemble(2 * N, dimensions=2, radius=1.5)
factors.encoders = np.tile(
[[1, 1], [-1, 1], [1, -1], [-1, -1]],
(factors.n_neurons // 4, 1))
product = nengo.Ensemble(N, dimensions=1)
nengo.Connection(sin, factors[0])
nengo.Connection(cons, factors[1])
nengo.Connection(
factors, product, function=lambda x: x[0] * x[1], synapse=0.01)
sin_p = nengo.Probe(sin, 'output', sample_every=.01)
# TODO
# m.probe(conn, sample_every=.01)
factors_p = nengo.Probe(
factors, 'decoded_output', sample_every=.01, synapse=.01)
product_p = nengo.Probe(
product, 'decoded_output', sample_every=.01, synapse=.01)
sim = Simulator(m)
sim.run(6)
with Plotter(Simulator, nl) as plt:
t = sim.trange(dt=.01)
plt.subplot(211)
plt.plot(t, sim.data[factors_p])
plt.plot(t, np.sin(np.arange(0, 6, .01)))
plt.plot(t, sim.data[sin_p])
plt.subplot(212)
plt.plot(t, sim.data[product_p])
# TODO
# plt.plot(sim.data[conn])
plt.plot(t, -.5 * np.sin(np.arange(0, 6, .01)))
plt.savefig('test_ensemble.test_prod.pdf')
plt.close()
sin = np.sin(np.arange(0, 6, .01))
assert npext.rmse(sim.data[factors_p][:, 0], sin) < 0.1
assert npext.rmse(sim.data[factors_p][20:, 1], -0.5) < 0.1
assert npext.rmse(sim.data[product_p][:, 0], -0.5 * sin) < 0.1
示例6: test_oscillator
def test_oscillator(Simulator, nl, plt):
model = nengo.Network(label='Oscillator', seed=789)
with model:
model.config[nengo.Ensemble].neuron_type = nl()
inputs = {0: [1, 0], 0.5: [0, 0]}
input = nengo.Node(piecewise(inputs), label='Input')
tau = 0.1
freq = 5
T = nengo.networks.Oscillator(tau, freq, n_neurons=100)
nengo.Connection(input, T.input)
A = nengo.Ensemble(100, dimensions=2)
nengo.Connection(A, A, synapse=tau,
transform=[[1, -freq*tau], [freq*tau, 1]])
nengo.Connection(input, A)
in_probe = nengo.Probe(input)
A_probe = nengo.Probe(A, synapse=0.01)
T_probe = nengo.Probe(T.ensemble, synapse=0.01)
sim = Simulator(model)
sim.run(3.0)
t = sim.trange()
plt.plot(t, sim.data[A_probe], label='Manual')
plt.plot(t, sim.data[T_probe], label='Template')
plt.plot(t, sim.data[in_probe], 'k', label='Input')
plt.legend(loc=0)
assert rmse(sim.data[A_probe], sim.data[T_probe]) < 0.3
示例7: test_integrator
def test_integrator(Simulator, nl):
model = nengo.Network(label='Integrator')
with model:
inputs = {0: 0, 0.2: 1, 1: 0, 2: -2, 3: 0, 4: 1, 5: 0}
input = nengo.Node(piecewise(inputs))
tau = 0.1
T = nengo.networks.Integrator(tau, neurons=nl(100), dimensions=1)
nengo.Connection(input, T.input, filter=tau)
A = nengo.Ensemble(nl(100), dimensions=1)
nengo.Connection(A, A, filter=tau)
nengo.Connection(input, A, transform=tau, filter=tau)
input_p = nengo.Probe(input, 'output')
A_p = nengo.Probe(A, 'decoded_output', filter=0.01)
T_p = nengo.Probe(T.ensemble, 'decoded_output', filter=0.01)
sim = Simulator(model, dt=0.001)
sim.run(6.0)
with Plotter(Simulator, nl) as plt:
t = sim.trange()
plt.plot(t, sim.data[A_p], label='Manual')
plt.plot(t, sim.data[T_p], label='Template')
plt.plot(t, sim.data[input_p], 'k', label='Input')
plt.legend(loc=0)
plt.savefig('test_integrator.test_integrator.pdf')
plt.close()
assert rmse(sim.data[A_p], sim.data[T_p]) < 0.2
示例8: test_integrator
def test_integrator(Simulator, nl, plt):
model = nengo.Network(label='Integrator', seed=892)
with model:
model.config[nengo.Ensemble].neuron_type = nl()
inputs = {0: 0, 0.2: 1, 1: 0, 2: -2, 3: 0, 4: 1, 5: 0}
input = nengo.Node(piecewise(inputs))
tau = 0.1
T = nengo.networks.Integrator(tau, n_neurons=100, dimensions=1)
nengo.Connection(input, T.input, synapse=tau)
A = nengo.Ensemble(100, dimensions=1)
nengo.Connection(A, A, synapse=tau)
nengo.Connection(input, A, transform=tau, synapse=tau)
input_p = nengo.Probe(input)
A_p = nengo.Probe(A, synapse=0.01)
T_p = nengo.Probe(T.ensemble, synapse=0.01)
sim = Simulator(model, dt=0.001)
sim.run(6.0)
t = sim.trange()
plt.plot(t, sim.data[A_p], label='Manual')
plt.plot(t, sim.data[T_p], label='Template')
plt.plot(t, sim.data[input_p], 'k', label='Input')
plt.legend(loc=0)
assert rmse(sim.data[A_p], sim.data[T_p]) < 0.2
示例9: test_sine_waves
def test_sine_waves(Simulator, plt, seed):
radius = 2
dim = 5
product = nengo.networks.Product(
200, dim, radius, net=nengo.Network(seed=seed))
func_A = lambda t: np.sqrt(radius)*np.sin(np.arange(1, dim+1)*2*np.pi*t)
func_B = lambda t: np.sqrt(radius)*np.sin(np.arange(dim, 0, -1)*2*np.pi*t)
with product:
input_A = nengo.Node(func_A)
input_B = nengo.Node(func_B)
nengo.Connection(input_A, product.A)
nengo.Connection(input_B, product.B)
p = nengo.Probe(product.output, synapse=0.005)
with Simulator(product) as sim:
sim.run(1.0)
t = sim.trange()
AB = np.asarray(list(map(func_A, t))) * np.asarray(list(map(func_B, t)))
delay = 0.013
offset = np.where(t >= delay)[0]
for i in range(dim):
plt.subplot(dim+1, 1, i+1)
plt.plot(t + delay, AB[:, i])
plt.plot(t, sim.data[p][:, i])
plt.xlim(right=t[-1])
plt.yticks((-2, 0, 2))
assert rmse(AB[:len(offset), :], sim.data[p][offset, :]) < 0.2
示例10: run_trial
def run_trial():
model = nengo.Network(seed=rng.randint(maxint))
with model:
model.config[nengo.Ensemble].n_eval_points = n_eval_points
stimulus = nengo.Node(
output=lambda t: stimulus_fn(max(0., t - wait_duration)),
size_out=2)
product_net = nengo.networks.Product(n_neurons, 1)
nengo.Connection(stimulus[0], product_net.A)
nengo.Connection(stimulus[1], product_net.B)
probe_test = nengo.Probe(product_net.output)
ens_direct = nengo.Ensemble(
1, dimensions=2, neuron_type=nengo.Direct())
result_direct = nengo.Node(size_in=1)
nengo.Connection(stimulus, ens_direct)
nengo.Connection(
ens_direct, result_direct, function=lambda x: x[0] * x[1],
synapse=None)
probe_direct = nengo.Probe(result_direct)
sim = nengo.Simulator(model)
sim.run(duration + wait_duration, progress_bar=False)
selection = sim.trange() > wait_duration
test = sim.data[probe_test][selection]
direct = sim.data[probe_direct][selection]
return rmse(test, direct)
示例11: test_sine_waves
def test_sine_waves(Simulator, plt, seed):
radius = 2
dim = 5
product = nengo.networks.Product(200, dim, radius, seed=seed)
func_a = lambda t: np.sqrt(radius)*np.sin(np.arange(1, dim+1)*2*np.pi*t)
func_b = lambda t: np.sqrt(radius)*np.sin(np.arange(dim, 0, -1)*2*np.pi*t)
with product:
input_a = nengo.Node(func_a)
input_b = nengo.Node(func_b)
nengo.Connection(input_a, product.input_a)
nengo.Connection(input_b, product.input_b)
p = nengo.Probe(product.output, synapse=0.005)
with Simulator(product) as sim:
sim.run(1.0)
t = sim.trange()
ideal = (np.asarray([func_a(tt) for tt in t])
* np.asarray([func_b(tt) for tt in t]))
delay = 0.013
offset = np.where(t >= delay)[0]
for i in range(dim):
plt.subplot(dim+1, 1, i+1)
plt.plot(t + delay, ideal[:, i])
plt.plot(t, sim.data[p][:, i])
plt.xlim(right=t[-1])
plt.yticks((-2, 0, 2))
assert rmse(ideal[:len(offset), :], sim.data[p][offset, :]) < 0.2
示例12: test_integrator
def test_integrator(Simulator, plt, seed):
model = nengo.Network(seed=seed)
with model:
inputs = {0: 0, 0.2: 1, 1: 0, 2: -2, 3: 0, 4: 1, 5: 0}
input = nengo.Node(Piecewise(inputs))
tau = 0.1
T = nengo.networks.Integrator(tau, n_neurons=100, dimensions=1)
nengo.Connection(input, T.input, synapse=tau)
A = nengo.Ensemble(100, dimensions=1)
nengo.Connection(A, A, synapse=tau)
nengo.Connection(input, A, transform=tau, synapse=tau)
input_p = nengo.Probe(input, sample_every=0.01)
A_p = nengo.Probe(A, synapse=0.01, sample_every=0.01)
T_p = nengo.Probe(T.ensemble, synapse=0.01, sample_every=0.01)
with Simulator(model) as sim:
sim.run(6.0)
t = sim.trange(sample_every=0.01)
plt.plot(t, sim.data[A_p], label='Manual')
plt.plot(t, sim.data[T_p], label='Template')
plt.plot(t, sim.data[input_p], 'k', label='Input')
plt.legend(loc='best')
assert rmse(sim.data[A_p], sim.data[T_p]) < 0.1
示例13: test_sine_waves
def test_sine_waves(Simulator, nl):
radius = 2
dim = 5
product = nengo.networks.Product(
200, dim, radius, neuron_type=nl(), seed=63)
func_A = lambda t: np.sqrt(radius)*np.sin(np.arange(1, dim+1)*2*np.pi*t)
func_B = lambda t: np.sqrt(radius)*np.sin(np.arange(dim, 0, -1)*2*np.pi*t)
with product:
input_A = nengo.Node(func_A)
input_B = nengo.Node(func_B)
nengo.Connection(input_A, product.A)
nengo.Connection(input_B, product.B)
p = nengo.Probe(product.output, synapse=0.005)
sim = Simulator(product)
sim.run(1.0)
t = sim.trange()
AB = np.asarray(list(map(func_A, t))) * np.asarray(list(map(func_B, t)))
delay = 0.013
offset = np.where(t >= delay)[0]
with Plotter(Simulator, nl) as plt:
for i in range(dim):
plt.subplot(dim+1, 1, i+1)
plt.plot(t + delay, AB[:, i])
plt.plot(t, sim.data[p][:, i])
plt.savefig('test_product.test_sine_waves.pdf')
plt.close()
assert rmse(AB[:len(offset), :], sim.data[p][offset, :]) < 0.2
示例14: test_sine_waves
def test_sine_waves(Simulator, nl):
radius = 2
dim = 5
product = nengo.networks.Product(nl(200), dim, radius)
func_A = lambda t: radius*np.sin(np.arange(1, dim+1)*2*np.pi*t)
func_B = lambda t: radius*np.sin(np.arange(dim, 0, -1)*2*np.pi*t)
pstc = 0.003
with product:
input_A = nengo.Node(output=func_A)
input_B = nengo.Node(output=func_B)
nengo.Connection(input_A, product.A)
nengo.Connection(input_B, product.B)
p = nengo.Probe(product.output, synapse=pstc)
sim = Simulator(product, seed=123)
sim.run(1.0)
t = sim.trange()
AB = np.asarray(list(map(func_A, t))) * np.asarray(list(map(func_B, t)))
delay = 0.011
offset = np.where(t > delay)[0]
with Plotter(Simulator) as plt:
for i in range(dim):
plt.subplot(dim+1, 1, i+1)
plt.plot(t + delay, AB[:, i], label="$A \cdot B$")
plt.plot(t, sim.data[p][:, i], label="Output")
plt.legend()
plt.savefig('test_product.test_sine_waves.pdf')
plt.close()
assert rmse(AB[:len(offset), :], sim.data[p][offset, :]) < 0.3
示例15: test_direct_mode_with_single_neuron
def test_direct_mode_with_single_neuron(Simulator, plt, seed):
radius = 2
dim = 5
config = nengo.Config(nengo.Ensemble)
config[nengo.Ensemble].neuron_type = nengo.Direct()
with config:
product = nengo.networks.Product(
1, dim, radius, net=nengo.Network(seed=seed))
func_A = lambda t: np.sqrt(radius)*np.sin(np.arange(1, dim+1)*2*np.pi*t)
func_B = lambda t: np.sqrt(radius)*np.sin(np.arange(dim, 0, -1)*2*np.pi*t)
with product:
input_A = nengo.Node(func_A)
input_B = nengo.Node(func_B)
nengo.Connection(input_A, product.A)
nengo.Connection(input_B, product.B)
p = nengo.Probe(product.output, synapse=0.005)
sim = Simulator(product)
sim.run(1.0)
t = sim.trange()
AB = np.asarray(list(map(func_A, t))) * np.asarray(list(map(func_B, t)))
delay = 0.013
offset = np.where(t >= delay)[0]
for i in range(dim):
plt.subplot(dim+1, 1, i+1)
plt.plot(t + delay, AB[:, i])
plt.plot(t, sim.data[p][:, i])
plt.xlim(right=t[-1])
assert rmse(AB[:len(offset), :], sim.data[p][offset, :]) < 0.2