Hi @cansukucuksozen,
You didn’t specify but I assume that you are doing this from within the NengoGUI? If you are not using NengoGUI, there are some other things (apart from those I will be discussing below) that you will need to add to your code to get it to function.
Apart from that, I presume that what you are attempting to accomplish is to use the scalar inputs (from nodes) to affect the input values to the two actions you have defined? Let me know if my presumption is wrong.
Looking at your code, it is mostly correct. I’ll step through your code and explain what each part of it does, and if it need correction.
import nengo
import nengo.spa as spa
D = 32
model = spa.SPA()
with model:
model.mind = spa.State(D)
model.action = spa.State(D)
This part is pretty straight forward. You defined an SPA model, as well as two State modules, one called mind
and the other called action
.
actions = spa.Actions(
"dot(mind,THOUGHT1) --> action=DO1",
"dot(mind,THOUGHT2) --> action=DO2"
)
model.bg = spa.BasalGanglia(actions)
In this part of the code two rules are defined as part of the BG actions. The first rule triggers if the value represented in the mind
State is the THOUGHT1
semantic pointer. When this rule triggers, the value in the action
State is set to the DO1
semantic pointer. The second rule triggers if the value represented in the mind
State is the THOUGHT2
semantic pointer, and this will result in the semantic pointer DO2
being stored in the action
State.
If you are using NengoGUI, you will need to modify the semantic pointer values of the mind
State for these rules to have any effect. You do this by right clicking on the mind
State on the network diagram, choosing the semantic pointer cloud
and then using the set value
option in the right-click menu of the semantic pointer cloud.
If you are not using NengoGUI, you’ll need to add a spa.Input
module (the syntax is very much like a nengo.Node
) to provide the mind
State with some input. Otherwise, the value inside mind
will not change as the simulation is running. You can see an example of how to do this on this documentation page. I should note that the documentation I’ve linked to is not the most recent version since the build-in nengo.spa
library has been deprecated in favour of using the more fully featured NengoSPA package.
node1 = nengo.Node([0])
node2 = nengo.Node([0])
Here, you create two Nengo nodes. These nodes are (I assume) to be used to feed a scalar value offset to the BG inputs. They are currently defined with a starting output of [0]
(which is just a scalar value of 0). If you are using the NengoGUI, you can set these values using the input slider for these nodes. If you are not using the GUI, you’ll need to modify this code to use a python function instead of a steady “0” as an output.
nengo.Connection(node1[0], model.bg.input)
nengo.Connection(node2[0], model.bg.input)
So here is where your issue is. I think what you are trying to do is to connect node1
to the first BG action, and node2
to the second BG action? If that was the case, what you’ll want to do is this:
nengo.Connection(node1, model.bg.input[0])
nengo.Connection(node2, model.bg.input[1])
In the corrected code, the output of each node is a scalar value, so it doesn’t need (or can’t) be index. For the connection’s destinations, we use the list index to tell Nengo which dimension of the BG input to connect to. Since node1
is to be connected to the first action, the index [0]
is used here. Likewise, since node2
is to be connected to the second action, the index [1]
is used.
And that should fix your code, assuming i’ve interpreted your intention properly.