Exemple #1
0
    def model(self, p):
        model = spa.SPA()
        with model:
            model.vision = spa.Buffer(dimensions=p.D)
            model.phrase = spa.Buffer(dimensions=p.D)
            model.motor = spa.Buffer(dimensions=p.D)
            model.noun = spa.Memory(dimensions=p.D, synapse=0.1)
            model.verb = spa.Memory(dimensions=p.D, synapse=0.1)

            model.bg = spa.BasalGanglia(
                spa.Actions(
                    'dot(vision, WRITE) --> verb=vision',
                    'dot(vision, ONE+TWO+THREE) --> noun=vision',
                    '0.5*(dot(vision, NONE-WRITE-ONE-TWO-THREE) + '
                    'dot(phrase, WRITE*VERB))'
                    '--> motor=phrase*~NOUN',
                ))
            model.thal = spa.Thalamus(model.bg)

            model.cortical = spa.Cortical(
                spa.Actions(
                    'phrase=noun*NOUN',
                    'phrase=verb*VERB',
                ))

            def vision_input(t):
                index = int(t / p.time_per_word) % 3
                return ['WRITE', 'ONE', 'NONE'][index]

            model.input = spa.Input(vision=vision_input)

            self.motor_vocab = model.get_output_vocab('motor')
            self.p_thal = nengo.Probe(model.thal.actions.output, synapse=0.03)
            self.p_motor = nengo.Probe(model.motor.state.output, synapse=0.03)
        return model
Exemple #2
0
def test_exception():
    with pytest.raises(Exception):
        with spa.SPA() as model:
            vocab = spa.Vocabulary(16)
            model.buffer = spa.Memory(dimensions=12, vocab=vocab)

    with spa.SPA() as model:
        model.memory = spa.Memory(dimensions=12, subdimensions=3)
Exemple #3
0
    def model(self, p):
        model = spa.SPA()
        with model:
            model.vision = spa.Buffer(dimensions=p.D)
            model.phrase = spa.Buffer(dimensions=p.D)
            model.motor = spa.Buffer(dimensions=p.D)
            model.noun = spa.Memory(dimensions=p.D, synapse=0.1)
            model.verb = spa.Memory(dimensions=p.D, synapse=0.1)

            model.bg = spa.BasalGanglia(
                spa.Actions(
                    'dot(vision, WRITE) --> verb=vision',
                    'dot(vision, ONE+TWO+THREE) --> noun=vision',
                    '0.5*(dot(vision, NONE-WRITE-ONE-TWO-THREE) + '
                    'dot(phrase, WRITE*VERB))'
                    '--> motor=phrase*~NOUN',
                ))
            model.thal = spa.Thalamus(model.bg)

            model.cortical = spa.Cortical(
                spa.Actions(
                    'phrase=noun*NOUN',
                    'phrase=verb*VERB',
                ))

            def vision_input(t):
                index = int(t / p.time_per_word) % 3
                return ['WRITE', 'ONE', 'NONE'][index]

            model.input = spa.Input(vision=vision_input)

            self.motor_vocab = model.get_output_vocab('motor')
            self.p_thal = nengo.Probe(model.thal.actions.output, synapse=0.03)
            self.p_motor = nengo.Probe(model.motor.state.output, synapse=0.03)

        split.split_input_nodes(model, max_dim=64)
        self.replaced = split.split_passthrough(model, max_dim=p.split_max_dim)
        if p.pass_ensembles > 0:
            split.pass_ensembles(model, max_dim=p.pass_ensembles)

        if p.backend == 'nengo_spinnaker':
            import nengo_spinnaker
            nengo_spinnaker.add_spinnaker_params(model.config)
            for node in model.all_nodes:
                if node.output is None:
                    if node.size_in > p.pf_max_dim:
                        print 'limiting', node
                        model.config[node].n_cores_per_chip = p.pf_cores
                        model.config[node].n_chips = p.pf_n_chips
            model.config[nengo_spinnaker.Simulator].placer_kwargs = dict(
                effort=0.1)

        if p.fixed_seed:
            for ens in model.all_ensembles:
                ens.seed = 1

        return model
