コード例 #1
0
    def test_recording_1_element(self):
        p.setup(timestep=1.0, min_delay=1.0, max_delay=144.0)
        n_neurons = 200  # number of neurons in each population
        p.set_number_of_neurons_per_core("IF_curr_exp", n_neurons / 2)

        cell_params_lif = {
            'cm': 0.25,
            'i_offset': 0.0,
            'tau_m': 20.0,
            'tau_refrac': 2.0,
            'tau_syn_E': 5.0,
            'tau_syn_I': 5.0,
            'v_reset': -70.0,
            'v_rest': -65.0,
            'v_thresh': -50.0
        }

        populations = list()
        projections = list()

        spike_array = {'spike_times': [[0]]}
        populations.append(
            p.Population(n_neurons,
                         p.IF_curr_exp,
                         cell_params_lif,
                         label='pop_1'))
        populations.append(
            p.Population(1,
                         p.SpikeSourceArray,
                         spike_array,
                         label='inputSpikes_1'))

        projections.append(
            p.Projection(populations[1], populations[0],
                         p.AllToAllConnector()))

        populations[1].record()

        p.run(5000)

        spike_array_spikes = populations[1].getSpikes()
        boxed_array = numpy.zeros(shape=(0, 2))
        boxed_array = numpy.append(boxed_array, [[0, 0]], axis=0)
        numpy.testing.assert_array_equal(spike_array_spikes, boxed_array)

        p.end()
コード例 #2
0
    def test_run(self):
        sim.setup()

        sim.Population(3, sim.SpikeSourceArray,
                       {"spike_times": [1.0, 2.0, 3.0]})
        p2 = sim.Population(3, sim.SpikeSourceArray,
                            {"spike_times": [[10.0], [20.0], [30.0]]})
        p3 = sim.Population(4, sim.IF_cond_exp, {})

        sim.Projection(
            p2, p3,
            sim.FromListConnector([(0, 0, 0.1, 1.0), (1, 1, 0.1, 1.0),
                                   (2, 2, 0.1, 1.0)]))

        sim.run(100.0)

        sim.end()
    def test_run(self):
        with LogCapture() as l:
            p.setup()
            p1 = p.Population(1, p.IF_curr_exp, {})
            p2 = p.Population(1, p.IF_curr_exp, {})

            proj = p.Projection(p1, p2, p.AllToAllConnector())

            p.run(500)

            proj.getWeights()

            p.run(500)

            proj.getWeights()

            p.end()
            self.assert_logs_messages(l.records, "Getting weights", 'INFO', 2)
コード例 #4
0
 def inhibit_along_eyesight(network_topology):
     for population_ids in network_topology:
         # generate population id pairs from all populations lying along the projection axis
         pairs = filter(
             lambda x: x[0] != x[1],
             it.product(population_ids[population_ids >= 0], repeat=2))
         logger.debug(
             "Generated inhibitory connection list for populations {}".
             format(pairs))
         for presynaptic, postsynaptic in pairs:
             pyNN.Projection(
                 presynaptic_population=self._network['collectors']
                 [presynaptic],
                 postsynaptic_population=self._network['collectors']
                 [postsynaptic],
                 connector=pyNN.OneToOneConnector(
                     weights=self.params['synapse']['wCCi'],
                     delays=self.params['synapse']['dCCi']),
                 target='inhibitory')
コード例 #5
0
    def test_recording_poisson_spikes_rate_0(self):
        p.setup(timestep=1.0, min_delay=1.0, max_delay=144.0)
        n_neurons = 256  # number of neurons in each population
        p.set_number_of_neurons_per_core("IF_curr_exp", n_neurons / 2)

        cell_params_lif = {
            'cm': 0.25,
            'i_offset': 0.0,
            'tau_m': 20.0,
            'tau_refrac': 2.0,
            'tau_syn_E': 5.0,
            'tau_syn_I': 5.0,
            'v_reset': -70.0,
            'v_rest': -65.0,
            'v_thresh': -50.0
        }

        populations = list()
        projections = list()

        populations.append(
            p.Population(n_neurons,
                         p.IF_curr_exp,
                         cell_params_lif,
                         label='pop_1'))
        populations.append(
            p.Population(n_neurons,
                         p.SpikeSourcePoisson, {'rate': 0},
                         label='inputSpikes_1'))

        projections.append(
            p.Projection(populations[1], populations[0],
                         p.OneToOneConnector()))

        populations[1].record()

        p.run(5000)

        spikes = populations[1].getSpikes()
        print spikes

        p.end()
コード例 #6
0
    def depress_cores(self, w_range=[-2.0, -1.5], d_range=[2.0, 2.0]):
        """Connect depressing noise sources to variables populations.

        args:
            w_range: range for the random distribution of synaptic weights in the form [w_min, w_max].
            d_range: range for the random distribution of synaptic delays in the form [d_min, d_max].
        """
        print msg, 'connecting Poisson noise sources to neural populations for dissipation'
        delays = RandomDistribution('uniform', d_range)
        weights = RandomDistribution('uniform', w_range)
        for depressor in range(self.d_populations):
            for variable in range(self.variables_number):
                if variable not in self.clues[0]:
                    synapses = p.Projection(
                        self.diss_pops[depressor][variable],
                        self.var_pops[variable],
                        p.OneToOneConnector(weights=weights, delays=delays),
                        target='inhibitory')
                    self.diss_conns.append(synapses)
        self.diss_times += self.disss
コード例 #7
0
    def _apply_ordering_constraint(self):
        """
        Implement the proposed by Christoph ordering constraint of inhibiting possible *mirror* matches. 
        For example: | |a|b|c| - | |1|2|3|  -->  (a,3), (b,2), (c,1) could be sometimes prevented if (b,2)
        would inhibit (a,1) and (c,3) event types. These lie on the flipped diagonal of each population id.
         
        Returns:
            In-place method
        """
        logger.info(
            "Applying the ordering constraint on the temporal coincidence network."
        )

        # get all flipped diagonal population groups
        all_mirrored_diags = [
            self._network_topology[::-1, :].diagonal(i)
            for i in xrange(-self.max_disparity - 1, self.max_disparity + 2)
        ]
        valid_mirrored_diags = [
            group for group in [d[d >= 0] for d in all_mirrored_diags]
            if len(group) > 1
        ]
        for mirrored_diag in valid_mirrored_diags:
            for presynaptic, postsynaptic in pairs_of_neighbours(
                    mirrored_diag,
                    window_size=self.params['topology']['radius_ordering'] +
                    1):
                pyNN.Projection(
                    presynaptic_population=self._network['collectors']
                    [presynaptic],
                    postsynaptic_population=self._network['collectors']
                    [postsynaptic],
                    connector=pyNN.OneToOneConnector(
                        weights=self.params['synapse']['wCCo'],
                        delays=self.params['synapse']['dCCo']),
                    target='inhibitory')
        logger.debug(
            "Applying the ordering constraint on the temporal coincidence network completed."
        )
コード例 #8
0
def do_run(nNeurons):
    cell_params_lif = {
        'cm': 0.25,  # nF
        'i_offset': 0.0,
        'tau_m': 10.0,
        'tau_refrac': 2.0,
        'tau_syn_E': 2.5,
        'tau_syn_I': 2.5,
        'v_reset': -70.0,
        'v_rest': -65.0,
        'v_thresh': -55.4
    }

    spike_list = {'spike_times': [float(x) for x in range(0, 599, 50)]}
    p.setup(timestep=1.0, min_delay=1.0, max_delay=32.0)

    p.set_number_of_neurons_per_core("SpikeSourceArray", 100)  # FAILS

    populations = list()
    projections = list()

    populations.append(
        p.Population(nNeurons, p.SpikeSourceArray, spike_list, label='input'))
    populations.append(
        p.Population(1, p.IF_curr_exp, cell_params_lif, label='pop_1'))
    projections.append(
        p.Projection(populations[0], populations[1], p.AllToAllConnector()))

    populations[0].record()

    p.run(1000)

    spikes = populations[0].getSpikes(compatible_output=True)

    p.end()

    return spikes
