nengo-ocl icon indicating copy to clipboard operation
nengo-ocl copied to clipboard

Multiple sliced Neuron->Neuron connections do not work properly

Open hunse opened this issue 4 years ago • 0 comments

https://forum.nengo.ai/t/connecting-ensembles-using-neuron-clusters-second-question-added/1121/4

Doing multiple connections from different slices of neurons in an ensemble to the same target does not work properly.

Minimal example, where the output should be a sine wave with amplitude between -1 and 1. Works properly in Nengo.

import matplotlib.pyplot as plt
import nengo
import nengo_ocl
import numpy as np

with nengo.Network() as model:
    inp = nengo.Node(lambda t: np.sin(6*t))
    ens1 = nengo.Ensemble(20, 1, seed=1, label="a")
    node2 = nengo.Node(size_in=1)
    node2_p = nengo.Probe(node2, synapse=0.03)
    nengo.Connection(inp, ens1, synapse=None)

    # Make temporary connection and use it to retrieve weights
    conn = nengo.Connection(
        ens1, node2, solver=nengo.solvers.LstsqL2(), seed=3
    )

    with nengo.Simulator(model) as sim:
        weights = sim.data[conn].weights

    model.connections.remove(conn)

    # Make connections between clusters
    Ncluster = 10  # number of neurons per cluster
    clusters1 = np.arange(0, ens1.n_neurons, Ncluster)

    if 0:
        nengo.Connection(ens1.neurons, node2, transform=weights)
    else:
        for i, begin1 in enumerate(clusters1):
            end1 = begin1 + Ncluster

            nengo.Connection(
                ens1.neurons[begin1:end1],
                node2,
                transform=weights[:, begin1:end1],
                label="a%d-b" % (i,)
            )

# with nengo.Simulator(model) as sim:
with nengo_ocl.Simulator(model) as sim:
    sim.run(1.0)

plt.plot(sim.trange(), sim.data[node2_p])
plt.ylim([-1, 1])

plt.show()

Figure_1

hunse avatar Apr 03 '20 20:04 hunse