Exemple #4
0
def test_neurons():
    with spa.SPA() as model:
        model.memory = spa.Memory(dimensions=16, neurons_per_dimension=2)

    assert len(model.memory.state.ensembles) == 1
    assert model.memory.state.ensembles[0].n_neurons == 16 * 2

    with spa.SPA() as model:
        model.memory = spa.Memory(dimensions=16, subdimensions=1,
                                  neurons_per_dimension=2)

    assert len(model.memory.state.ensembles) == 16
    assert model.memory.state.ensembles[0].n_neurons == 2
Exemple #5
0
def test_run(Simulator, seed, plt):
    with spa.SPA(seed=seed) as model:
        model.memory = spa.Memory(dimensions=32)

        def input(t):
            if 0 <= t < 0.05:
                return 'A'
            else:
                return '0'

        model.input = spa.Input(memory=input)

    memory, vocab = model.get_module_output('memory')

    with model:
        p = nengo.Probe(memory, 'output', synapse=0.03)

    sim = Simulator(model)
    sim.run(0.5)
    t = sim.trange()

    similarity = np.dot(sim.data[p], vocab.vectors.T)
    plt.plot(t, similarity)
    plt.ylabel("Similarity to 'A'")
    plt.xlabel("Time (s)")

    # value should peak above 1.0, then decay down to near 1.0
    assert np.mean(similarity[(t > 0.05) & (t < 0.1)]) > 1.2
    assert np.mean(similarity[(t > 0.2) & (t < 0.3)]) > 0.8
    assert np.mean(similarity[t > 0.49]) > 0.7
Exemple #6
0
def test_run_decay(Simulator, plt, seed):
    with spa.SPA(seed=seed) as model:
        model.memory = spa.Memory(dimensions=32, tau=0.05)

        def input(t):
            if 0 <= t < 0.05:
                return 'A'
            else:
                return '0'

        model.input = spa.Input(memory=input)

    memory, vocab = model.get_module_output('memory')

    with model:
        p = nengo.Probe(memory, 'output', synapse=0.03)

    sim = Simulator(model)
    sim.run(0.3)
    data = np.dot(sim.data[p], vocab.vectors.T)

    t = sim.trange()
    plt.plot(t, data)

    assert data[t == 0.05, 0] > 1.0
    assert data[t == 0.299, 0] < 0.4
Exemple #7
0
def test_basic():
    with spa.SPA() as model:
        model.memory = spa.Memory(dimensions=16)

    input = model.get_module_input('memory')
    output = model.get_module_output('memory')
    assert input[0] is model.memory.state.input
    assert output[0] is model.memory.state.output
    assert input[1] is output[1]
    assert input[1].dimensions == 16
Exemple #8
0
        def __init__(self):
            self.memory = spa.Memory(dimensions=32, tau=0.05)

            def input(t):
                if 0 <= t < 0.05:
                    return 'A'
                else:
                    return '0'

            self.input = spa.Input(memory=input)
    def model(self, p):
        model = spa.SPA()
        with model:
            model.vision = spa.Buffer(dimensions=p.D)
            model.state = spa.Memory(dimensions=p.D)
            actions = ['dot(state, S%d) --> state=S%d' % (i,(i+1))
                       for i in range(p.n_actions - 1)]
            actions.append('dot(state, S%d) --> state=vision' %
                           (p.n_actions - 1))
            model.bg = spa.BasalGanglia(actions=spa.Actions(*actions))
            model.thal = spa.Thalamus(model.bg)

            model.input = spa.Input(vision='S%d' % p.start,
                                    state=lambda t: 'S%d' % p.start if
                                              t < 0.1 else '0')

            self.probe = nengo.Probe(model.thal.actions.output, synapse=0.03)

        return model
Exemple #10
0
    def model(self, p):
        model = spa.SPA()
        with model:
            model.vision = spa.Buffer(dimensions=p.D)
            model.state = spa.Memory(dimensions=p.D)
            actions = [
                'dot(state, S%d) --> state=S%d' % (i, (i + 1))
                for i in range(p.n_actions - 1)
            ]
            actions.append('dot(state, S%d) --> state=vision' %
                           (p.n_actions - 1))
            model.bg = spa.BasalGanglia(actions=spa.Actions(*actions))
            model.thal = spa.Thalamus(model.bg)

            model.input = spa.Input(vision='S%d' % p.start,
                                    state=lambda t: 'S%d' % p.start
                                    if t < 0.1 else '0')

            self.probe = nengo.Probe(model.thal.actions.output, synapse=0.03)

        split.split_passthrough(model, max_dim=p.split_max_dim)
        if p.pass_ensembles > 0:
            split.pass_ensembles(model, max_dim=p.pass_ensembles)

        if p.backend == 'nengo_spinnaker':
            import nengo_spinnaker
            nengo_spinnaker.add_spinnaker_params(model.config)
            for node in model.all_nodes:
                if node.output is None:
                    if node.size_in > p.pf_max_dim:
                        print 'limiting', node
                        model.config[node].n_cores_per_chip = p.pf_cores
                        model.config[node].n_chips = p.pf_n_chips

            model.config[nengo_spinnaker.Simulator].placer_kwargs = dict(
                effort=0.1)

        if p.fixed_seed:
            for ens in model.all_ensembles:
                ens.seed = 1

        return model