コード例 #9
0
def do_run():
    # this test ensures there is too much dtcm used up, thus crashes during
    # initisation
    p.setup(timestep=1.0, min_delay=1.0, max_delay=144.0)

    input = p.Population(1024, p.SpikeSourcePoisson, {'rate': 10}, "input")
    relay_on = p.Population(1024, p.IF_curr_exp, {}, "input")

    t_rule_LGN = p.SpikePairRule(tau_plus=17, tau_minus=34)
    w_rule_LGN = p.AdditiveWeightDependence(w_min=0.0,
                                            w_max=0.3,
                                            A_plus=0.01,
                                            A_minus=0.0085)
    stdp_model_LGN = p.STDPMechanism(timing_dependence=t_rule_LGN,
                                     weight_dependence=w_rule_LGN)
    s_d_LGN = p.SynapseDynamics(slow=stdp_model_LGN)
    p.Projection(input,
                 relay_on,
                 p.OneToOneConnector(weights=1),
                 synapse_dynamics=s_d_LGN,
                 target='excitatory')

    p.run(1000)
    p.end()
コード例 #10
0
    def run_multiple_stdp_mechs_on_same_neuron(self):
        p.setup(timestep=1.0, min_delay=1.0, max_delay=144.0)
        nNeurons = 200  # number of neurons in each population

        cell_params_lif = {
            'cm': 0.25,
            'i_offset': 0.0,
            'tau_m': 20.0,
            'tau_refrac': 2.0,
            'tau_syn_E': 5.0,
            'tau_syn_I': 5.0,
            'v_reset': -70.0,
            'v_rest': -65.0,
            'v_thresh': -50.0
        }

        populations = list()
        projections = list()

        weight_to_spike = 2.0
        delay = 1

        connections = list()
        for i in range(0, nNeurons):
            singleConnection = (i, ((i + 1) % nNeurons), weight_to_spike,
                                delay)
            connections.append(singleConnection)

        # Plastic Connection between pre_pop and post_pop
        stdp_model1 = p.STDPMechanism(
            timing_dependence=p.SpikePairRule(tau_plus=16.7, tau_minus=33.7),
            weight_dependence=p.AdditiveWeightDependence(w_min=0.0,
                                                         w_max=1.0,
                                                         A_plus=0.005,
                                                         A_minus=0.005),
        )

        # Plastic Connection between pre_pop and post_pop
        stdp_model2 = p.STDPMechanism(
            timing_dependence=p.SpikePairRule(tau_plus=16.7, tau_minus=33.7),
            weight_dependence=p.AdditiveWeightDependence(w_min=0.0,
                                                         w_max=1.0,
                                                         A_plus=0.005,
                                                         A_minus=0.005),
        )

        # Plastic Connection between pre_pop and post_pop
        stdp_model3 = p.STDPMechanism(
            timing_dependence=p.SpikePairRule(tau_plus=16.7, tau_minus=33.7),
            weight_dependence=p.MultiplicativeWeightDependence(w_min=0.0,
                                                               w_max=1.0,
                                                               A_plus=0.005,
                                                               A_minus=0.005),
        )

        injectionConnection = [(0, 0, weight_to_spike, 1)]
        spikeArray1 = {'spike_times': [[0]]}
        spikeArray2 = {'spike_times': [[25]]}
        spikeArray3 = {'spike_times': [[50]]}
        spikeArray4 = {'spike_times': [[75]]}
        spikeArray5 = {'spike_times': [[100]]}
        spikeArray6 = {'spike_times': [[125]]}
        spikeArray7 = {'spike_times': [[150]]}
        spikeArray8 = {'spike_times': [[175]]}

        populations.append(
            p.Population(nNeurons,
                         p.IF_curr_exp,
                         cell_params_lif,
                         label='pop_1'))
        populations.append(
            p.Population(1,
                         p.SpikeSourceArray,
                         spikeArray1,
                         label='inputSpikes_1'))
        populations.append(
            p.Population(1,
                         p.SpikeSourceArray,
                         spikeArray2,
                         label='inputSpikes_2'))
        populations.append(
            p.Population(1,
                         p.SpikeSourceArray,
                         spikeArray3,
                         label='inputSpikes_3'))
        populations.append(
            p.Population(1,
                         p.SpikeSourceArray,
                         spikeArray4,
                         label='inputSpikes_4'))
        populations.append(
            p.Population(1,
                         p.SpikeSourceArray,
                         spikeArray5,
                         label='inputSpikes_5'))
        populations.append(
            p.Population(1,
                         p.SpikeSourceArray,
                         spikeArray6,
                         label='inputSpikes_6'))
        populations.append(
            p.Population(1,
                         p.SpikeSourceArray,
                         spikeArray7,
                         label='inputSpikes_7'))
        populations.append(
            p.Population(1,
                         p.SpikeSourceArray,
                         spikeArray8,
                         label='inputSpikes_8'))

        projections.append(
            p.Projection(populations[0], populations[0],
                         p.FromListConnector(connections)))
        pop = p.Projection(populations[1], populations[0],
                           p.FromListConnector(injectionConnection))
        projections.append(pop)
        synapse_dynamics = p.SynapseDynamics(slow=stdp_model1)
        pop = p.Projection(populations[2],
                           populations[0],
                           p.FromListConnector(injectionConnection),
                           synapse_dynamics=synapse_dynamics)
        projections.append(pop)
        # This is expected to raise a SynapticConfigurationException
        synapse_dynamics = p.SynapseDynamics(slow=stdp_model2)
        pop = p.Projection(populations[3],
                           populations[0],
                           p.FromListConnector(injectionConnection),
                           synapse_dynamics=synapse_dynamics)
        projections.append(pop)
        synapse_dynamics = p.SynapseDynamics(slow=stdp_model3)
        pop = p.Projection(populations[4],
                           populations[0],
                           p.FromListConnector(injectionConnection),
                           synapse_dynamics=synapse_dynamics)
        projections.append(pop)
コード例 #11
0
output = 100

p.setup(timestep=1.0)
p.set_number_of_neurons_per_core(p.IF_cond_exp, 100)

poisson_rate = {'rate': 15}
tracker = SummaryTracker()
tracker.print_diff()

input_pop = p.Population(input_size, p.IF_cond_exp, {}, label='input')
hidden_pop = p.Population(hidden_size, p.IF_cond_exp, {}, label='hidden')
output_pop = p.Population(output, p.IF_cond_exp, {}, label='output')
breakout = p.Population(1, spinn_breakout.Breakout, {}, label="breakout")
print "after populations"
tracker.print_diff()
a = p.Projection(input_pop, hidden_pop, p.AllToAllConnector(weights=0.5))
print "after i->h"
tracker.print_diff()
a = p.Projection(breakout, hidden_pop, p.AllToAllConnector(weights=0.5))
print "after b->h"
tracker.print_diff()
b = p.Projection(input_pop, output_pop, p.AllToAllConnector(weights=2))
print "after i->o"
tracker.print_diff()
c = p.Projection(hidden_pop, output_pop, p.AllToAllConnector(weights=2))
print "after h->o"
tracker.print_diff()
d = p.Projection(input_pop, input_pop, p.AllToAllConnector(weights=2))
print "after i->i"
tracker.print_diff()
a = p.Projection(input_pop, hidden_pop, p.AllToAllConnector(weights=2))
コード例 #12
0
if test_exc:
    target = sim.Population(num_exc, cell, exc_params, label='Target (EXC)')
else:
    target = sim.Population(num_exc, cell, inh_params, label='Target (INH)')

source.record()
target.record()
target.record_v()

########################################################################
# P R O J E C T I O N S
########################################################################

src_to_tgt = sim.Projection(source,
                            target,
                            sim.OneToOneConnector(weights=w2s,
                                                  generate_on_machine=True),
                            target='excitatory')

########################################################################
# R U N   S I M U L A T I O N
########################################################################

sim.run(sim_time)
spikes = {
    'target': target.getSpikes(compatible_output=True),
    'source': source.getSpikes(compatible_output=True),
}
voltage = target.get_v()
sim.end()
コード例 #13
0
                                      f_peak=f_peak)
