Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix spaopt #39

Merged
merged 2 commits into from
Jun 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ Release History
(`#35 <https://github.com/nengo/nengo/pull/35>`_,
`#32 <https://github.com/nengo/nengo/issues/32>`_,
`#34 <https://github.com/nengo/nengo/issues/34>`_)
- Improved accuracy by fixing choice of evaluation point and intercept
distributions.
(`#39 <https://github.com/nengo/nengo_spa/pull/39>`_)


0.1.1 (May 19, 2017)
Expand Down
18 changes: 14 additions & 4 deletions nengo_spa/modules/tests/test_cortical.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,16 @@ def test_convolution(Simulator, plt, seed):
pAinvB = nengo.Probe(model.outAinvB.output, synapse=0.03)
pAinvBinv = nengo.Probe(model.outAinvBinv.output, synapse=0.03)

for state in [
model.inA,
model.inB,
model.outAB,
model.outABinv,
model.outAinvB,
model.outAinvBinv]:
for e in state.all_ensembles:
e.radius = 1.

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

Expand Down Expand Up @@ -169,16 +179,16 @@ def test_convolution(Simulator, plt, seed):

# Ideal answer: A*B = [0,0,0,1,0]
assert np.allclose(np.mean(sim.data[pAB][-10:], axis=0),
np.array([0, 0, 0, 1, 0]), atol=0.2)
np.array([0, 0, 0, 1, 0]), atol=0.25)

# Ideal answer: A*~B = [0,0,0,0,1]
assert np.allclose(np.mean(sim.data[pABinv][-10:], axis=0),
np.array([0, 0, 0, 0, 1]), atol=0.2)
np.array([0, 0, 0, 0, 1]), atol=0.25)

# Ideal answer: ~A*B = [0,1,0,0,0]
assert np.allclose(np.mean(sim.data[pAinvB][-10:], axis=0),
np.array([0, 1, 0, 0, 0]), atol=0.2)
np.array([0, 1, 0, 0, 0]), atol=0.25)

# Ideal answer: ~A*~B = [0,0,1,0,0]
assert np.allclose(np.mean(sim.data[pAinvBinv][-10:], axis=0),
np.array([0, 0, 1, 0, 0]), atol=0.2)
np.array([0, 0, 1, 0, 0]), atol=0.25)
15 changes: 6 additions & 9 deletions nengo_spa/networks/circularconvolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def transform_in(dims, align, invert):
tr[i] = row.real if i % 4 == 0 or i % 4 == 3 else row.imag

remove_imag_rows(tr)
tr /= np.sqrt(dims)
return tr.reshape((-1, dims))


Expand All @@ -67,6 +66,9 @@ def transform_out(dims):

tr = tr.reshape(4*dims2, dims)
remove_imag_rows(tr)
# IDFT has a 1/D scaling factor
tr /= dims

return tr.T


Expand Down Expand Up @@ -193,14 +195,9 @@ def CircularConvolution(n_neurons, dimensions, invert_a=False, invert_b=False,
with net:
net.input_a = nengo.Node(size_in=dimensions, label="input_a")
net.input_b = nengo.Node(size_in=dimensions, label="input_b")
with nengo.Config(nengo.Ensemble) as cfg:
cfg[nengo.Ensemble].eval_points = nengo.dists.CosineSimilarity(
2 * dimensions + 2)
cfg[nengo.Ensemble].intercepts = nengo.dists.CosineSimilarity(
2 * dimensions + 2)
net.product = Product(
n_neurons, tr_out.shape[1],
input_magnitude=input_magnitude / np.sqrt(2.))
net.product = Product(
n_neurons, tr_out.shape[1],
input_magnitude=2 * input_magnitude / np.sqrt(2.))
net.output = nengo.Node(size_in=dimensions, label="output")

nengo.Connection(
Expand Down