Exemple #11
0
    def model(self, p):
        model = spa.SPA()
        with model:
            model.state = spa.Memory(dimensions=p.D)
            actions = [
                'dot(state, S%d) --> state=S%d' % (i, (i + 1) % p.n_actions)
                for i in range(p.n_actions)
            ]
            model.bg = spa.BasalGanglia(actions=spa.Actions(*actions))
            model.thal = spa.Thalamus(model.bg)

            def state_input(t):
                if t < 0.1:
                    return 'S0'
                else:
                    return '0'

            model.input = spa.Input(state=state_input)

            self.probe = nengo.Probe(model.thal.actions.output, synapse=0.03)
        return model
Exemple #12
0
### Step 1: Create the model

# In[ ]:

# Number of dimensions for the SPs
dimensions = 64

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

with model:
    # Specify the modules to be used
    model.vision = spa.Buffer(dimensions=dimensions, neurons_per_dimension=100)
    model.phrase = spa.Buffer(dimensions=dimensions, neurons_per_dimension=100)
    model.motor = spa.Buffer(dimensions=dimensions, neurons_per_dimension=100)
    model.noun = spa.Memory(dimensions=dimensions, neurons_per_dimension=100)
    model.verb = spa.Memory(dimensions=dimensions, neurons_per_dimension=100)

    # Specify the action mapping
    actions = spa.Actions(
        'dot(vision, WRITE) --> verb=vision',
        'dot(vision, ONE+TWO+THREE) --> noun=vision',
        '0.5*(dot(NONE-WRITE-ONE-TWO-THREE, vision) '
        '+ dot(phrase, WRITE*VERB)) '
        '--> motor=phrase*~NOUN',
    )
    cortical_actions = spa.Actions('phrase=noun*NOUN + verb*VERB', )
    model.bg = spa.BasalGanglia(actions=actions)
    model.thal = spa.Thalamus(model.bg)
    model.cortical = spa.Cortical(actions=cortical_actions)
Exemple #13
0
 def __init__(self):
     self.memory = spa.Memory(dimensions=16)