source_pop = sim.Population(N_layer,
                            sim.SpikeSourcePoisson, {
                                'rate': rates.ravel(),
                                'start': 0,
                                'duration': simtime
                            },
                            label="Poisson spike source")

ff_prob_conn = [(i, j, g_max, args.delay) for i in range(N_layer)
                for j in range(N_layer) if np.random.rand() < .05]

ff_projection = sim.Projection(
    source_pop,
    target_pop,
    # sim.FixedProbabilityConnector(p_connect=.1, weights=g_max),
    sim.FromListConnector(ff_prob_conn),
    synapse_dynamics=sim.SynapseDynamics(slow=structure_model_w_stdp),
    label="plastic_ff_projection")

if args.record_source:
    source_pop.record()
target_pop.record()

# Run simulation
pre_spikes = []
post_spikes = []

pre_weights = []
post_weights = []
コード例 #14
0
        #                     },
        #                    label="Variable-rate Poisson spike source # " +
        #                          str(number))
        # )

        # Neuron populations
        target_column.append(
            sim.Population(N_layer,
                           model,
                           cell_params,
                           label="TARGET_POP # " + str(number)))

        ff_connections.append(
            sim.Projection(source_column[0],
                           target_column[number],
                           sim.FromListConnector(init_ff_connections),
                           synapse_dynamics=sim.SynapseDynamics(
                               slow=structure_model_w_stdp),
                           label="plastic_ff_projection"))

        if args.case != CASE_CORR_NO_REW:
            lat_connections.append(
                sim.Projection(target_column[number],
                               target_column[number],
                               sim.FromListConnector(init_lat_connections),
                               synapse_dynamics=sim.SynapseDynamics(
                                   slow=structure_model_w_stdp),
                               label="plastic_lat_projection",
                               target="inhibitory"
                               if args.lateral_inhibition else "excitatory"))
else:
    # Testing mode is activated.
コード例 #15
0
ファイル: synfire_run.py プロジェクト: chanokin/sPyNNaker7
    def do_run(
            self, n_neurons, time_step=1, max_delay=144.0,
            input_class=SpikeSourceArray, spike_times=None, rate=None,
            start_time=None, duration=None, spike_times_list=None,
            placement_constraint=None, weight_to_spike=2.0, delay=17,
            neurons_per_core=10, cell_class=IF_curr_exp, constraint=None,
            cell_params=CELL_PARAMS_LIF, run_times=None, reset=False,
            extract_between_runs=True, set_between_runs=None, new_pop=False,
            record_input_spikes=False, record=True, get_spikes=None,
            spike_path=None, record_v=True, get_v=None, v_path=None,
            record_gsyn=True, get_gsyn=None, gsyn_path=None,
            use_spike_connections=True, use_wrap_around_connections=True,
            get_weights=False, get_delays=False,
            end_before_print=False, randomise_v_init=False):
        """

        :param n_neurons: Number of Neurons in chain
        :type  n_neurons: int
        :param time_step: time step value to be used in p.setup
        :type time_step: float
        :param max_delay: max_delay value to be used in p.setup
        :type max_delay: float
        :param rate: the rate of the SSP to fire at
        :type rate: float
        :param start_time: the start time for the SSP
        :type start_time: float
        :param duration: the length of time for the SSP to fire for
        :type duration: float
        :param input_class: the class for inputs spikes (SSA or SSP)
        :type input_class: SpikeSourceArray, SpikeSourcePoisson
        :param spike_times: times the SSA sends in spikes
        :type spike_times: matrix of int times the SSA sends in spikes
        :param spike_times_list: list of times the SSA sends in spikes
            - must be the same length as  run times
            - If set the spike_time parameter is ignored
        :type spike_times_list: list of matrix of
            int times the SSA sends in spikes
        :param placement_constraint: x, y and p values to add a
            placement_constraint to population[0]
        :type (int, int, int)
        :type weight_to_spike: float
        :param delay: time delay in the single connectors in the spike chain
        :type delay: float
        :param neurons_per_core: Number of neurons per core.
            If set to None no  set_number_of_neurons_per_core call will be made
        :type neurons_per_core: int or None
        :param constraint: A Constraint to be place on populations[0]
        :type constraint: AbstractConstraint
        :param cell_class: class to be used for the main population
            Not used by any test at the moment
        :type cell_class: AbstractPopulationVertex
        :param cell_params: values for the main population
            Not used by any test at the moment
            Note: the values must match what is expected by the cellclass
        :type cell_params: dict
        :param run_times: times for each run.
            A zero will skip run but trigger reset and get date ext as set
        :type run_times: list of int
        :param reset: if True will call reset after each run except the last
        :type reset: bool
        :param extract_between_runs: If True reads V, gysn and spikes
            between each run.
        :type extract_between_runs: bool
        :param set_between_runs set instuctions to be carried out between runs.
            Should be a list of tuples.
            First element of each tuple is 0 or 1
                0 for main population
                1 for input polulation
            Second element a String for name of peroperty to change
            Third element the new value
        :type set_between_runs: List[(int, String, any)]
        :param new_pop: If True will add a new population before the second run
        :type new_pop: bool
        :param record_input_spikes: check for recording input spikes
        :type record_input_spikes: bool
        :param record: If True will aks for spikes to be recorded
        :type record: bool
        :param get_spikes: If set overrides the normal behaviour
            of getting spikes if and only if record is True.
            If left None the value of record is used.
        :type get_spikes: bool
        :param spike_path: The path to print(write) the last spike data too
        :type spike_path: str or None
        :param record_v: If True will aks for voltage to be recorded
        :type record_v: bool
        :param get_v: If set overrides the normal behaviour
            of getting v if and only if record_v is True.
            If left None the value of record_v is used.
        :type get_v: bool
        :param v_path: The path to print(write) the last v data too
        :type v_path: str or None
        :param record_gsyn: If True will aks for gsyn to be recorded
        :type record_gsyn: bool
        :param get_gsyn: If set overrides the normal behaviour
            of getting gsyn if and only if record_gsyn is True.
            If left None the value of record_gsyn is used.
        :type get_v: bool
        :param gsyn_path: The path to print(write) the last gsyn data too
        :type gsyn_path: str or None
        :param get_weights: If True weights will be gotten
        :type get_weights: bool
        :param get_delays: If True delays will be gotten
        :type get_delays: bool
        :param end_before_print: If True will call end() before running the \
            optional print commands.
            Note: end will always be called twice even if no print path
            provided
            WARNING: This is expected to cause an Exception \
                if spike_path, v_path or gsyn_path provided
        :type end_before_print: bool
        :param randomise_v_init: randomises the v_init of the output pop.
        :type randomise_v_init: bool
        :param use_spike_connections: Will put the spike connections in
        :type use_spike_connections: bool
        :param use_wrap_around_connections: Will also put in a connector from
            the last spike neuron back to the first
            Note: Has no effect if use_spike_connections == False
        :type use_wrap_around_connections: bool
        """

        self._recorded_v = []
        self._recorded_spikes = []
        self._recorded_gsyn = []
        self._input_spikes_recorded = []
        self._weights = []
        self._delays = []

        if run_times is None:
            run_times = [1000]

        if set_between_runs is None:
            set_between_runs = []

        if len(set_between_runs) > 0 and len(run_times) != 2:
            raise Exception("set_between_runs requires exactly 2 run times")

        if spike_times is None:
            spike_times = [[0]]

        if get_spikes is None:
            get_spikes = record

        if get_v is None:
            get_v = record_v

        if get_gsyn is None:
            get_gsyn = record_gsyn

        p.setup(timestep=time_step, min_delay=1.0, max_delay=max_delay)
        if neurons_per_core is not None:
            p.set_number_of_neurons_per_core("IF_curr_exp", neurons_per_core)

        populations = list()
        projections = list()

        loop_connections = list()
        if use_wrap_around_connections:
            for i in range(0, n_neurons):
                single_connection = \
                    (i, ((i + 1) % n_neurons), weight_to_spike, delay)
                loop_connections.append(single_connection)
        else:
            for i in range(0, n_neurons - 1):
                single_connection = (i, i + 1, weight_to_spike, delay)
                loop_connections.append(single_connection)

        injection_connection = [(0, 0, weight_to_spike, 1)]

        run_count = 0
        if spike_times_list is None:
            spike_array = {'spike_times': spike_times}
        else:
            spike_array = {'spike_times': spike_times_list[run_count]}

        populations.append(p.Population(
            n_neurons, cell_class, cell_params, label='pop_1'))

        if placement_constraint is not None:
            if len(placement_constraint) == 2:
                (x, y) = placement_constraint
                populations[0].add_placement_constraint(x=x, y=y)
            else:
                (x, y, proc) = placement_constraint
                populations[0].add_placement_constraint(x=x, y=y, p=proc)

        if randomise_v_init:
            rng = p.NumpyRNG(seed=28375)
            v_init = p.RandomDistribution('uniform', [-60, -40], rng)
            populations[0].randomInit(v_init)

        if constraint is not None:
            populations[0].set_constraint(constraint)

        if input_class == SpikeSourceArray:
            populations.append(p.Population(
                1, input_class, spike_array, label='inputSSA_1'))
        else:
            populations.append(p.Population(
                1, input_class,
                {'rate': rate, 'start': start_time, 'duration': duration},
                label='inputSSP_1'))

        # handle projections
        if use_spike_connections:
            projections.append(p.Projection(populations[0], populations[0],
                               p.FromListConnector(loop_connections)))

        projections.append(p.Projection(populations[1], populations[0],
                           p.FromListConnector(injection_connection)))

        # handle recording
        if record or spike_path is not None:
            populations[0].record()
        if record_v or v_path is not None:
            populations[0].record_v()
        if record_gsyn or gsyn_path is not None:
            populations[0].record_gsyn()
        if record_input_spikes:
            populations[1].record()

        results = ()

        for runtime in run_times[:-1]:
            # This looks strange but is to allow getting data before run
            if runtime > 0:
                p.run(runtime)
            run_count += 1

            if extract_between_runs:
                self._get_data(
                    populations[0], populations[1], get_spikes, get_v,
                    get_gsyn, record_input_spikes)
                if get_weights:
                    self._weights.append(projections[0].getWeights())
                if get_delays:
                    self._delays.append(projections[0].getDelays())

            if new_pop:
                populations.append(
                    p.Population(n_neurons, cell_class, cell_params,
                                 label='pop_2'))
                injection_connection = [(n_neurons - 1, 0, weight_to_spike, 1)]
                new_projection = p.Projection(
                    populations[0], populations[2],
                    p.FromListConnector(injection_connection))
                projections.append(new_projection)

            if spike_times_list is not None:
                populations[1].tset("spike_times", spike_times_list[run_count])

            for (pop, name, value) in set_between_runs:
                if pop == 0:
                    populations[0].set(name, value)
                else:
                    populations[1].set(name, value)

            if reset:
                p.reset()

        p.run(run_times[-1])

        self._get_data(
            populations[0], populations[1], get_spikes, get_v, get_gsyn,
            record_input_spikes)
        if get_weights:
            self._weights.append(projections[0].getWeights())
        if get_delays:
            self._delays.append(projections[0].getDelays())

        if end_before_print:
            if v_path is not None or spike_path is not None or \
                    gsyn_path is not None:
                print "NOTICE! end is being called before print.. commands " \
                      "which could cause an exception"
            p.end()

        if v_path is not None:
            populations[0].print_v(v_path)
        if spike_path is not None:
            populations[0].printSpikes(spike_path)
        if gsyn_path is not None:
            populations[0].print_gsyn(gsyn_path)
        p.end()

        return results
