Пример #1
0
    def test_cubic_interpolation_warning(self):
        pytest.importorskip("scipy")

        # cubic interpolation with 0 not in times
        process = Piecewise({0.001: 0, 0.1: 0.1}, interpolation="cubic")
        with pytest.warns(UserWarning,
                          match="'cubic' interpolation.*for t=0.0"):
            try:
                process.run(0.001)
            except ValueError:
                pass  # scipy may raise a ValueError
Пример #2
0
    def product(x):
        return x[0] * x[1]

    nengo.Connection(combined, prod, function=product)

with model:
    inputA_probe = nengo.Probe(input_A)
    inputB_probe = nengo.Probe(input_B)

    A_probe = nengo.Probe(A, synapse=0.01)
    B_probe = nengo.Probe(B, synapse=0.01)

    combined_probe = nengo.Probe(combined, synapse=0.01)
    prod_probe = nengo.Probe(prod, synapse=0.01)

with nengo.Simulator(model) as sim:
    sim.run(5)

plt.figure()
plt.plot(sim.trange(), sim.data[A_probe], label="Decoded A")
plt.plot(sim.trange(), sim.data[B_probe], label="Decoded B")
plt.plot(sim.trange(), sim.data[prod_probe], label="Decoded product")

plt.plot(sim.trange(),
         correct_ans.run(sim.time, dt=sim.dt),
         c="k",
         label="Actual product")
plt.legend(loc="best")
plt.show()
    nengo.Connection(control, A[1], synapse=0.005)

with model:
    nengo.Connection(A,
                     A[0],
                     function=lambda x: x[0] * x[1] + x[0],
                     synapse=tau)
    A_probe = nengo.Probe(A, "decoded_output", synapse=0.01)

with nengo.Simulator(model) as sim:
    sim.run(1.4)

t = sim.trange()
dt = t[1] - t[0]
input_sig = input_func.run(t[-1], dt=dt)
control_sig = control_func.run(t[-1], dt=dt)
ref = dt * np.cumsum(input_sig)

plt.figure(figsize=(6, 8))
plt.subplot(211)
plt.plot(t, input_sig, label="input")
plt.ylabel("label")
plt.legend()

plt.subplot(212)
plt.plot(t, ref, "k--", label="exact")
plt.plot(t, sim.data[A_probe][:, 0], label="A (value)")
plt.plot(t, sim.data[A_probe][:, 1], label="A (control)")
plt.ylabel("x(t)")
plt.legend()