Ejemplo n.º 1
0
def test_optimizer_does_not_change_result(seed):
    dtype_resolution = np.finfo(nengo.rc.float_dtype).resolution
    dtype_decimal = int(np.floor(-np.log10(dtype_resolution) * 0.5))

    model = learning_net()
    model.seed = seed

    with model:
        # Add the default probe for every non-Probe object
        probes = [
            nengo.Probe(obj) for obj in model.all_objects
            if not isinstance(obj, (nengo.Probe, nengo.Network))
        ]
        # Also probe learning rules and neurons
        probes.extend(nengo.Probe(ens.neurons) for ens in model.all_ensembles)
        probes.extend(
            nengo.Probe(conn.learning_rule) for conn in model.all_connections
            if conn.learning_rule is not None)

    with nengo.Simulator(model, optimize=False) as sim:
        sim.run(0.1)
    with nengo.Simulator(model, optimize=True) as sim_opt:
        sim_opt.run(0.1)

    for probe in probes:
        assert_almost_equal(sim.data[probe],
                            sim_opt.data[probe],
                            decimal=dtype_decimal)
Ejemplo n.º 2
0
def test_unsupervised_exact_match(Simulator, learning_rule, seed, rng):
    sim_time = 1.0

    m, activity_p, trans_p = learning_net(
        learning_rule, nengo.Network(seed=seed), rng)

    refimpl_sim = nengo.Simulator(m)
    refimpl_sim.run(sim_time)

    mpi_sim = Simulator(m)
    mpi_sim.run(sim_time)

    assert np.allclose(
        refimpl_sim.data[activity_p], mpi_sim.data[activity_p],
        atol=0.00001, rtol=0.00)
    assert np.allclose(
        refimpl_sim.data[trans_p], mpi_sim.data[trans_p],
        atol=0.00001, rtol=0.00)

    refimpl_sim.reset()
    mpi_sim.reset()

    refimpl_sim.run(sim_time)
    mpi_sim.run(sim_time)

    assert np.allclose(
        refimpl_sim.data[activity_p], mpi_sim.data[activity_p],
        atol=0.00001, rtol=0.00)
    assert np.allclose(
        refimpl_sim.data[trans_p], mpi_sim.data[trans_p],
        atol=0.00001, rtol=0.00)