コード例 #16
0
breakout_pop = p.Population(1, spinn_breakout.Breakout, {}, label="breakout")
ex.activate_live_output_for(breakout_pop, host="0.0.0.0", port=UDP_PORT1)
ex.activate_live_output_for(breakout_pop, host="0.0.0.0", port=UDP_PORT2)

# Create spike injector to send random spikes to the paddle
spike_array = [[0, 2, 4, 6, 8, 10], [1, 3, 5, 7, 9, 11]]

# Connect key spike injector to breakout population
# array_input = p.Population(2, p.SpikeSourceArray(spike_times=spike_array), label="input_connect")
# poisson = p.SpikeSourcePoisson(rate=20)
rate = {'rate': 2}  #, 'duration': 10000000}
spike_input = p.Population(2,
                           p.SpikeSourcePoisson,
                           rate,
                           label="input_connect")
p.Projection(spike_input, breakout_pop, p.AllToAllConnector(weights=2))
# key_input_connection = SpynnakerLiveSpikesConnection(send_labels=["input_connect"])

# Create visualiser
# visualiser = Visualiser(
#     UDP_PORT, None,
#     x_res=X_RESOLUTION, y_res=Y_RESOLUTION,
#     x_bits=X_BITS, y_bits=Y_BITS)

running = True
t = threading.Thread(target=thread_visualiser, args=(UDP_PORT1))
r = threading.Thread(target=thread_visualiser, args=(UDP_PORT1))
result = [0 for i in range(2)]
# t = ThreadPool(processes=2)
# r = ThreadPool(processes=2)
# result = t.apply_async(thread_visualiser, [UDP_PORT1])
コード例 #17
0
                                            payload_as_time_stamps=False,
                                            use_payload_prefix=False)
# populations.append(Population(nNeurons,
#                               IF_curr_exp, cell_params_lif,
#                               label='pop_%d' % i))

pop_external = p.Population(nNeurons,
                            p.external_devices.SpikeInjector,
                            cell_params_ext_dev,
                            label='Babel_Dummy')

populations.append(
    p.Population(nNeurons, p.IF_curr_exp, cell_params_lif, label='pop_%d' % 1))

projections.append(
    p.Projection(pop_external, populations[1],
                 p.OneToOneConnector(weights=weight_to_spike, delays=10)))

# populations[0].record_v()
#  at the moment is only possible to observe one population per core
populations[1].record_v()

for pop in populations:
    pop.record(to_file=False)  # sends spike to the Monitoring application

#    populations[i].record_variable('rate', save_to='eth')
#  sends spike to the Monitoring application

p.run(10000)

# retrieving spike results and plotting...
コード例 #18
0
        lateral_inhibition=args.lateral_inhibition,
        random_partner=args.random_partner,
        p_elim_dep=p_elim_dep,
        p_elim_pot=p_elim_pot,
        sigma_form_forward=sigma_form_forward,
        sigma_form_lateral=sigma_form_lateral,
        p_form_forward=p_form_forward,
        p_form_lateral=p_form_lateral)
elif case == CASE_CORR_NO_REW:
    structure_model_w_stdp = stdp_model

# structure_model_w_stdp = sim.StructuralMechanism(weight=g_max, s_max=s_max)

ff_projection = sim.Projection(
    source_pop,
    target_pop,
    sim.FromListConnector(init_ff_connections),
    synapse_dynamics=sim.SynapseDynamics(slow=structure_model_w_stdp),
    label="plastic_ff_projection")

lat_projection = sim.Projection(
    target_pop,
    target_pop,
    sim.FromListConnector(init_lat_connections),
    synapse_dynamics=sim.SynapseDynamics(slow=structure_model_w_stdp),
    label="plastic_lat_projection",
    target="inhibitory" if args.lateral_inhibition else "excitatory")

