SPA Sequence Routed exampleΒΆ


Nengo example: Routed sequencing

This demo uses the basal ganglia model to cycle through a 5 element sequence, where an arbitrary start can be presented to the model. The addition of routing allows the system to choose between two different actions: whether to go through the sequence, or be driven by the visual input. If the visual input has its value set to 0.8*START+D (for instance), it will begin cycling through at D->E, etc. The 0.8 scaling helps ensure start is unlikely to accidently match other SPAs (which can be a problem in low dimensional examples like this one).

In [ ]:
# Setup for the notebook
import matplotlib.pyplot as plt
%matplotlib inline

import nengo
%load_ext nengo.ipynb
from nengo import spa
<IPython.core.display.Javascript at 0x7f048c313110>

Step 1: Create the model

Notice that when you specify actions, you're determining which modules are connected to which. For example, by having a mapping that depends on the state of cortex, you are determining that the cortex and basal ganglia must be connected. As well, when you specify that the result of the action changes the state of cortex, then you are determining that thalamus must be connected to cortex.

In [2]:
# Number of dimensions for the Semantic Pointers
dimensions = 16

# Make a model object with the SPA network
model = spa.SPA(label='Routed_Sequence')

with model:
    # Specify the modules to be used
    model.cortex = spa.Buffer(dimensions=dimensions) = spa.Buffer(dimensions=dimensions) 
    # Specify the action mapping
    actions = spa.Actions(
        'dot(vision, START) --> cortex = vision',
        'dot(cortex, A) --> cortex = B',
        'dot(cortex, B) --> cortex = C',
        'dot(cortex, C) --> cortex = D',
        'dot(cortex, D) --> cortex = E',
        'dot(cortex, E) --> cortex = A'
    ) = spa.BasalGanglia(actions=actions)
    model.thal = spa.Thalamus(

Step 2: Provide the input

Specify a function that provides the model with an initial input semantic pointer.

In [3]:
def start(t):
    if t < 0.1:
        return '0.8*START+D'
        return '0'

with model:
    model.input = spa.Input(vision=start)

Step 3: Probe the output

In [4]:
with model:
    cortex = nengo.Probe(model.cortex.state.output, synapse=0.01)
    vision = nengo.Probe(, synapse=0.01)
    actions = nengo.Probe(model.thal.actions.output, synapse=0.01)
    utility = nengo.Probe(, synapse=0.01)

Step 4: Run the model

In [5]:
# Create the simulator object
with nengo.Simulator(model) as sim:
    # Simulate the model for 0.5 seconds

Step 5: Plot the results

In [6]:
fig = plt.figure(figsize=(12,8))
p1 = fig.add_subplot(4,1,1)
p1.plot(sim.trange(), model.similarity(, vision))
p1.legend(model.get_output_vocab('vision').keys, fontsize='x-small')

p2 = fig.add_subplot(4,1,2)
p2.plot(sim.trange(), model.similarity(, cortex))
p2.legend(model.get_output_vocab('cortex').keys, fontsize='x-small')

p3 = fig.add_subplot(4,1,3)

p4 = fig.add_subplot(4,1,4)


Download spa_sequence_routed as an IPython notebook or Python script.