예제 #1
0
    pfcRULEasso = spa.ThresholdingAssocMem(0.3,
                                           input_vocab=vocab,
                                           mapping=assoRule,
                                           function=lambda x: 1
                                           if x > 0.1 else 0,
                                           label='pfcRULEasso')
    stim_cue >> pfcRULEasso
    pfcRULEasso >> pfcRULEmemo

    # connections
    stim_cue >> ppc
    stim_cue >> pfcCUE

    motorClean = spa.WTAAssocMem(threshold=0.1,
                                 input_vocab=vocab,
                                 output_vocab=vocab,
                                 mapping=movesMap,
                                 function=lambda x: 1 if x > 0.1 else 0,
                                 label='motorClean')

    nengo.Connection(mdRULE.output,
                     pfcRULEmemo.input,
                     transform=5,
                     synapse=0.05)

    with spa.ActionSelection() as act_sel:
        spa.ifmax(spa.dot(pfcRULEasso, s.AUD), s.AUD >> mdRULE)
        spa.ifmax(spa.dot(pfcRULEasso, s.VIS), s.VIS >> mdRULE)
        spa.ifmax(spa.dot(stim_target, s.AUD * s.RIGHT + s.VIS * s.LEFT),
                  stim_target * ~pfcRULEmemo >> motorClean)
        spa.ifmax(spa.dot(stim_target, s.VIS * s.RIGHT + s.AUD * s.LEFT),
                  stim_target * ~pfcRULEmemo >> motorClean)