Exemple #14
0
    def run(self):
        n_neurons = 40
        subdim = 16
        direct = False
        output = self.stimuli.output  # vector output from coherence score
        threshold = self.stimuli.threshold  # for correct answer on inf task
        g_transform = np.transpose(np.ones((1, self.dimensions)))  # mem gate

        model = spa.SPA(label='ConceptModel', seed=self.seed)

        with model:

            # Vision Component
            model.vision = spa.Buffer(dimensions=self.dimensions,
                                      subdimensions=subdim,
                                      neurons_per_dimension=n_neurons,
                                      vocab=self.main_voc,
                                      direct=direct)

            # Memory Component
            model.sp_mem = spa.Buffer(dimensions=self.dimensions,
                                      subdimensions=subdim,
                                      neurons_per_dimension=n_neurons,
                                      vocab=self.main_voc,
                                      direct=direct)
            model.context_mem = spa.Memory(dimensions=self.dimensions,
                                           subdimensions=subdim,
                                           neurons_per_dimension=n_neurons,
                                           vocab=self.main_voc,
                                           tau=0.01 / 0.3,
                                           direct=direct)

            # Inferential Evaluation Subsystem
            model.inference = spa.Buffer(dimensions=self.dimensions,
                                         subdimensions=subdim,
                                         neurons_per_dimension=n_neurons,
                                         vocab=self.feat_voc,
                                         direct=direct)
            model.score = spa.Memory(dimensions=1,
                                     neurons_per_dimension=3000,
                                     synapse=0.05,
                                     direct=direct)
            model.gatesignal = spa.Memory(dimensions=1,
                                          neurons_per_dimension=500,
                                          synapse=0.05,
                                          direct=direct)
            model.cleanup1 = spa.AssociativeMemory(
                input_vocab=self.feat_voc,
                output_vocab=self.weight_voc,
                n_neurons_per_ensemble=250,
                threshold=0.25)

            # Perceptual Evaluation Subsystem
            model.cleanup2 = spa.AssociativeMemory(input_vocab=self.label_voc,
                                                   output_vocab=self.label_voc,
                                                   n_neurons_per_ensemble=1000,
                                                   threshold=threshold)

            # Shared Component
            model.decision = spa.Memory(dimensions=self.dimensions,
                                        subdimensions=subdim,
                                        neurons_per_dimension=n_neurons,
                                        vocab=self.label_voc,
                                        tau=0.01 / 0.3,
                                        synapse=0.05,
                                        direct=direct)

            # Motor Component
            model.motor = spa.Memory(dimensions=self.dimensions,
                                     subdimensions=subdim,
                                     neurons_per_dimension=n_neurons,
                                     vocab=self.label_voc,
                                     synapse=0.1,
                                     direct=direct)

            # Convenient probing of rule applications
            if self.raster:
                model.apps = spa.Buffer(dimensions=self.dimensions,
                                        subdimensions=subdim,
                                        neurons_per_dimension=n_neurons,
                                        vocab=self.feat_voc,
                                        direct=direct)

                self.pApps = nengo.Probe(model.apps.state.output, synapse=0.03)
                self.appSpikes = nengo.Probe(model.apps.state.ea_ensembles[3],
                                             'spikes')

                nengo.Connection(model.cleanup1.output, model.apps.state.input)

            # Action definitions
            actions = spa.Actions(
                'dot(vision, POSNER) --> context_mem=VIS',
                'dot(vision, BROOKS) --> context_mem=VIS',
                'dot(vision, MURPHY) --> context_mem=INFER',
                'dot(context_mem, VIS)   --> gatesignal=2, context_mem=R5',
                'dot(context_mem, INFER) --> context_mem=R1',
                'dot(context_mem, R1)    --> inference=sp_mem*~R1, context_mem=R2',
                'dot(context_mem, R2)    --> inference=sp_mem*~R2, context_mem=R3',
                'dot(context_mem, R3)    --> inference=sp_mem*~R3, context_mem=R4',
                'dot(context_mem, R4)    --> inference=sp_mem*~R4, context_mem=R5',
                'dot(context_mem, R5)    --> motor=decision')

            # Basal ganglia and thalamus
            model.bg = spa.BasalGanglia(actions)
            model.thal = spa.Thalamus(model.bg)

            # Subnetworks defined outside of SPA
            model.product = Product(600, self.dimensions)
            model.vis_gate = Product(300, self.dimensions)
            model.mem_gate = Product(300, self.dimensions)
            model.conv = CircularConvolution(250,
                                             self.dimensions,
                                             invert_a=True)

            # Connections for gate with memory for perceptual evaluation tasks
            nengo.Connection(model.vision.state.output, model.vis_gate.B)
            nengo.Connection(model.gatesignal.state.output,
                             model.vis_gate.A,
                             transform=g_transform)
            nengo.Connection(model.vis_gate.output, model.conv.A)
            nengo.Connection(model.sp_mem.state.output, model.mem_gate.B)
            nengo.Connection(model.gatesignal.state.output,
                             model.mem_gate.A,
                             transform=g_transform)
            nengo.Connection(model.mem_gate.output, model.conv.B)
            nengo.Connection(model.conv.output, model.decision.state.input)

            # Connections for inferential evaluation tasks
            nengo.Connection(model.inference.state.output,
                             model.cleanup1.input)
            nengo.Connection(model.cleanup1.output, model.product.A)
            nengo.Connection(model.vision.state.output, model.product.B)
            nengo.Connection(model.cleanup2.output, model.decision.state.input)
            nengo.Connection(model.product.output,
                             model.score.state.input,
                             transform=model.product.dot_product_transform())
            nengo.Connection(model.score.state.output,
                             model.cleanup2.input,
                             transform=np.transpose(output))

            # Input to visual buffer
            def vision(t):
                if t < 0.08: return self.stimuli.task
                if 0.0801 <= t < 1: return self.probe
                else: return '0'

            model.input = spa.Input(vision=vision, sp_mem=self.stimuli.memory)

            # Inhibit the gate with inference actions
            actions = [2, 4, 5, 6, 7, 8]
            target = model.gatesignal
            for action in actions:
                for e in target.all_ensembles:
                    nengo.Connection(model.thal.actions.ensembles[action],
                                     e.neurons,
                                     transform=[[-2]] * e.n_neurons)

            # Set radius for ensemble computing scalar coherence score.
            for ens in model.score.state.ensembles:
                ens.radius = 2

            # Define probes for semantic pointer plots
            self.pVision = nengo.Probe(model.vision.state.output, synapse=0.03)
            self.pMotor = nengo.Probe(model.motor.state.output, synapse=0.03)
            self.pMemory = nengo.Probe(model.sp_mem.state.output, synapse=0.03)
            self.pContext = nengo.Probe(model.context_mem.state.output,
                                        synapse=0.03)
            self.pScore = nengo.Probe(model.score.state.output, synapse=0.03)
            self.pDecision = nengo.Probe(model.decision.state.output,
                                         synapse=0.03)
            self.pActions = nengo.Probe(model.thal.actions.output,
                                        synapse=0.01)
            self.pUtility = nengo.Probe(model.bg.input, synapse=0.01)

            # Define probes for spike rasters
            self.visSpikes = nengo.Probe(model.vision.state.ea_ensembles[3],
                                         'spikes')
            self.conSpikes = nengo.Probe(
                model.context_mem.state.ea_ensembles[5], 'spikes')
            self.memSpikes = nengo.Probe(model.sp_mem.state.ea_ensembles[7],
                                         'spikes')
            self.motSpikes = nengo.Probe(model.motor.state.ea_ensembles[1],
                                         'spikes')
            self.scoSpikes = nengo.Probe(model.score.state.ea_ensembles[0],
                                         'spikes')

        # Run the model
        sim = nengo.Simulator(model)
        sim.run(0.45)

        # Save graph if plotting chosen
        if self.raster:
            graph = Plotter(self, sim)
            if self.stimuli.task == 'MURPHY':
                graph.plot_spikes_inf()
            else:
                graph.plot_spikes_vis()

        # Assess correctness of output
        self.measure_output(sim)