# +-------------------------------------------------------------------+
# | Simulation and results                                            |
# +-------------------------------------------------------------------+
コード例 #19
0
def do_run(nNeurons):
    p.setup(timestep=1.0, min_delay=1.0, max_delay=144.0)

    p.set_number_of_neurons_per_core("IF_curr_exp", nNeurons / 2)

    cell_params_lif = {
        'cm': 0.25,
        'i_offset': 0.0,
        'tau_m': 20.0,
        'tau_refrac': 2.0,
        'tau_syn_E': 5.0,
        'tau_syn_I': 5.0,
        'v_reset': -70.0,
        'v_rest': -65.0,
        'v_thresh': -50.0
    }

    p.set_number_of_neurons_per_core("IF_cond_exp", nNeurons / 2)

    cell_params_cond = {
        'cm': 0.25,
        'i_offset': 0.0,
        'tau_m': 20.0,
        'tau_refrac': 2.0,
        'tau_syn_E': 5.0,
        'tau_syn_I': 5.0,
        'v_reset': -70.0,
        'v_rest': -65.0,
        'v_thresh': -50.0,
        'e_rev_E': 0.,
        'e_rev_I': -80.
    }

    p.set_number_of_neurons_per_core("IZK_curr_exp", 100)

    cell_params_izk = {
        'a': 0.02,
        'b': 0.2,
        'c': -65,
        'd': 8,
        'v_init': -75,
        'u_init': 0,
        'tau_syn_E': 2,
        'tau_syn_I': 2,
        'i_offset': 0
    }

    populations = list()
    projections = list()

    current_weight_to_spike = 2.0
    cond_weight_to_spike = 0.035
    delay = 17

    # different strangths of connection
    curr_injection_connection = [(0, 0, current_weight_to_spike, delay)]
    cond_injection_connection = [(0, 0, cond_weight_to_spike, delay)]
    izk_injection_connection = [(0, 0, current_weight_to_spike, delay)]
    sinkConnection = [(0, 0, 0, 1)]

    # spike time
    spikeArray = {'spike_times': [[0]]}

    # curr set up
    populations.append(
        p.Population(nNeurons,
                     p.IF_cond_exp,
                     cell_params_cond,
                     label='pop_cond'))
    # cond setup
    populations.append(
        p.Population(nNeurons,
                     p.IF_curr_exp,
                     cell_params_lif,
                     label='pop_curr'))
    # izk setup
    populations.append(
        p.Population(nNeurons,
                     p.IZK_curr_exp,
                     cell_params_izk,
                     label='izk pop'))

    # sink pop for spikes to go to (otherwise they are not recorded as firing)
    populations.append(
        p.Population(nNeurons,
                     p.IF_curr_exp,
                     cell_params_lif,
                     label='sink_pop'))
    populations.append(
        p.Population(1, p.SpikeSourceArray, spikeArray, label='inputSpike'))

    pop = p.Projection(populations[4], populations[0],
                       p.FromListConnector(cond_injection_connection))
    projections.append(pop)
    pop = p.Projection(populations[4], populations[1],
                       p.FromListConnector(curr_injection_connection))
    projections.append(pop)
    pop = p.Projection(populations[4], populations[2],
                       p.FromListConnector(izk_injection_connection))
    projections.append(pop)
    projections.append(
        p.Projection(populations[2], populations[3],
                     p.FromListConnector(sinkConnection)))
    projections.append(
        p.Projection(populations[1], populations[3],
                     p.FromListConnector(sinkConnection)))
    projections.append(
        p.Projection(populations[0], populations[3],
                     p.FromListConnector(sinkConnection)))
    # record stuff for cond
    populations[0].record_v()
    populations[0].record_gsyn()
    populations[0].record()

    # record stuff for curr
    populations[1].record_v()
    populations[1].record_gsyn()
    populations[1].record()

    # record stuff for izk
    populations[2].record_v()
    populations[2].record_gsyn()
    populations[2].record()

    p.run(500)

    # get cond
    cond_v = populations[0].get_v(compatible_output=True)
    cond_gsyn = populations[0].get_gsyn(compatible_output=True)
    cond_spikes = populations[0].getSpikes(compatible_output=True)

    # get curr
    curr_v = populations[1].get_v(compatible_output=True)
    curr_gsyn = populations[1].get_gsyn(compatible_output=True)
    curr_spikes = populations[1].getSpikes(compatible_output=True)

    # get izk
    izk_v = populations[2].get_v(compatible_output=True)
    izk_gsyn = populations[2].get_gsyn(compatible_output=True)
    izk_spikes = populations[2].getSpikes(compatible_output=True)

    p.end()

    return (cond_v, cond_gsyn, cond_spikes, curr_v, curr_gsyn, curr_spikes,
            izk_v, izk_gsyn, izk_spikes)
コード例 #20
0
    delays.append(float(delay))
    singleConnection = (i, ((i + 1) % nNeurons), weight_to_spike, delay)
    connections.append(singleConnection)

injectionConnection = [(0, 0, weight_to_spike, 1)]
spikeArray = {'spike_times': [[0]]}

populations.append(
    p.Population(nNeurons, p.IF_curr_exp, cell_params_lif, label='pop_1'))

populations.append(
    p.Population(1, p.SpikeSourceArray, spikeArray, label='inputSpikes_1'))
# populations[0].set_mapping_constraint({"x": 1, "y": 0})

projections.append(
    p.Projection(populations[0], populations[0],
                 p.FromListConnector(connections)))
projections.append(
    p.Projection(populations[1], populations[0],
                 p.FromListConnector(injectionConnection)))

populations[0].record()
p.external_devices.activate_live_output_for(populations[0])
populations[0].set_constraint(p.ChipAndCoreConstraint(0, 0, 2))
populations[1].set_constraint(p.ChipAndCoreConstraint(0, 0, 3))

run_time = 1000
print "Running for {} ms".format(run_time)
p.run(run_time)

v = None
gsyn = None
コード例 #21
0
    def _apply_continuity_constraint(self):
        """
        Implement the David Marr's continuity constraint which encourages the spiking of disparity sensitive neurons 
        which lie in the same disparity map. This is backed by the assumption that physical object are coherent 
        and disparity does not change by much (if at all).
        
        Returns:
            In-place method
        """
        logger.info(
            "Applying the continuity constraint on the temporal coincidence network."
        )
        logger.warning(
            "The current implementation supports only cross-like connection patterns, "
            "i.e. a neuron will excite only neurons to the left, right, top and bottom. "
        )

        if self.params['topology']['radius_continuity'] > self.retina_n_cols:
            new_radius = 1
            logger.warning(
                "Radius of excitation is too big. Setting radius to {}".format(
                    new_radius))
            self.params['topology']['radius_continuity'] = new_radius

        logger.debug("Same-disparity population ids: {}".format(
            list(self._same_disparity_populations)))

        # iterate over population or neural ids and construct pairs from neighbouring units
        for population_ids in self._same_disparity_populations:
            for presynaptic, postsynaptic in pairs_of_neighbours(
                    population_ids,
                    window_size=self.params['topology']['radius_continuity'] +
                    1,
                    add_reciprocal=True):
                pyNN.Projection(
                    presynaptic_population=self._network['collectors']
                    [presynaptic],
                    postsynaptic_population=self._network['collectors']
                    [postsynaptic],
                    connector=pyNN.OneToOneConnector(
                        weights=self.params['synapse']['wCCe'],
                        delays=self.params['synapse']['dCCe']),
                    target='excitatory')

        # construct vertical connections within each neural population
        within_population_neuron_pairs = pairs_of_neighbours(
            range(self.retina_n_rows),
            window_size=self.params['topology']['radius_continuity'] + 1,
            add_reciprocal=True)
        logger.debug("Within-population neuron pairs: {}".format(
            within_population_neuron_pairs))

        connection_list = [(src, dst, self.params['synapse']['wCCe'],
                            self.params['synapse']['dCCe'])
                           for src, dst in within_population_neuron_pairs]
        if len(self._network['collectors']) > 1 and len(connection_list) > 0:
            for population in self._network['collectors']:
                pyNN.Projection(
                    presynaptic_population=population,
                    postsynaptic_population=population,
                    connector=pyNN.FromListConnector(connection_list),
                    target='excitatory')
        logger.debug(
            "Applying the continuity constraint on the temporal coincidence network completed."
        )
