def __init__(self, config, exc_weights, inh_weights): b.Network.__init__(self) Configurable.__init__(self, config) self._add_config_value('stimulus_duration', quantity) builder = TrainedLearningModelBuilder(config['model']) self.input_gen = inputs.GroupedSpikeTimesGenerator( config['inputs'], self.stimulus_duration) self.indexing_scheme = self.input_gen.get_indexing_scheme() self.neuron = builder.build_neuron_group() self.input_neurons = b.SpikeGeneratorGroup( self.input_gen.num_trains, inputs.swap_tuple_values(self.input_gen)) self.input_groups = ModelInputGroups( self.indexing_scheme, self.input_neurons) self.exc_synapses = builder.build_exc_synapses( self.input_groups.excitatory, self.neuron, exc_weights) self.inh_synapses = builder.build_inh_synapses( self.input_groups.inhibitory, self.neuron, inh_weights) self.add( self.neuron, self.input_neurons, self.inh_synapses, self.exc_synapses)
def __init__(self, config, indata=None): b.Network.__init__(self) builder = ModelBuilder(config['model']) if indata is None: self.input_gen = inputs.GroupedSpikeTimesGenerator(config['inputs']) self.input_neurons = b.SpikeGeneratorGroup( self.input_gen.num_trains, inputs.swap_tuple_values(self.input_gen)) else: self.input_gen = inputs.StoredSpikeTimesProvider(indata) self.input_neurons = b.SpikeGeneratorGroup( self.input_gen.num_trains, self.input_gen) self.indexing_scheme = self.input_gen.get_indexing_scheme() self.neuron = builder.build_neuron_group() self.input_groups = ModelInputGroups( self.indexing_scheme, self.input_neurons) self.exc_synapses = builder.build_exc_synapses( self.input_groups.excitatory, self.neuron, self.tuning_function(self.input_groups.exc_group_membership, 5)) self.total_exc_weight_l1 = np.sum(self.exc_synapses.w[:, :]) self.total_exc_weight_l2 = linalg.norm(self.exc_synapses.w[:, :]) self.inh_synapses = builder.build_inh_synapses( self.input_groups.inhibitory, self.neuron) @b.network_operation def normalize_exc_synapses_mult_l1(): self.exc_synapses.w[:, :] = \ self.total_exc_weight_l1 * self.exc_synapses.w[:, :] / np.sum( self.exc_synapses.w[:, :]) @b.network_operation def normalize_exc_synapses_mult_l2(): self.exc_synapses.w[:, :] = \ self.total_exc_weight_l2 * self.exc_synapses.w[:, :] / linalg.norm( self.exc_synapses.w[:, :].flat) @b.network_operation def normalize_exc_synapses_add_l1(): self.exc_synapses.w[:, :] -= \ (np.sum(self.exc_synapses.w[:, :]) - self.total_exc_weight_l1) / \ self.exc_synapses.w[:, :].shape[0] self.exc_synapses.w[:, :] = np.maximum(0, self.exc_synapses.w[:, :]) self.inh_synapses.w[:, :] = np.maximum(0, self.inh_synapses.w[:, :]) @b.network_operation def normalize_exc_synapses_add_l2(): self.exc_synapses.w[:, :] -= \ (linalg.norm(self.exc_synapses.w[:, :]) - self.total_exc_weight_l2) / self.exc_synapses.w[:, :].shape[0] self.exc_synapses.w[:, :] = np.maximum(0, self.exc_synapses.w[:, :]) self.inh_synapses.w[:, :] = np.maximum(0, self.inh_synapses.w[:, :]) @b.network_operation def noop(): pass normalizations = { 'mult_l1': normalize_exc_synapses_mult_l1, 'add_l1': normalize_exc_synapses_add_l1, 'mult_l2': normalize_exc_synapses_mult_l2, 'add_l2': normalize_exc_synapses_add_l2, 'none': noop } self.add( self.neuron, self.input_neurons, self.inh_synapses, self.exc_synapses, normalizations[config['model']['normalization']])