-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
With this change, decoders that are manually specified through a connection from `ens.neurons` with a `transform` are treated the same as decoders specified through a connection from `ens` with a `NoSolver` solver. Co-authored-by: Trevor Bekolay <[email protected]>
- Loading branch information
Showing
2 changed files
with
69 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import pytest | ||
import nengo | ||
import numpy as np | ||
|
||
|
||
@pytest.mark.parametrize("pre_dims", [1, 3]) | ||
@pytest.mark.parametrize("post_dims", [1]) | ||
@pytest.mark.parametrize("learn", [True, False]) | ||
@pytest.mark.parametrize("use_solver", [True, False]) | ||
def test_manual_decoders( | ||
seed, Simulator, pre_dims, post_dims, learn, use_solver): | ||
|
||
with nengo.Network(seed=seed) as model: | ||
pre = nengo.Ensemble(50, dimensions=pre_dims, | ||
gain=np.ones(50), | ||
bias=np.ones(50) * 5) | ||
post = nengo.Node(None, size_in=post_dims) | ||
|
||
learning_rule_type = nengo.PES() if learn else None | ||
weights = np.zeros((post_dims, 50)) | ||
if use_solver: | ||
conn = nengo.Connection(pre, post, | ||
function=lambda x: np.zeros(post_dims), | ||
learning_rule_type=learning_rule_type, | ||
solver=nengo.solvers.NoSolver(weights.T)) | ||
else: | ||
conn = nengo.Connection(pre.neurons, post, | ||
learning_rule_type=learning_rule_type, | ||
transform=weights) | ||
|
||
if learn: | ||
error = nengo.Node(np.zeros(post_dims)) | ||
nengo.Connection(error, conn.learning_rule) | ||
|
||
pre_probe = nengo.Probe(pre.neurons, synapse=None) | ||
post_probe = nengo.Probe(post, synapse=None) | ||
|
||
with Simulator(model, precompute=False) as sim: | ||
sim.run(0.1) | ||
|
||
# Ensure pre population has a lot of activity | ||
assert np.mean(sim.data[pre_probe]) > 100 | ||
# But that post has no activity due to the zero weights | ||
assert np.all(sim.data[post_probe] == 0) |