コード例 #22
0
    def test_va_benchmark(self):
        try:
            simulator_name = 'spiNNaker'

            timer = Timer()

            # === Define parameters =========================================

            rngseed = 98766987
            parallel_safe = True

            n = 1500  # number of cells
            # number of excitatory cells:number of inhibitory cells
            r_ei = 4.0
            pconn = 0.02  # connection probability

            dt = 0.1  # (ms) simulation timestep
            tstop = 200  # (ms) simulaton duration
            delay = 1

            # Cell parameters
            area = 20000.  # (µm²)
            tau_m = 20.  # (ms)
            cm = 1.  # (µF/cm²)
            g_leak = 5e-5  # (S/cm²)
            e_leak = -49.  # (mV)
            v_thresh = -50.  # (mV)
            v_reset = -60.  # (mV)
            t_refrac = 5.  # (ms) (clamped at v_reset)
            # (mV) 'mean' membrane potential,  for calculating CUBA weights
            v_mean = -60.
            tau_exc = 5.  # (ms)
            tau_inh = 10.  # (ms)
            # (nS) #Those weights should be similar to the COBA weights
            g_exc = 0.27
            # (nS) # but the delpolarising drift should be taken into account
            g_inh = 4.5
            e_rev_exc = 0.  # (mV)
            e_rev_inh = -80.  # (mV)

            # === Calculate derived parameters ===============================

            area *= 1e-8  # convert to cm²
            cm *= area * 1000  # convert to nF
            r_m = 1e-6 / (g_leak * area)  # membrane resistance in MΩ
            assert tau_m == cm * r_m  # just to check

            # number of excitatory cells
            n_exc = int(round((n * r_ei / (1 + r_ei))))
            n_inh = n - n_exc  # number of inhibitory cells

            print n_exc, n_inh

            celltype = p.IF_curr_exp
            # (nA) weight of excitatory synapses
            w_exc = 1e-3 * g_exc * (e_rev_exc - v_mean)
            w_inh = 1e-3 * g_inh * (e_rev_inh - v_mean)  # (nA)
            assert w_exc > 0
            assert w_inh < 0

            # === Build the network ==========================================

            p.setup(timestep=dt, min_delay=delay, max_delay=delay)

            if simulator_name == 'spiNNaker':
                # this will set 100 neurons per core
                p.set_number_of_neurons_per_core('IF_curr_exp', 100)
                # this will set 50 neurons per core
                p.set_number_of_neurons_per_core('IF_cond_exp', 50)

            node_id = 1
            np = 1

            host_name = socket.gethostname()
            print "Host #%d is on %s" % (np, host_name)

            cell_params = {
                'tau_m': tau_m,
                'tau_syn_E': tau_exc,
                'tau_syn_I': tau_inh,
                'v_rest': e_leak,
                'v_reset': v_reset,
                'v_thresh': v_thresh,
                'cm': cm,
                'tau_refrac': t_refrac,
                'i_offset': 0
            }

            print cell_params

            timer.start()

            print "%s Creating cell populations..." % node_id
            exc_cells = p.Population(n_exc,
                                     celltype,
                                     cell_params,
                                     label="Excitatory_Cells")
            inh_cells = p.Population(n_inh,
                                     celltype,
                                     cell_params,
                                     label="Inhibitory_Cells")
            p.NativeRNG(12345)

            print "%s Initialising membrane potential to random values..." \
                  % node_id
            rng = NumpyRNG(seed=rngseed, parallel_safe=parallel_safe)
            uniform_distr = RandomDistribution('uniform', [v_reset, v_thresh],
                                               rng=rng)
            exc_cells.initialize('v', uniform_distr)
            inh_cells.initialize('v', uniform_distr)

            print "%s Connecting populations..." % node_id
            exc_conn = p.FixedProbabilityConnector(pconn,
                                                   weights=w_exc,
                                                   delays=delay)
            inh_conn = p.FixedProbabilityConnector(pconn,
                                                   weights=w_inh,
                                                   delays=delay)

            connections = dict()
            connections['e2e'] = p.Projection(exc_cells,
                                              exc_cells,
                                              exc_conn,
                                              target='excitatory',
                                              rng=rng)
            connections['e2i'] = p.Projection(exc_cells,
                                              inh_cells,
                                              exc_conn,
                                              target='excitatory',
                                              rng=rng)
            connections['i2e'] = p.Projection(inh_cells,
                                              exc_cells,
                                              inh_conn,
                                              target='inhibitory',
                                              rng=rng)
            connections['i2i'] = p.Projection(inh_cells,
                                              inh_cells,
                                              inh_conn,
                                              target='inhibitory',
                                              rng=rng)

            # === Setup recording ==============================
            print "%s Setting up recording..." % node_id
            exc_cells.record()

            # === Run simulation ================================
            print "%d Running simulation..." % node_id

            print "timings: number of neurons:", n
            print "timings: number of synapses:", n * n * pconn

            p.run(tstop)

            exc_spikes = exc_cells.getSpikes()
            print len(exc_spikes)

            current_file_path = os.path.dirname(os.path.abspath(__file__))
            current_file_path = os.path.join(current_file_path, "spikes.data")
            exc_cells.printSpikes(current_file_path)
            pre_recorded_spikes = p.utility_calls.read_spikes_from_file(
                current_file_path, 0, n_exc, 0, tstop)

            for spike_element, read_element in zip(exc_spikes,
                                                   pre_recorded_spikes):
                self.assertEqual(round(spike_element[0], 1),
                                 round(read_element[0], 1))
                self.assertEqual(round(spike_element[1], 1),
                                 round(read_element[1], 1))

            p.end()


# System intentional overload so may error
        except SpinnmanTimeoutException as ex:
            raise SkipTest(ex)
コード例 #23
0
def do_run(nNeurons, neurons_per_core):

    p.setup(timestep=1.0, min_delay=1.0, max_delay=32.0)
    p.set_number_of_neurons_per_core("IF_curr_exp", neurons_per_core)

    nPopulations = 62
    cell_params_lif = {
        'cm': 0.25,
        'i_offset': 0.0,
        'tau_m': 20.0,
        'tau_refrac': 2.0,
        'tau_syn_E': 5.0,
        'tau_syn_I': 5.0,
        'v_reset': -70.0,
        'v_rest': -65.0,
        'v_thresh': -50.0
    }

    populations = list()
    projections = list()

    weight_to_spike = 1.5
    delay = 5

    for i in range(0, nPopulations):
        populations.append(
            p.Population(nNeurons,
                         p.IF_curr_exp,
                         cell_params_lif,
                         label='pop_' + str(i)))
        # print "++++++++++++++++"
        # print "Added population %s" % (i)
        # print "o-o-o-o-o-o-o-o-"
    for i in range(0, nPopulations):
        projections.append(
            p.Projection(populations[i],
                         populations[(i + 1) % nPopulations],
                         p.OneToOneConnector(weight_to_spike, delay),
                         label="Projection from pop {} to pop "
                         "{}".format(i, (i + 1) % nPopulations)))
        # print "++++++++++++++++++++++++++++++++++++++++++++++++++++"
        # print "Added projection from population %s to population %s" \
        #       % (i, (i + 1) % nPopulations)

        # print "----------------------------------------------------"

    # pp(projections)
    spikeArray = {'spike_times': [[0]]}
    populations.append(
        p.Population(1, p.SpikeSourceArray, spikeArray, label='inputSpikes_1'))
    projections.append(
        p.Projection(populations[-1], populations[0],
                     p.AllToAllConnector(weight_to_spike, delay)))

    for i in range(0, nPopulations):
        populations[i].record_v()
        populations[i].record_gsyn()
        populations[i].record()

    p.run(1500)

    v = None
    gsyn = None
    spikes = None
    ''''
    weights = projections[0].getWeights()
    delays = projections[0].getDelays()
    '''

    v = populations[0].get_v(compatible_output=True)
    gsyn = populations[0].get_gsyn(compatible_output=True)
    spikes = populations[0].getSpikes(compatible_output=True)

    p.end()

    return (v, gsyn, spikes)
コード例 #24
0
ファイル: test_brainstem.py プロジェクト: rjames91/Brainstem
oct_pop = sim.Population(oct_pop_size,
                         sim.IF_curr_exp,
                         D_stellate_parameters,
                         label="D_stellate_pop")