예제 #2
0
    def model(self, p):
        vocab_space = spa.Vocabulary(p.D_space, strict=False)
        vocab_space.populate('OBJ1; OBJ2; OBJ3; OBJ4; OBJ5; X; Y')

        vocab_rule = spa.Vocabulary(p.D)
        vocab_rule.populate(
            'OBJ1; OBJ2; OBJ3; OBJ4; OBJ5; BELOW; ABOVE; LEFT; RIGHT; S; O; V')

        vocab_obj = vocab_rule.create_subset(
            ['OBJ1', 'OBJ2', 'OBJ3', 'OBJ4', 'OBJ5'])
        vocab_rel = vocab_rule.create_subset(
            ['BELOW', 'ABOVE', 'LEFT', 'RIGHT'])

        model = spa.Network()
        with model:

            rule = spa.State(vocab_rule)

            objs = spa.State(feedback=1, vocab=vocab_space)

            subject = spa.WTAAssocMem(threshold=0.3, input_vocab=vocab_obj)
            object = spa.WTAAssocMem(threshold=0.3, input_vocab=vocab_obj)
            relation = spa.WTAAssocMem(threshold=0.3, input_vocab=vocab_rel)

            status = spa.State(p.D)

            def input(t):
                t = t % 1.6
                if t < 0.4:
                    return 'OBJ1*S+LEFT*V+OBJ2*O'
                elif t < 0.8:
                    return 'OBJ2*S+LEFT*V+OBJ3*O'
                elif t < 1.2:
                    return 'OBJ3*S+LEFT*V+OBJ4*O'
                elif t < 1.6:
                    return 'OBJ4*S+LEFT*V+OBJ5*O'

            input = spa.Transcode(input, output_vocab=vocab_rule)

            speed = 0.7
            separation = 0.7
            strength = 0.5

            spa.Actions('''
                input -> rule
                reinterpret(rule*~S) ->subject
                reinterpret(rule*~O) ->object
                reinterpret(rule*~V) ->relation
                
                ifmax (dot(relation, BELOW-ABOVE-LEFT-RIGHT)*strength +
                       (dot(objs, translate(subject)*Y) - dot(objs, translate(object)*Y)) +
                       separation):
                            BAD -> status
                            speed*Y*translate(object)-speed*Y*translate(subject) -> objs
                elifmax (dot(relation, BELOW-ABOVE-LEFT-RIGHT)*strength -
                       (dot(objs, translate(subject)*Y) - dot(objs, translate(object)*Y)) -
                       separation):
                            GOOD -> status
                            
                ifmax (dot(relation, ABOVE-BELOW-LEFT-RIGHT)*strength +
                       (dot(objs, translate(subject)*Y) - dot(objs, translate(object)*Y)) +
                       separation):
                            BAD -> status
                            speed*Y*translate(object)-speed*Y*translate(subject) -> objs
                elifmax (dot(relation, ABOVE-BELOW-LEFT-RIGHT)*strength -
                       (dot(objs, translate(subject)*Y) - dot(objs, translate(object)*Y)) -
                       separation):
                            GOOD -> status    
                            
                ifmax (dot(relation, LEFT-RIGHT-ABOVE-BELOW)*strength +
                       (dot(objs, translate(subject)*X) - dot(objs, translate(object)*X)) +
                       separation):
                            BAD -> status
                            speed*X*translate(object)-speed*X*translate(subject) -> objs
                elifmax (dot(relation, LEFT-RIGHT-ABOVE-BELOW)*strength -
                       (dot(objs, translate(subject)*X) - dot(objs, translate(object)*X)) -
                       separation):
                            GOOD -> status
                            
                ifmax (dot(relation, RIGHT-ABOVE-BELOW-LEFT)*strength +
                       (dot(objs, translate(subject)*X) - dot(objs, translate(object)*X)) +
                       separation):
                            BAD -> status
                            speed*X*translate(object)-speed*X*translate(subject) -> objs
                elifmax (dot(relation, RIGHT-ABOVE-BELOW-LEFT)*strength -
                       (dot(objs, translate(subject)*X) - dot(objs, translate(object)*X)) -
                       separation):
                            GOOD -> status                        
                ''')

            def display_node(t, x):
                return x

            display = nengo.Node(display_node, size_in=10)

            nengo.Connection(objs.output,
                             display[0],
                             transform=[vocab_space.parse('OBJ1*X').v])
            nengo.Connection(objs.output,
                             display[1],
                             transform=[vocab_space.parse('OBJ1*Y').v])
            nengo.Connection(objs.output,
                             display[2],
                             transform=[vocab_space.parse('OBJ2*X').v])
            nengo.Connection(objs.output,
                             display[3],
                             transform=[vocab_space.parse('OBJ2*Y').v])
            nengo.Connection(objs.output,
                             display[4],
                             transform=[vocab_space.parse('OBJ3*X').v])
            nengo.Connection(objs.output,
                             display[5],
                             transform=[vocab_space.parse('OBJ3*Y').v])
            nengo.Connection(objs.output,
                             display[6],
                             transform=[vocab_space.parse('OBJ4*X').v])
            nengo.Connection(objs.output,
                             display[7],
                             transform=[vocab_space.parse('OBJ4*Y').v])
            nengo.Connection(objs.output,
                             display[8],
                             transform=[vocab_space.parse('OBJ5*X').v])
            nengo.Connection(objs.output,
                             display[9],
                             transform=[vocab_space.parse('OBJ5*Y').v])

        for net in model.networks:
            if net.label is not None:
                if net.label.startswith('dot'):
                    net.label = ''
                if net.label.startswith('channel'):
                    net.label = ''

        with model:
            self.result = nengo.Probe(display, synapse=0.03)
        return model
예제 #3
0
    # state representation of input
    target  = spa.State(D, label='Target')
    cue     = spa.State(D, label='Cue')
    motor = spa.State(dims, feedback = 1, label = 'motor')


    # Connect to repreesentation of inputs
    target_in   >> target
    cue_in      >> cue

    # pfc
    pfc  = spa.State(dims, feedback = pfcFB,  label = 'pfc')
    vocab = pfc.vocab
    vocab.add('RULE1', vocab.parse('CUE_A+CUE_C'))
    vocab.add('RULE2', vocab.parse('CUE_B+CUE_D'))
    vocab.add('CONTEXT1', vocab.parse('CUE_A+CUE_B'))
    vocab.add('CONTEXT2', vocab.parse('CUE_C+CUE_D'))

    cue >> pfc

    with spa.ActionSelection():
        spa.ifmax( 0.5, s.X*0 >> pfc)
        spa.ifmax( 0.8*spa.dot(pfc, s.RULE1) +  0.8*spa.dot(target, s.LIGHT*(s.RIGHT+s.LEFT)),
                           target*~s.LIGHT >> motor )
        spa.ifmax( 0.8*spa.dot(pfc, s.RULE2) +  0.8*spa.dot(target, s.SOUND*(s.RIGHT+s.LEFT)),
                           target*~s.SOUND >> motor )

    md = spa.WTAAssocMem(threshold = 0.5, input_vocab = pfc.vocab, mapping = map, label = 'MD')
    pfc >> md
    md*0.8 >> pfc