Exemple #15
0
 def __init__(self):
     vocab = spa.Vocabulary(16)
     self.buffer = spa.Memory(dimensions=12, vocab=vocab)
Exemple #16
0
    inp_vecs[1,:] = act_id_vocab['PUT_KETTLE_UNDER_TAP'].v
    inp_vecs[2,:] = act_id_vocab['BOIL_KETTLE'].v

    out_vecs[0,:] = base_vocab['KETTLE_UNDER_TAP'].v
    out_vecs[1,:] = base_vocab['KETTLE_UNPLUGGED'].v
    out_vecs[2,:] = 0.4* base_vocab['WATER_IN_KETTLE'].v + 0.6*base_vocab['KETTLE_PLUGGED_IN'].v


    motor_sys = nodes.MotorSystem(act_id_vocab, world)
    vision_sys = nodes.VisualSystem(act_id_vocab, world)
    check_sys = nodes.VisualSystem(goal_check_vocab, world, _)

    with spa.SPA() as model:

        # For managing control signals
        model.ctrl = spa.Memory(dimensions=D, tau=0.05) 
        model.switch = spa.Memory(dimensions=D, vocab=signal_vocab, synapse=0.1, tau=0.15)

        # Main state representations    
        model.m_goal = spa.Memory(dimensions=D, vocab=base_vocab)
        model.i_goal = spa.Memory(dimensions=D, vocab=base_vocab, synapse=0.005, tau=0.05)
        model.action = spa.Memory(dimensions=D, vocab=act_id_vocab, synapse=0.005, tau=0.03)
        model.effect = spa.Memory(dimensions=D, vocab=base_vocab, synapse=0.005, tau=0.05)
        model.precon = spa.Memory(dimensions=D, vocab=base_vocab, synapse=0.005, tau=0.05)
        model.location = spa.State(dimensions=D, vocab=base_vocab)
        
        # Associative Memories 
        model.loc_to_object = spa.AssociativeMemory(input_vocab=obj_vocab, output_vocab=obj_id_vocab,
                                                    input_keys=objects, output_keys=objects,
                                                    wta_output=False, threshold=.5)
        
__author__ = 'bogdanp'

import nengo
import nengo.spa as spa
import numpy as np