#create connectivity list for AN-->D_stellate_pop projections TODO:change this weight to depend on fan_in_d
an_oct_weight = 4  #100/fan_in_oct#0.3
an_oct_conns = []
for i in range(oct_pop_size):
    for j in range(fan_in_oct):
        an_index = i * fan_in_oct + j  #i+j#
        an_oct_conns.append((an_index, i, an_oct_weight, 1.))

#setup projection
an_d_proj = sim.Projection(AN_pop,
                           oct_pop,
                           sim.FromListConnector(an_oct_conns),
                           target="excitatory")
oct_pop.record('spikes')
oct_pop.record_v()

#AN_pop.record('spikes')

T_stellate_parameters_IZH = {
    'a': 0.02,  #Izhikevich
    'b': 0.2,
    'c': -65,
    'd': 10,
    # 'v_init': -75,
    # 'u_init': 0,
    'tau_syn_E': 3,
    #'tau_syn_I': 10,
コード例 #25
0
    def apply_constraints(self,
                          kind="inhibitory",
                          w_range=[-0.2, -0.0],
                          d_range=[2.0, 2.0],
                          random_cons=False,
                          pAF=0.5):
        """Map constraints list to inhibitory or excitatory connections between neural populations.

        The clues_inhibition class variable determines whether clues should receive inhibitory connections or not.

        args:
            kind: whether constraints are inhibitory or excitatory.
            w_range: range for the random distribution of synaptic weights in the form [w_min, w_max].
            d_range: range for the random distribution of synaptic delays in the form [d_min, d_max].
            random_cons: whether constraints are randomly choosen to be inhibitory or excitatory with probability pAF.
            pAF: probability of inhibitory connections, as a probability it should be between 0.0 and 1.0. It only works
                when random_cons is True.
         """
        delays = RandomDistribution('uniform', d_range)
        weights = RandomDistribution('uniform', w_range)  # 1.8 2.0 spin_system
        if 'weight' in self.constraints[0]:
            print msg, '''creating constraints between CSP variables with specified weights and randomly distributed
                        delays'''
        else:
            print msg, '''creating constraints between CSP variables with random and  uniformelly distributed delays
                       and weights'''
        for constraint in self.constraints:
            source = constraint['source']
            target = constraint['target']
            if random_cons:
                kind = np.random.choice(['inhibitory', 'excitatory'],
                                        p=[pAF, 1 - pAF])
            #TODO find a way of reducing the next two conditionals, they're equal except for conditioning on target...
            #TODO ... being a clue.
            if self.clues_inhibition:
                connections = []
                for n in range(self.size):
                    for m in range(self.size):
                        if 'weight' in constraint:
                            weight = constraint['weight']
                        else:
                            weight = weights.next()
                        connections.append(
                            (m, n, weight if m // self.core_size == n //
                             self.core_size else 0.0, delays.next()))
                synapses = p.Projection(self.var_pops[source],
                                        self.var_pops[target],
                                        p.FromListConnector(connections,
                                                            safe=True),
                                        target=kind)
                self.constraint_conns.append(synapses)
                if self.directed == False:
                    synapses = p.Projection(self.var_pops[target],
                                            self.var_pops[source],
                                            p.FromListConnector(connections,
                                                                safe=True),
                                            target=kind)
                    self.constraint_conns.append(synapses)
            elif target not in self.clues[0]:
                connections = []
                for n in range(self.size):
                    for m in range(self.size):
                        if 'weight' in constraint:
                            weight = constraint['weight']
                        else:
                            weight = weights.next()
                        connections.append(
                            (m, n, weight if m // self.core_size == n //
                             self.core_size else 0.0, delays.next()))
                synapses = p.Projection(self.var_pops[source],
                                        self.var_pops[target],
                                        p.FromListConnector(connections,
                                                            safe=True),
                                        target=kind)
                self.constraint_conns.append(synapses)
                if self.directed == False:
                    synapses = p.Projection(self.var_pops[target],
                                            self.var_pops[source],
                                            p.FromListConnector(connections,
                                                                safe=True),
                                            target=kind)
                    self.constraint_conns.append(synapses)
コード例 #26
0
def do_run():
    # SpiNNaker setup
    p.setup(timestep=1.0, min_delay=1.0, max_delay=10.0)

    # +-------------------------------------------------------------------+
    # | General Parameters                                                |
    # +-------------------------------------------------------------------+

    # Population parameters
    model = p.IF_curr_exp
    # model = sim.IF_cond_exp
    """
    cell_params = {'i_offset' : .1,    'tau_refrac' : 3.0, 'v_rest' : -65.0,
                   'v_thresh' : -51.0,  'tau_syn_E'  : 2.0,
                   'tau_syn_I': 5.0,    'v_reset'    : -70.0}
    """
    cell_params = {
        'cm': 0.25,  # nF
        'i_offset': 0.0,
        'tau_m': 10.0,
        'tau_refrac': 2.0,
        'tau_syn_E': 2.5,
        'tau_syn_I': 2.5,
        'v_reset': -70.0,
        'v_rest': -65.0,
        'v_thresh': -55.4
    }

    # Other simulation parameters
    e_rate = 200
    in_rate = 350

    n_stim_test = 5
    n_stim_pairing = 10
    dur_stim = 20

    pop_size = 40

    ISI = 150.
    start_test_pre_pairing = 200.
    start_pairing = 1500.
    start_test_post_pairing = 700.

    simtime = start_pairing + start_test_post_pairing + \
        ISI * (n_stim_pairing + n_stim_test) + 550.  # let's make it 5000

    # Initialisations of the different types of populations
    IAddPre = []
    IAddPost = []

    # +-------------------------------------------------------------------+
    # | Creation of neuron populations                                    |
    # +-------------------------------------------------------------------+

    # Neuron populations
    pre_pop = p.Population(pop_size, model, cell_params)
    post_pop = p.Population(pop_size, model, cell_params)

    # Test of the effect of activity of the pre_pop population on the post_pop
    # population prior to the "pairing" protocol : only pre_pop is stimulated
    for i in range(n_stim_test):
        IAddPre.append(
            p.Population(
                pop_size, p.SpikeSourcePoisson, {
                    'rate': in_rate,
                    'start': start_test_pre_pairing + ISI * (i),
                    'duration': dur_stim
                }))

    # Pairing protocol : pre_pop and post_pop are stimulated with a 10 ms
    # difference
    for i in range(n_stim_pairing):
        IAddPre.append(
            p.Population(
                pop_size, p.SpikeSourcePoisson, {
                    'rate': in_rate,
                    'start': start_pairing + ISI * (i),
                    'duration': dur_stim
                }))
        IAddPost.append(
            p.Population(
                pop_size, p.SpikeSourcePoisson, {
                    'rate': in_rate,
                    'start': start_pairing + ISI * (i) + 10.,
                    'duration': dur_stim
                }))

    # Test post pairing : only pre_pop is stimulated
    # (and should trigger activity in Post)
    for i in range(n_stim_test):
        start = start_pairing + ISI * n_stim_pairing + \
                start_test_post_pairing + ISI * i
        IAddPre.append(
            p.Population(pop_size, p.SpikeSourcePoisson, {
                'rate': in_rate,
                'start': start,
                'duration': dur_stim
            }))

    # Noise inputs
    INoisePre = p.Population(pop_size,
                             p.SpikeSourcePoisson, {
                                 'rate': e_rate,
                                 'start': 0,
                                 'duration': simtime
                             },
                             label="expoisson")
    params = {'rate': e_rate, 'start': 0, 'duration': simtime}
    INoisePost = p.Population(pop_size,
                              p.SpikeSourcePoisson,
                              params,
                              label="expoisson")

    # +-------------------------------------------------------------------+
    # | Creation of connections                                           |
    # +-------------------------------------------------------------------+

    # Connection parameters
    JEE = 3.

    # Connection type between noise poisson generator and
    # excitatory populations
    ee_connector = p.OneToOneConnector(weights=JEE * 0.05)

    # Noise projections
    p.Projection(INoisePre, pre_pop, ee_connector, target='excitatory')
    p.Projection(INoisePost, post_pop, ee_connector, target='excitatory')

    # Additional Inputs projections
    for i in range(len(IAddPre)):
        p.Projection(IAddPre[i], pre_pop, ee_connector, target='excitatory')
    for i in range(len(IAddPost)):
        p.Projection(IAddPost[i], post_pop, ee_connector, target='excitatory')

    # Plastic Connections between pre_pop and post_pop
    timing_dependence = p.SpikePairRule(tau_plus=20., tau_minus=50.0)
    weight_dependence = p.AdditiveWeightDependence(w_min=0,
                                                   w_max=0.9,
                                                   A_plus=0.02,
                                                   A_minus=0.02)
    stdp_model = p.STDPMechanism(timing_dependence=timing_dependence,
                                 weight_dependence=weight_dependence)

    plastic_projection = \
        p.Projection(pre_pop, post_pop,
                     p.FixedProbabilityConnector(p_connect=0.5),
                     synapse_dynamics=p.SynapseDynamics(slow=stdp_model)
                     )

    # +-------------------------------------------------------------------+
    # | Simulation and results                                            |
    # +-------------------------------------------------------------------+

    # Record neurons' potentials
    pre_pop.record_v()
    post_pop.record_v()

    # Record spikes
    pre_pop.record()
    post_pop.record()

    # Run simulation
    p.run(simtime)

    weights = plastic_projection.getWeights()

    pre_spikes = pre_pop.getSpikes(compatible_output=True)
    post_spikes = post_pop.getSpikes(compatible_output=True)

    p.end()

    return (weights, pre_spikes, post_spikes)
コード例 #27
0
                       [i[2] for i in v_for_neuron])