예제 #4
0
    key_range(1, 11, 1) + ['D0=D1*~D1'] +
    ['GET_V ; GET_COM ; GET_ADD ; SET_COM ; SET_ADD ; SET_M'])

with spa.Network() as model:

    input_INSTRUCTIONS = spa.Transcode(lambda t: '\
                D1 * (GET_V) +\
                D2 * (GET_ADD + SET_ADD) +\
                D3 * (GET_COM + SET_COM) + \
                D4 * (SET_M) \
            ',
                                       output_vocab=vocab)
    POS = WM(100, vocab)
    clean_POS = spa.WTAAssocMem(threshold=.2,
                                input_vocab=POS.vocab,
                                mapping=['D1', 'D2', 'D3', 'D4'],
                                n_neurons=50,
                                function=lambda x: x > 0)
    nengo.Connection(POS.output, clean_POS.input)
    INCREMENT = WM(100, vocab)

    PRIM = spa.Bind(neurons_per_dimension=200, vocab=vocab, unbind_right=True)
    GET_PRIM = spa.WTAAssocMem(threshold=.5,
                               input_vocab=PRIM.vocab,
                               mapping=['GET_V', 'GET_COM', 'GET_ADD'],
                               n_neurons=50,
                               function=lambda x: x > 0)
    SET_PRIM = spa.WTAAssocMem(threshold=.5,
                               input_vocab=PRIM.vocab,
                               mapping=['SET_COM', 'SET_ADD', 'SET_M'],
                               n_neurons=50,
예제 #5
0
###########
# Model 7 #
###########

# cleanup memories illustrated

with spa.Network() as model:
    scene = spa.sym.RED * spa.sym.SQUARE + spa.sym.BLUE * spa.sym.CIRCLE
    stim = spa.Transcode(lambda t: 'CIRCLE' if t < 0.25 else 'SQUARE',
                         output_vocab=dim)
    unbind = spa.Transcode(lambda t, x: scene * ~x,
                           input_vocab=dim,
                           output_vocab=dim)

    am = spa.WTAAssocMem(0.4, model.vocabs[dim])

    stim >> unbind
    unbind >> am

    probe = nengo.Probe(am.output, synapse=0.01)

sim = nengo.Simulator(model)
sim.run(0.5)

plt.plot(sim.trange(), spa.similarity(sim.data[probe], model.vocabs[dim]))
plt.xlabel('time (s)')
plt.ylabel('similarity')
plt.legend(model.vocabs[dim].keys())
plt.show()
예제 #6
0
    def construct_network(self):
        self.send_n_neurons_per_dim()
        s = spa.sym
        net = self.network

        # temporary parameters
        self.crosstalk = False
        self.crosstalk_lr = 5e-12

        with net:

            net.input_net = spa.Network(label='inputs', seed=self.seed)

            with net.input_net:
                net.input_net.RETINA_input = spa.Transcode(
                    self.experiment.RETINA_input,
                    input_vocab=self.vocabs['GW'],
                    output_vocab=self.vocabs['GW'])

            net.V = DirectProcessor(
                self.vocabs['GW'],
                self.vocabs['GW'],
                'V',
                receiver=False,  # V only sends info to GW
                seed=self.seed,
                prediction_out=self.crosstalk,
                n_neurons_per_dim=self.n_neurons_per_dim)
            nengo.Connection(net.input_net.RETINA_input.output,
                             net.V.input.input,
                             synapse=None)

            net.FIXATE_detector = nengo.Node(size_in=1,
                                             label='FIXATE detector')
            nengo.Connection(
                net.V.input.output,
                net.FIXATE_detector,
                transform=net.V.output_vocab.parse('FIXATE').v[None, :],
                synapse=.05
            )  # some synaptic delay is necessary to ensure the stimulus has time to enter GW
            net.declare_output(net.FIXATE_detector, None)

            net.M = DirectProcessor(
                self.vocabs['GW'],
                self.vocabs['GW'],
                'M',
                sender=False,  # M only receives info from GW
                seed=self.seed,
                n_neurons_per_dim=self.n_neurons_per_dim)

            net.BTN = nengo.Node(Button(
                SP_vectors=[
                    self.vocabs['GW'].parse('LESS').v,
                    self.vocabs['GW'].parse('MORE').v
                ],
                trial_length=self.experiment.trial_length,
                wait_length=self.experiment.t_start),
                                 label='button',
                                 size_in=self.vocabs['GW'].dimensions)
            nengo.Connection(
                net.M.output.output, net.BTN
            )  # Connect output of M to BTN that records behavioral response

            net.ADD = ADDProcessor(self.vocabs['GW'],
                                   'ADD',
                                   self.n_neurons_per_dim,
                                   self.rng,
                                   self.BG_bias,
                                   self.BG_thr,
                                   feedback=self.proc_feedback,
                                   seed=self.seed)
            with net.input_net:
                net.input_net.ADDEND = spa.Transcode(
                    self.experiment.ADDEND_input,
                    input_vocab=self.vocabs['GW'],
                    output_vocab=self.vocabs['GW'],
                    label='ADDEND')
            nengo.Connection(net.input_net.ADDEND.output,
                             net.ADD.bind.input_right,
                             synapse=None)

            if self.compare_tau != 0:
                net.COM = CompareProcessor(
                    self.vocabs['GW'],
                    self.vocabs['GW'],
                    'COM',
                    self.experiment.trial_length,
                    self.experiment.t_start if self.integrator_reset else 0,
                    self.n_neurons_per_dim,
                    self.rng,
                    self.n_samples,
                    tau=self.compare_tau,
                    seed=self.seed,
                    prediction_in=self.crosstalk)
            else:
                net.COM = AMProcessor(self.vocabs['GW'],
                                      self.vocabs['GW'],
                                      'COM', {
                                          'D2': 'LESS',
                                          'D4': 'LESS',
                                          'D6': 'MORE',
                                          'D8': 'MORE'
                                      },
                                      n_neurons_per_dim=self.n_neurons_per_dim,
                                      seed=self.seed,
                                      prediction_in=self.crosstalk)

            self.processors = [net.V, net.COM, net.M, net.ADD]

            if self.crosstalk:
                net.crosstalk = Prediction(net.V,
                                           net.COM,
                                           rate=self.crosstalk_lr)

            net.GW = GlobalWorkspace(self.vocabs['GW'],
                                     mappings={
                                         net.V:
                                         ['D2', 'D4', 'D6', 'D8', 'FIXATE'],
                                         net.ADD: ['D2', 'D4', 'D6', 'D8'],
                                         net.COM: ['MORE', 'LESS'],
                                     },
                                     n_neurons=self.n_neurons_per_dim['AM'],
                                     seed=self.seed)
            for detector in net.GW.detectors.values():
                net.declare_output(detector, None)

            net.POS = WM(200, self.vocabs['PRIM'])
            net.clean_POS = spa.WTAAssocMem(
                threshold=0,
                input_vocab=net.POS.vocab,
                mapping=['D1', 'D2', 'D3', 'D4'],
                n_neurons=self.n_neurons_per_dim['AM'],
                function=lambda x: x > 0)
            nengo.Connection(net.POS.output, net.clean_POS.input)

            net.INCREMENT = WM(200, self.vocabs['PRIM'])

            nengo.Connection(
                net.clean_POS.output,
                net.INCREMENT.input,
                transform=net.POS.vocab.parse('D1').get_binding_matrix())
            nengo.Connection(net.INCREMENT.output, net.POS.input)

            with net.input_net:
                net.input_net.INSTRUCTIONS = spa.Transcode(
                    self.experiment.INSTRUCTIONS_input,
                    input_vocab=self.vocabs['PRIM'],
                    output_vocab=self.vocabs['PRIM'],
                    label='INSTRUCTIONS')

            net.PRIM = spa.Bind(
                neurons_per_dimension=self.n_neurons_per_dim['Bind'],
                vocab=self.vocabs['PRIM'],
                unbind_right=True)

            net.input_net.INSTRUCTIONS >> net.PRIM.input_left
            net.clean_POS >> net.PRIM.input_right

            # GET selector
            with spa.Network(label='GET selector',
                             seed=self.seed) as net.GET_selector:
                net.GET_selector.labels = []
                with spa.ActionSelection() as net.GET_selector.AS:

                    net.GET_selector.labels.append("GET V (FIXATE)")
                    spa.ifmax(net.GET_selector.labels[-1],
                              self.BG_bias + net.FIXATE_detector,
                              net.V.preconscious >> net.GW.AMs[net.V].input,
                              s.D1 >> net.POS.input, 1 >> net.INCREMENT.reset)

                    net.GET_selector.labels.append("GET ADD")
                    spa.ifmax(
                        net.GET_selector.labels[-1],
                        self.BG_bias + spa.dot(net.PRIM, s.GET_ADD) *
                        (1 - net.GW.detectors[net.ADD]),
                        net.ADD.preconscious >> net.GW.AMs[net.ADD].input,
                        1 >> net.POS.gate,
                    )

                    net.GET_selector.labels.append("GET COM")
                    spa.ifmax(
                        net.GET_selector.labels[-1],
                        self.BG_bias + spa.dot(net.PRIM, s.GET_COM) *
                        (1 - net.GW.detectors[net.COM]),
                        net.COM.preconscious >> net.GW.AMs[net.COM].input,
                        1 >> net.POS.gate,
                    )

                    net.GET_selector.labels.append("Thresholder")
                    spa.ifmax(
                        net.GET_selector.labels[-1],
                        self.BG_bias + self.BG_thr,
                        1 >> net.INCREMENT.gate,
                    )

            # SET selector
            with spa.Network(label='SET selector',
                             seed=self.seed) as net.SET_selector:
                net.SET_selector.labels = []
                with spa.ActionSelection() as net.SET_selector.AS:

                    net.SET_selector.labels.append("SET ADD")
                    spa.ifmax(
                        net.SET_selector.labels[-1],
                        self.BG_bias + spa.dot(net.PRIM, s.SET_ADD) *
                        (1 - net.GW.detectors[net.ADD]),
                        net.GW.AMs[net.COM] >> net.ADD.broadcast,
                        net.GW.AMs[net.V] >> net.ADD.broadcast,
                    )

                    net.SET_selector.labels.append("SET COM")
                    spa.ifmax(
                        net.SET_selector.labels[-1],
                        self.BG_bias + spa.dot(net.PRIM, s.SET_COM) *
                        (1 - net.GW.detectors[net.COM]),
                        net.GW.AMs[net.ADD] >> net.COM.broadcast,
                        net.GW.AMs[net.V] >> net.COM.broadcast,
                    )

                    net.SET_selector.labels.append("SET M")
                    spa.ifmax(
                        net.SET_selector.labels[-1],
                        self.BG_bias + spa.dot(net.PRIM, s.SET_M),
                        net.GW.AMs[net.COM] >> net.M.broadcast,
                        net.GW.AMs[net.V] >> net.M.broadcast,
                        net.GW.AMs[net.ADD] >> net.M.broadcast,
                    )

                    net.SET_selector.labels.append("Thresholder")
                    spa.ifmax(net.SET_selector.labels[-1], self.BG_bias +
                              self.BG_thr)  # Threshold for action
    errorPPC    = spa.State(vocab, feedback = 0.05, label = 'errPPC')
    errorRULE   = spa.State(vocab, feedback = 0.05, label = 'errRULE')
    
    # define inputs
    stim_cue    = spa.Transcode( function = exp.presentCues, output_vocab = vocab, label='stim Cue')
    stim_target = spa.Transcode( function = exp.presentTargets, output_vocab = vocab, label='stim Target')
    
    # connections
    nengo.Connection(md.output, pfcRULE.input, synapse=0.05)
    #md >> pfcRULE
    stim_cue >> ppc
    stim_cue >> pfcCUE
    
    
    motorClean  = spa.WTAAssocMem(threshold=0.1, input_vocab=vocab,
                                        mapping = movesMap,
                                        label = 'motorClean')
    #ppc     >> ppcClean
    #motor   >> motorClean
    
    pfcRULE - md >> pfcRULE 
    
    with spa.ActionSelection():
        spa.ifmax(0.3*spa.dot(s.NOTHING, pfcCUE),s.NOTHING >> pfcRULE)

        spa.ifmax(spa.dot(s.CUE_A + s.CUE_C, pfcCUE),
                        s.VIS >> pfcRULE)
        spa.ifmax(spa.dot(s.CUE_B + s.CUE_D, pfcCUE),
                        s.AUD >> pfcRULE)
        spa.ifmax(spa.dot(stim_target, s.AUD*s.RIGHT+s.VIS*s.LEFT),
                          stim_target*~pfcRULE >> motorClean)