dimensions = 64  # the dimensionality of the vectors

model = spa.SPA()
with model:
    model.cortex = spa.Buffer(dimensions=dimensions, neurons_per_dimension=100)
    model.motor = spa.Buffer(dimensions=dimensions, neurons_per_dimension=100)
    model.buffer = spa.Buffer(dimensions=dimensions, neurons_per_dimension=100)
    # model.buffer2 = spa.Buffer(dimensions=dimensions, neurons_per_dimension=100)
    model.direction = spa.Memory(dimensions=dimensions, tau=0.01)
    # model.time = nengo.networks.Oscillator(1, 1, 500)
    # model.perceived_time = spa.Memory(dimensions=dimensions, tau=0.1)
    # Specify the action mapping
    actions = spa.Actions(
        '.8 * dot(cortex, S) + dot(buffer, L)--> motor = LS, cortex = S',
        '.8 * dot(cortex, S) + dot(buffer, R)--> motor = RS, cortex = S',
        '.8 * dot(cortex, G) + dot(buffer, L)--> motor = LG, cortex = G',
        '.8 * dot(cortex, G) + dot(buffer, R)--> motor = RG, cortex = G',
    )

    cortical_actions = spa.Actions('buffer= buffer + .1 * direction ')
    model.cortical = spa.Cortical(cortical_actions)

    model.bg = spa.BasalGanglia(actions=actions)
    model.thal = spa.Thalamus(model.bg)
Exemple #18
0
 def __init__(self):
     self.memory = spa.Memory(dimensions=16,
                              subdimensions=1,
                              neurons_per_dimension=2)
Exemple #19
0
# The new graph is a "Semantic pointer" graph.  Rather than showing the
# individual values, it shows how close the currently represented vector is
# to the ideal original vectors.  Furthermore, you can use it as an input
# system as well, and define new concepts.

# Press play to start the simulation running.  Now right-click on the "vision"
# graph (the blank space above the "vision" box in the diagram).  Select
# "Set value..." and put in CAT as a value.  Nengo will randomly generate a
# new vector to mean CAT and will feed it into the model.  Since the vision
# system is connected to the memory system, the memory will gradually store CAT
# as well.  Now right-click on vision, go to "Set value" and just leave it
# blank (click OK).  The CAT in vision will go away, but the memory should
# continue to store CAT.  Now set the vision to DOG.  This new vector will
# be fed into the memory, gradually replacing the CAT.  (The size and darkness
# of the words indicates how similar the vector is to the ideal vectors for
# CAT and DOG).

import nengo
import nengo.spa as spa

D = 32  # the dimensionality of the vectors

model = spa.SPA()
with model:
    model.vision = spa.Buffer(D)

    model.memory = spa.Memory(D, synapse=0.1)

    nengo.Connection(model.vision.state.output,
                     model.memory.state.input,
                     transform=0.1)
# Number of dimensions for the SPs
dimensions = 64

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

with model:
    # Initial the three visual perceptual memory component and one working memory component.
    model.vision1 = spa.State(dimensions=dimensions,
                              neurons_per_dimension=100,
                              feedback=0.7)
    model.vision2 = spa.State(dimensions=dimensions,
                              neurons_per_dimension=100,
                              feedback=0.7)
    model.cue = spa.Buffer(dimensions=dimensions, neurons_per_dimension=100)
    model.representation = spa.Memory(dimensions=dimensions,
                                      neurons_per_dimension=100)

    # Specify the action mapping and attention function
    actions = spa.Actions(
        'dot(cue, LEFT) --> vision1=vision1*2',
        'dot(cue, RIGHT) --> vision2=vision2*2',
    )
    cortical_actions = spa.Actions('representation=vision1+vision2', )
    model.bg = spa.BasalGanglia(actions=actions)
    model.thal = spa.Thalamus(model.bg)
    model.cortical = spa.Cortical(actions=cortical_actions)


# Stimulus dataset
# input visual1
def input_vision1(t):
import nengo
import nengo.spa as spa

D = 32  # the dimensionality of the vectors