p.setup(time_step)

input_pop = p.Population(1,
                         p.SpikeSourceArray, {"spike_times": spike_times},
                         label="input")

my_model_pop = p.Population(1,
                            MyModelCurrExp, {
                                "my_parameter": -70.0,
                                "i_offset": i_offset,
                            },
                            label="my_model_pop")
p.Projection(input_pop, my_model_pop, p.OneToOneConnector(weights=weight))

my_model_my_synapse_type_pop = p.Population(
    1,
    MyModelCurrMySynapseType, {
        "my_parameter": -70.0,
        "i_offset": i_offset,
        "my_ex_synapse_parameter": 0.5
    },
    label="my_model_my_synapse_type_pop")
p.Projection(input_pop, my_model_my_synapse_type_pop,
             p.OneToOneConnector(weights=weight))

my_model_my_additional_input_pop = p.Population(
    1,
    MyModelCurrExpMyAdditionalInput, {
コード例 #28
0
# # FPGA Retina - Up Polarity
# retina_pop = p.Population(
#     None, q.ExternalFPGARetinaDevice, get_updated_params({
#         'retina_key': 0x5,
#         'mode': q.ExternalFPGARetinaDevice.MODE_128,
#         'polarity': q.ExternalFPGARetinaDevice.UP_POLARITY}),
#     label='External retina')

# FPGA Retina - Down Polarity
retina_pop = p.Population(
    None,
    p.external_devices.ExternalFPGARetinaDevice,
    get_updated_params({
        'retina_key':
        0x5,
        'mode':
        p.external_devices.ExternalFPGARetinaDevice.MODE_128,
        'polarity':
        p.external_devices.ExternalFPGARetinaDevice.DOWN_POLARITY
    }),
    label='External retina')

population = p.Population(1024, p.IF_curr_exp, {}, label='pop_1')
p.Projection(
    retina_pop, population,
    p.FromListConnector(retina_lib.subSamplerConnector2D(128, 32, 2.0, 1)))

# q.activate_live_output_for(population)
p.run(100)
p.end()
コード例 #29
0
def do_run(nNeurons):

    p.setup(timestep=1.0, min_delay=1.0, max_delay=32.0)

    p.set_number_of_neurons_per_core("IF_curr_exp", 100)

    cm = list()
    i_off = list()
    tau_m = list()
    tau_re = list()
    tau_syn_e = list()
    tau_syn_i = list()
    v_reset = list()
    v_rest = list()
    v_thresh = list()

    cell_params_lif = {'cm': cm, 'i_offset': i_off, 'tau_m': tau_m,
                       'tau_refrac': tau_re, 'tau_syn_E': tau_syn_e,
                       'tau_syn_I': tau_syn_i, 'v_reset': v_reset,
                       'v_rest': v_rest, 'v_thresh': v_thresh}

    for atom in range(0, nNeurons):
        cm.append(0.25)
        i_off.append(0.0)
        tau_m.append(10.0)
        tau_re.append(2.0)
        tau_syn_e.append(0.5)
        tau_syn_i.append(0.5)
        v_reset.append(-65.0)
        v_rest.append(-65.0)
        v_thresh.append(-64.4)

    gbar_na_distr = RandomDistribution('normal', (20.0, 2.0),
                                       rng=NumpyRNG(seed=85524))

    cell_params_lif = {'cm': cm, 'i_offset': i_off, 'tau_m': tau_m,
                       'tau_refrac': tau_re, 'tau_syn_E': tau_syn_e,
                       'tau_syn_I': tau_syn_i, 'v_reset': v_reset,
                       'v_rest': v_rest, 'v_thresh': v_thresh}

    populations = list()
    projections = list()

    weight_to_spike = 2
    delay = 1

    connections = list()
    for i in range(0, nNeurons):
        singleConnection = (i, ((i + 1) % nNeurons), weight_to_spike, delay)
        connections.append(singleConnection)

    injectionConnection = [(0, 0, weight_to_spike, delay)]
    spikeArray = {'spike_times': [[0]]}
    populations.append(p.Population(nNeurons, p.IF_curr_exp, cell_params_lif,
                                    label='pop_1'))
    populations.append(p.Population(1, p.SpikeSourceArray, spikeArray,
                                    label='inputSpikes_1'))

    populations[0].set({'cm': 0.25})
    populations[0].set('cm', cm)
    populations[0].set({'tau_m': tau_m, 'v_thresh': v_thresh})
    populations[0].set('i_offset', gbar_na_distr)
    populations[0].set('i_offset', i_off)

    projections.append(p.Projection(populations[0], populations[0],
                                    p.FromListConnector(connections)))
    projections.append(p.Projection(populations[1], populations[0],
                                    p.FromListConnector(injectionConnection)))

    populations[0].record_v()
    populations[0].record_gsyn()
    populations[0].record()

    p.run(100)

    v = populations[0].get_v(compatible_output=True)
    gsyn = populations[0].get_gsyn(compatible_output=True)
    spikes = populations[0].getSpikes(compatible_output=True)

    p.end()

    return (v, gsyn, spikes)
コード例 #30
0
stdp_model = sim.STDPMechanism(
    timing_dependence = TimingDependenceCerebellum(tau=tau, peak_time=peak_time),
    weight_dependence = sim.AdditiveWeightDependence(w_min=1.0, w_max=15.0, A_plus=0.5, A_minus=0.01)
)

#stdp_model = sim.STDPMechanism(
#    timing_dependence = sim.SpikePairRule(tau_plus=tau, tau_minus=tau),
#    weight_dependence = sim.AdditiveWeightDependence(w_min=1.0, w_max=15.0, A_plus=0.1, A_minus=0.1)
#)


# Connections between spike sources and neuron populations
    ####### SET HERE THE PARALLEL FIBER-PURKINJE CELL LEARNING RULE
ee_connector = sim.AllToAllConnector(weights=1.0)
projection_pf = sim.Projection(pre_stim, population, ee_connector,
                                         synapse_dynamics=sim.SynapseDynamics(slow=stdp_model),
                                         target='excitatory')

                                         
proj2 = sim.Projection(pre_stim, population2, ee_connector,target='excitatory')

# SET HERE THE TEACHING SIGNAL PROJECTION
ee_connector = sim.OneToOneConnector(weights=0.0)
proj_teaching = sim.Projection(teaching_stim, population, ee_connector, target='supervision')
#proj_dummy = sim.Projection(dummy_stim,population,sim.OneToOneConnector(weights=1000.1), target='inhibitory')

#IPython.embed()

print("Simulating for %us" % (sim_time / 1000))

# Run simulation