Пример #1
0
    def model(self, p):
        random.seed(p.exp_seed)

        data_dir = os.path.join(
            os.path.dirname(__file__), os.pardir, os.pardir, 'data')
        sp_path = os.path.join(data_dir, 'associationmatrices')
        assoc, i2w, _ = load_assoc_mat(sp_path, p.assocmat)

        sp_path = os.path.join(data_dir, 'semanticpointers')
        pointers, _, _ = load_pointers(sp_path, p.sp_file)

        rat_path = os.path.join(data_dir, 'rat', p.ratfile)
        self.rat_items = list(filter_valid(load_rat_items(rat_path), i2w))

        with spa.SPA(seed=p.model_seed) as model:
            self.model = model
            # set up vocab
            self.vocab = model.get_default_vocab(p.d)
            for i, pointer in enumerate(pointers):
                sanitized = i2w[i].upper().replace(' ', '_').replace(
                    '+', '_').replace('-', '_').replace('&', '_').replace(
                        "'", '_')
                self.vocab.add(sanitized, pointer)

            # set up model
            self.stimulus = Stimulus(self.rat_items)
            model.stimulus = StimulusModule(
                self.stimulus, self.vocab, p.neurons_per_dimension)
            model.rat_model = FfwdConnectionsRat(
                assoc, self.vocab,
                neurons_per_dimension=p.neurons_per_dimension)
            nengo.Connection(model.stimulus.cue1.output, model.rat_model.cue1)
            nengo.Connection(model.stimulus.cue2.output, model.rat_model.cue2)
            nengo.Connection(model.stimulus.cue3.output, model.rat_model.cue3)
            self.p_output = nengo.Probe(
                model.rat_model.rat_state.output, synapse=0.003)
            self.p_cue1 = nengo.Probe(
                model.stimulus.cue1.output, synapse=0.003)
            self.p_cue2 = nengo.Probe(
                model.stimulus.cue2.output, synapse=0.003)
            self.p_cue3 = nengo.Probe(
                model.stimulus.cue3.output, synapse=0.003)
            self.p_spikes = nengo.Probe(
                model.rat_model.rat_state.state_ensembles.ensembles[0].neurons,
                'spikes')

            tr = np.dot(
                self.vocab.vectors.T,
                np.dot(assoc.T, self.vocab.vectors)) / 3.
            direct_result = nengo.Ensemble(
                n_neurons=1, dimensions=p.d, neuron_type=nengo.Direct())
            nengo.Connection(
                model.stimulus.cue1.output, direct_result, transform=tr)
            nengo.Connection(
                model.stimulus.cue2.output, direct_result, transform=tr)
            nengo.Connection(
                model.stimulus.cue3.output, direct_result, transform=tr)
            self.p_direct = nengo.Probe(direct_result, synapse=0.003)

        return model
Пример #2
0
    def model(self, p):
        random.seed(p.exp_seed)

        data_dir = os.path.join(
            os.path.dirname(__file__), os.pardir, os.pardir, 'data')
        sp_path = os.path.join(data_dir, 'semanticpointers')
        pointers, i2w, _ = load_pointers(sp_path, p.sp_file)

        rat_path = os.path.join(data_dir, 'rat', 'problems.txt')
        self.rat_items = list(filter_valid(load_rat_items(rat_path), i2w))
        shuffle(self.rat_items)

        with spa.SPA(seed=p.model_seed) as model:
            # set up vocab
            vocab = model.get_default_vocab(p.d)
            for i, pointer in enumerate(pointers):
                vocab.add(i2w[i].upper(), pointer)

            # set up model
            self.stimulus = Stimulus(self.rat_items)
            model.stimulus = StimulusModule(self.stimulus, p.d)
            model.rat_model = FfwdRat(p.d)
            nengo.Connection(model.stimulus.cue1.output, model.rat_model.cue1)
            nengo.Connection(model.stimulus.cue2.output, model.rat_model.cue2)
            nengo.Connection(model.stimulus.cue3.output, model.rat_model.cue3)
            self.p_output = nengo.Probe(model.rat_model.rat_state.output)

        return model