model = spa.SPA()
with model:
    model.vision = spa.Buffer(D)
    
    model.noun = spa.Memory(D, synapse=0.2)
    model.verb = spa.Memory(D, synapse=0.2)
    model.sentence = spa.Buffer(D)
    
    model.speech = spa.Buffer(D)
    model.hand = spa.Buffer(D)

    actions = spa.Actions(
        'dot(vision, WRITE+SAY) --> verb=vision',
        'dot(vision, A+B+C+D+E) --> noun=vision',
        'dot(sentence, VERB*WRITE) - dot(vision, WRITE+SAY+A+B+C+D+E)'
            '--> hand=sentence*~NOUN',
        'dot(sentence, VERB*SAY) - dot(vision, WRITE+SAY+A+B+C+D+E)'
            '--> speech=sentence*~NOUN',
        )
        
    model.bg = spa.BasalGanglia(actions)
    model.thalamus = spa.Thalamus(model.bg)
    
    model.cortical = spa.Cortical(spa.Actions(
        'sentence=verb*VERB+noun*NOUN',
        ))
Exemple #22
0
                           feedback=0.7,
                           vocab=vocab)
 model.vision2 = spa.State(dimensions=dimensions,
                           neurons_per_dimension=100,
                           feedback=0.7,
                           vocab=vocab)
 model.cue = spa.State(dimensions=dimensions,
                       neurons_per_dimension=100,
                       feedback=0.7,
                       vocab=vocab)
 model.target = spa.State(dimensions=dimensions,
                          neurons_per_dimension=100,
                          feedback=0.7,
                          vocab=vocab)
 model.representation = spa.Memory(dimensions=dimensions,
                                   neurons_per_dimension=100,
                                   vocab=vocab)
 model.awake = spa.Memory(dimensions=dimensions,
                          neurons_per_dimension=100,
                          vocab=vocab)
 model.similar = spa.Compare(dimensions=dimensions, vocab=vocab)
 model.output = spa.Buffer(dimensions=dimensions, neurons_per_dimension=100)
 model.state = spa.Buffer(dimensions=dimensions, neurons_per_dimension=100)
 # Specify the action mapping and attention function
 actions = spa.Actions(
     #'dot(cue, LEFT) --> vision1=vision1*2',
     #'dot(cue, RIGHT) --> vision2=vision2*2',
     #'dot(cue, HIGH) --> output = LOW'
     #'dot(cue, LOW) --> output = LOW'
     'similar --> output = Match',
     '1.5 - similar --> output = NotMatch',
Exemple #23
0
# 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[ ]:

# Number of dimensions for the Semantic Pointers
dimensions = 128

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

with model:
    # Specify the modules to be used
    model.vision = spa.Buffer(dimensions=dimensions, neurons_per_dimension=100)
    model.motor = spa.Buffer(dimensions=dimensions, neurons_per_dimension=100)
    model.memory = spa.Memory(dimensions=dimensions,
                              neurons_per_dimension=100,
                              synapse=0.1)

    # Specify the action mapping
    actions = spa.Actions(
        'dot(vision, STATEMENT) --> memory = vision',
        'dot(vision, QUESTION) --> motor = ~vision*memory',
    )
    model.bg = spa.BasalGanglia(actions=actions)
    model.thal = spa.Thalamus(model.bg)

# ## Provide the input

# In[ ]:

def _test_sequence(Simulator, plt, seed, outfile, prune_passthrough):
    dimensions = 32
    subdimensions = 16
    T = 4.0
    seq_length = 6

    with spa.SPA(seed=seed) as model:
        model.state = spa.Memory(dimensions=dimensions,
                                 subdimensions=subdimensions)

        seq_actions = [
            'dot(state,A%d) --> state=A%d' % (i, (i + 1) % seq_length)
            for i in range(seq_length)
        ]

        model.bg = spa.BasalGanglia(spa.Actions(*seq_actions))
        model.thal = spa.Thalamus(model.bg)

        def stim_state(t):
            if t < 0.1:
                return 'A0'
            else:
                return '0'

        model.input = spa.Input(state=stim_state)

        p_state = nengo.Probe(model.state.state.output, synapse=0.01)

        if 'spinnaker' in Simulator.__module__:
            nengo_spinnaker.add_spinnaker_params(model.config)
            model.config[
                model.input.input_nodes['state']].function_of_time = True

    vocab = model.get_input_vocab('state')

    if prune_passthrough:
        model = remove_passthrough_nodes(model)

    sim = Simulator(model)
    sim.run(T)

    t = sim.trange()
    data = sim.data[p_state]
    ideal = np.array([vocab.parse('A%d' % i).v for i in range(seq_length)])
    dotp = np.dot(data, ideal.T)

    best = np.argmax(dotp, axis=1)
    delta = np.diff(best)
    indexes = np.where(delta != 0)
    # [:, 1:] ignores the first transition, which is meaningless
    delta_t = np.diff(indexes)[:, 1:] * 0.001

    mean = np.mean(delta_t)
    std = np.std(delta_t)

    outfile.write('"n_neurons": %d,\n' % sum(e.n_neurons
                                             for e in model.all_ensembles))
    outfile.write('"simtime": %f,\n' % T)
    outfile.write('"timing_mean": %f,\n' % mean)
    outfile.write('"timing_std": %f,\n' % std)

    figsize = (onecolumn, 4.0) if horizontal else (onecolumn * 2, 3.0)
    setup(figsize=figsize,
          palette_args={
              'palette': "cubehelix",
              'n_colors': 6
          })
    plt.plot(t[t < 1.0], dotp[t < 1.0])
    for transition in t[indexes[0]]:
        plt.axvline(transition, c='0.5', lw=1, ls=':')
    plt.ylabel('Similarity to item')
    plt.xlabel('Time (s)')
    plt.xlim(right=1.0)
    sns.despine()
    if prune_passthrough:
        plt.saveas = 'results-4.svg'
    else:
        plt.saveas = 'results-5.svg'

    if hasattr(sim, 'close'):
        sim.close()
Exemple #25
0
import nengo
import nengo.spa as spa

model = spa.SPA(label="Parser")
with model:
    model.vision = spa.Buffer(dimensions=32)
    model.noun = spa.Memory(dimensions=32)
    model.verb = spa.Memory(dimensions=32)

    model.sentence = spa.Buffer(dimensions=32)

    actions = spa.Actions(
        'dot(vision, WRITE + READ + RUN) --> verb=vision * 0.5',
        'dot(vision, ONE + TWO + THREE) --> noun=vision * 0.5',
    )
    model.bg = spa.BasalGanglia(actions)
    model.thalamus = spa.Thalamus(model.bg)

    cortical_action = spa.Actions('sentence = verb * VERB + noun * NOUN', )
    model.cortical = spa.Cortical(cortical_action)

    nengo.Probe(model.vision.state.output)
    nengo.Probe(model.noun.state.output)
    nengo.Probe(model.verb.state.output)
    nengo.Probe(model.sentence.state.output)
    nengo.Probe(model.bg.input)
    nengo.Probe(model.thalamus.actions.output)

import nengo_gui
gui = nengo_gui.Config()
gui[model].scale = 0.18071493982562714
# Tutorial 21: Sequential Semantic Pointer Actions

# In this example, we define a set of actions that follow through a
# repeating sequence (A, B, C, D, E).  This shows that you can define
# actions which affect the performance of later actions.

import nengo
import nengo.spa as spa

D = 32  # the dimensionality of the vectors

model = spa.SPA()
with model:
    model.memory = spa.Memory(D)

    actions = spa.Actions(
        'dot(memory, A) --> memory=B',
        'dot(memory, B) --> memory=C',
        'dot(memory, C) --> memory=D',
        'dot(memory, D) --> memory=E',
        'dot(memory, E) --> memory=A',
    )

    model.bg = spa.BasalGanglia(actions)
    model.thalamus = spa.Thalamus(model.bg)
from nengo import spa


# ## Create the model

# In[ ]:

# Number of dimensions for the Semantic Pointers
dimensions = 32

model = spa.SPA(label="Simple question answering")

with model:
    model.color_in = spa.Buffer(dimensions=dimensions)
    model.shape_in = spa.Buffer(dimensions=dimensions)
    model.conv = spa.Memory(dimensions=dimensions, subdimensions=4, synapse=0.4)
    model.cue = spa.Buffer(dimensions=dimensions)
    model.out = spa.Buffer(dimensions=dimensions)
    
    # Connect the buffers
    cortical_actions = spa.Actions(
        'conv = color_in * shape_in',
        'out = conv * ~cue'
    )
    model.cortical = spa.Cortical(cortical_actions)  


# ## Provide the input
# 
# The color input will `RED` and then `BLUE` for 0.25 seconds each before being turned off. In the same way the shape input will be `CIRCLE` and then `SQUARE` for 0.25 seconds each. Thus, the network will bind alternatingly `RED * CIRCLE` and `BLUE * SQUARE` for 0.5 seconds each.
#