N-back model & dot products

Hi -

I’ve been trying to re-create the n-back model of Jan Gosmann and Chris E. I’ve been using spa.State for ‘stimulus’, memory, updated_list, etc. I’ve been using ensembles for the various gates, and the spa. BasalGanglia and spa.Thalamus .

I have had problems computing the vector dot product as shown in the attached code …

It seems if I could get around the 'dot(Stimulus,Stimulus) … error I would get reasonable results …

mport nengo
import numpy as np
import nengo.spa as spa
D = 8

model = spa.SPA()
def inputter(t):
if 0.1 < t < 0.2:
model.Stimulus = 'C’
elif 0.5 < t < 0.6:
model.Stimulus = 'G’
model.Strimulus = ‘0’

with model:
model.Stimulus = spa.State(D)
Thresholding = 0.5

model.Cortical_State = spa.State(D)
assign_state = spa.Actions(
    # line 21 is below ..
'dot(Stimulus, WAIT) + 0.2 --> Cortical_State = ENCODE',
    'dot(Cortical_State, ENCODE) +dot(Cortical_State,WAIT)--> Cortical_State = WAIT',
    # line 23 is below:
'dot(Cortical_State, TRANSFER) + 0.5 --> Cortical_State = TRANSFER'

for line 21, I tried writing 'dot(Stimulus,Stimulus) but get …

#Compare between two sources will never be implemented

also for reasons I can’t understand in line 23, if I substitute Thresholding for 0.5 I get …

… ’ is not supported by the Basal Ganglia.

model.bg = spa.BasalGanglia(assign_state)
model.thal = spa.Thalamus(model.bg)

# when I try what I conceive as a 'work-around' as below
print(model.Stimulus.output[0] * model.Stimulus.output[0])
# unsupported operand type(s) for *: 'ObjView' and 'ObjView'

Is the original model available for sharing?. I assume it’s written in Nengo 1.4.**

Finally, I wrote code that included 2/3 of the elements in figure 1 of the paper. I kept the dimensions low - 8, and the ensembles small - around 500 neurons. Yet - at least on my older computer at home - it wouldn’t load?? even though I didn’t get error messages when composing it …

Is this a computer memory issue?



to use a dot product within one of the action rules it is currently necessary to add the required components manually. The code should look somewhat like this:

model.stimulus_dot = spa.Compare(D)
assign_state = spa.Actions(
    'stimulus_dot --> ...',
    # ...
model.cortical = spa.Cortical(spa.Actions(
    'stimulus_dot_A = Stimulus',
    'stimulus_dot_B = Stimulus',

Incidentally, the statement that “Compare between two sources will never be implemented.” is not completely correct. It will not be implemented in the SPA module shipped with Nengo. But I am developing a new, improved SPA module where this will be implemented. If you feel adventurous you can actually try it out by doing a development install of the new-spa branch of Nengo.

As for line 23: Unfortunately, you cannot access variables defined in your Python code from the action rules. Any identifier in there is either expected to be a Semantic Pointer (if it starts with a capital) or a SPA module assigned (if it starts with a lowercase letter). This also means you probably have to change Stimulus to stimulus and Cortical_State to cortical_state. I don’t think this difference of identifiers starting with capitals or lowercase is not really documented anywhere, but it should be. So this is useful feedback for us for when we get around to improve the SPA documentation.

The print(model.Stimulus.output[0] * model.Stimulus.output[0]) does not work because model.Stimulus.output[0] is not an actual number, but just an object indicating the first dimension ([0]) of the output of model.Stimulus. Within Nengo this object can be used to make connections from it to other Nengo objects. To provide some code that might be roughly equivalent to what you intended here:

# ...
product = nengo.Node(lambda x: x * x, size_in=1)
nengo.Connection(model.Stimulus.output[0], product, synapse=0.005)
probe_product = nengo.Probe(product, synapse=0.01)
# ...

with nengo.Simulator(model) as sim:

# To access the product data, use sim.data[probe_product]

The original n-back model is available here.
The main model definition is in nback/model.py.
It is written in Nengo 2.0.1 and uses some components which are deprecated in the current Nengo 2.3.1, but it should still work.

Unfortunately, this is not enough information for me to tell what the problem is. How are you trying to run the model? Are you using NengoGUI? If so, maybe you can provide a screenshot?

thank you so much …

Howard Crystal, MD
Professor of Neurology, Pathology, and Psychiatry
SUNY Downstate
P: 718-270-2748, F: 718-221-5761