Пример #1
0
    def __init__(self, pre, post, solver=LstsqL2(), **kwargs):
        if isinstance(pre, nengo.Ensemble):
            solver = BiasedSolver(solver)
            bias = nengo.Node(output=solver.bias_function(post.size_in),
                              label="Bias")
            nengo.Connection(bias, post, synapse=None)

        super(Connection, self).__init__(pre, post, solver=solver, **kwargs)
Пример #2
0
    def __init__(self, pre, post, solver=LstsqL2(), bias_magnitude=1.0,
                 **kwargs):
        if isinstance(pre, nengo.Ensemble):
            solver = BiasedSolver(solver, magnitude=bias_magnitude)
            nengo.Connection(
                nengo.Node(output=bias_magnitude, label="Bias"), post,
                function=solver.bias_function(post.size_in), synapse=None)

        super(Connection, self).__init__(pre, post, solver=solver, **kwargs)
Пример #3
0
def test_biased_solver(Simulator, seed, d):
    solver = BiasedSolver()
    function = solver.bias_function(d)

    assert solver.bias is None
    assert np.allclose(function(np.ones(d)), np.zeros(d))

    with Network(seed=seed) as model:
        x = nengo.Ensemble(100, d)
        conn = nengo.Connection(x, x, solver=solver)

    with Simulator(model) as sim:
        bias = sim.data[conn].solver_info['bias']

    assert np.allclose(solver.bias, bias)
    assert np.allclose(function(np.ones(d)), bias)
Пример #4
0
def test_multiple_builds(Simulator, seed):
    # this is not a separate test because of nengo issue #1011
    solver = BiasedSolver()
    A, Y = np.ones((1, 1)), np.ones((1, 1))
    assert solver.bias is None
    solver(A, Y)
    assert solver.bias is not None
    with warns(UserWarning):
        solver(A, Y)

    # issue: #99
    with Network(seed=seed) as model:
        stim = nengo.Node(output=0)
        x = nengo.Ensemble(100, 1)
        out = nengo.Node(size_in=1)
        nengo.Connection(stim, x, synapse=None)
        conn = Connection(x, out, synapse=None)
        p = nengo.Probe(out, synapse=0.1)

    assert isinstance(conn.solver, BiasedSolver)

    with Simulator(model):
        pass

    with Simulator(model) as sim:
        sim.run(0.1)

    assert rmse(sim.data[p], 0) < 0.01
Пример #5
0
def test_biased_solver(Simulator, d):

    solver = BiasedSolver()
    function = solver.bias_function(d)

    assert solver.bias is None
    assert np.allclose(function(np.ones(d)), np.zeros(d))

    with Network() as model:
        x = nengo.Ensemble(100, d)
        conn = nengo.Connection(x, x, solver=solver)

    sim = Simulator(model)
    bias = sim.data[conn].solver_info['bias']

    assert np.allclose(solver.bias, bias)
    assert np.allclose(function(np.ones(d)), bias)
Пример #6
0
def test_biased_solver_weights(Simulator):
    solver = BiasedSolver(nengo.solvers.LstsqL2(weights=True))
    assert solver.weights

    with Network() as model:
        x = nengo.Ensemble(100, 1)
        nengo.Connection(x, x, solver=solver)

    Simulator(model)