How do you access an ensemble's decoder?

Is there a way to access an ensemble’s decoder value?

I understand that the decoder values are stored in connection.
However, in the controlled oscillator example: Controlled oscillator — Nengo 3.2.1.dev0 docs,
the feedback connection has a function that always return 0 for the last dimension.
Hence, when I read the decoder values for the last dimension of the feedback connection, they are all 0 for all neurons.

But when I probe the decoded_output of the oscillator ensemble, the decoded_output for the dimension is not 0. This makes me to think that there is another set of decoder values, that is not related to the decoder values stored in the feedback connection, used to calculate the decoded_output of the ensemble.

Is there a way to access that decoder values?

You are correct in the understanding that the decoders are associated with the connections (rather than with the ensemble). As such, to get access to the decoders, you will need to probe the connection object. There are 2 ways of getting a connection’s decoders. The first is to use a nengo.Probe and probe the "weights" property of a connection (you can use the sample_every parameter to limit the number of sample points that the probe records):

with model:
    ...
    fdbk_conn = nengo.Connection(oscillator, oscillator, function=feedback, synapse=tau)
    ...
    # Make the decoder probe
    decoder_probe = nengo.Probe(fdbk_conn, "weights", sample_every=sim_runtime)
    # If you set sample_every to be the same length as the simulation runtime, it will only record
    # one value. Since these decoders are static, it doesn't matter when in the simulation they
    # are recorded.

with nengo.Simulator(model) as sim:
    sim.run(sim_runtime)

If you do not want to create a probe, you can also access the decoders directly from within the sim context block:

with nengo.Simulator(model) as sim:
    decoders = sim.signals[sim.model.sig[fdbk_conn]["weights"]]

That is correct. When you probe the decoded output of an ensemble, a connection (not visible to the user) is made between the ensemble and the probe object. By default, Nengo will treat this connection as a communication channel (i.e., the identity function), which, in the case of the oscillator example, will be different from the function on the feedback connection.

Yup! Going back to the oscillator example, if you obtain the decoders for the feedback connection, the last dimension will be all 0. This the output for one example run:

[[-1.85915461e-05 -2.88481842e-05 -4.15516615e-05 ... -8.73461013e-08
   1.10145586e-04 -5.07662485e-05]
 [-4.82184753e-05 -6.23222074e-06  6.43241393e-05 ... -7.05898438e-05
   5.28892191e-05 -1.90313176e-04]
 [ 0.00000000e+00  0.00000000e+00  0.00000000e+00 ...  0.00000000e+00
   0.00000000e+00  0.00000000e+00]]
1 Like