Ejemplo n.º 1
0
 def connect_retina(retina,
                    network_topology_matrix,
                    block_l=None,
                    block_r=None):
     # since the network topology is a lower triangular matrix, iterating over the rows and removing the
     # artificially added -1 padding elements, yields the population ids in the network to which
     # a pixel from the left retina should be connected. The same is repeated for the right retina
     # but this time the network topology matrix is iterated along the columns.
     for pixel_id, row in enumerate(network_topology_matrix):
         for population_id in row[row >= 0]:
             pyNN.Projection(
                 presynaptic_population=retina[pixel_id],
                 postsynaptic_population=self._network['collectors']
                 [population_id],
                 connector=pyNN.OneToOneConnector(
                     weights=self.params['synapse']['wSC'],
                     delays=self.params['synapse']['dSC']),
                 target='excitatory')
             if block_l is not None and block_r is not None:
                 pyNN.Projection(
                     presynaptic_population=retina[pixel_id],
                     postsynaptic_population=self._network['blockers']
                     [population_id],
                     connector=pyNN.FromListConnector(block_l),
                     target='excitatory')
                 pyNN.Projection(
                     presynaptic_population=retina[pixel_id],
                     postsynaptic_population=self._network['blockers']
                     [population_id],
                     connector=pyNN.FromListConnector(block_r),
                     target='inhibitory')
Ejemplo n.º 2
0
def do_run(nNeurons):
    p.setup(timestep=1.0, min_delay=1.0, max_delay=144.0)
    max_delay = 50
    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
    }

    populations = list()
    projections = list()

    weight_to_spike = 2.0
    delay = numpy.random.RandomState()
    delays = list()

    connections = list()
    for i in range(0, nNeurons):
        d_value = int(delay.uniform(low=1, high=max_delay))
        delays.append(float(d_value))
        singleConnection = (i, ((i + 1) % nNeurons), weight_to_spike, d_value)
        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'))

    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()

    run_time = (max_delay * nNeurons)
    print "Running for {} ms".format(run_time)
    p.run(run_time)

    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)
Ejemplo n.º 3
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", 250)

    cell_params_lif = {
        'cm': 0.25,
        'i_offset': 0.0,
        'tau_m': 20.0,
        'tau_refrac': 5.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 = 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'))

    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(1000)
    ''''
    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)
Ejemplo n.º 4
0
    def internal_inhibition(self, w_range=[-0.2, 0.0], d_range=[2.0, 2.0]):
        """Connect the domains populations of the same variable using inhibitory synapses.

        the connectiviy establishes a lateral inhibition circuit over the domains of each variable, so that most of the
        time only the neurons from a single domain population are active.

        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, 'Creating lateral inhibition between domains of each variable'
        delays = RandomDistribution('uniform', d_range)
        weights = RandomDistribution('uniform', w_range)
        connections = [(m, n, 0.0 if m // self.core_size == n //
                        self.core_size else weights.next(), delays.next())
                       for n in range(self.size) for m in range(self.size)]
        for variable in range(self.variables_number):
            if self.clues_inhibition:
                synapses = p.Projection(self.var_pops[variable],
                                        self.var_pops[variable],
                                        p.FromListConnector(connections,
                                                            safe=True),
                                        target="inhibitory")
                self.internal_conns.append(synapses)
            elif variable not in self.clues:
                synapses = p.Projection(self.var_pops[variable],
                                        self.var_pops[variable],
                                        p.FromListConnector(connections,
                                                            safe=True),
                                        target="inhibitory")
                self.internal_conns.append(synapses)
 def test_tun(self):
     with self.assertRaises(SpinnmanTimeoutException):
         p.setup(timestep=1.0, min_delay=1.0, max_delay=144.0)
         # add to the path the location of the dodgy binary
         # (if_cur_exp with the c_main bodged to result in it
         # running for twice as long as expected)
         ex_finder = AbstractSpiNNakerCommon._EXECUTABLE_FINDER
         ex_finder.add_path(os.path.dirname(__file__))
         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 = 17
         loopConnections = list()
         for i in range(0, nNeurons):
             singleConnection = (i, ((i + 1) % nNeurons), weight_to_spike,
                                 delay)
             loopConnections.append(singleConnection)
         injectionConnection = [(0, 0, weight_to_spike, 1)]
         spikeArray = {'spike_times': [[0]]}
         populations.append(
             p.Population(nNeurons,
                          FakeIFCurrExp,
                          cell_params_lif,
                          label='pop_1'))
         populations.append(
             p.Population(1,
                          p.SpikeSourceArray,
                          spikeArray,
                          label='inputSpikes_1'))
         projections.append(
             p.Projection(populations[0], populations[0],
                          p.FromListConnector(loopConnections)))
         projections.append(
             p.Projection(populations[1], populations[0],
                          p.FromListConnector(injectionConnection)))
         populations[0].record_v()
         populations[0].record_gsyn()
         populations[0].record()
         p.run(5000)
         p.end()
Ejemplo n.º 6
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(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()

    weight_to_spike = 40
    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': [[50]]}
    populations.append(p.Population(nNeurons, IZK_curr_exp, cell_params_izk,
                                    label='pop_1'))
    populations.append(p.Population(1, p.SpikeSourceArray, spikeArray,
                                    label='inputSpikes_1'))

    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(500)

    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)
Ejemplo n.º 7
0
def setup_cam_pop(sim, spike_array, img_w, img_h, ch_bits=1, event_bits=0,
                    w2s=W2S):
    row_bits = int(np.ceil(np.log2(img_h)))
    col_bits = int(np.ceil(np.log2(img_w)))
    pop_size = (1 << (row_bits + col_bits + ch_bits + event_bits))
    cell = sim.IF_curr_exp

    dmy_pops = []
    dmy_prjs = []
    if is_spinnaker(sim):
        cam_pop = sim.Population(pop_size, sim.SpikeSourceArray, 
                                 {'spike_times': spike_array}, 
                                 label='Source Camera')

    else:
        cam_pop = sim.Population(pop_size, cell, params, label='camera')

        for i in range(pop_size):
            dmy_pops.append(sim.Population(1, sim.SpikeSourceArray, 
                                        {'spike_times': spike_array[i]},
                                        label='pixel (row, col) = (%d, %d)'%\
                                        (i//img_w, i%img_w)))
            conn = [(0, i, w2s, 1)]
            dmy_prjs.append(sim.Projection(dmy_pops[i], cam_pop,
                                        sim.FromListConnector(conn),
                                        target='excitatory',
                                        label='dmy to cam %d'%i))

    return cam_pop, dmy_pops, dmy_prjs
def do_run():
    p.setup(timestep=1.0, min_delay=1.0, max_delay=1.0)

    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,
                   'e_rev_E':  0.,     'e_rev_I': -80.}

    # setup test population
    if_pop = p.Population(1, p.IF_cond_exp, cell_params)
    # setup spike sources
    exc_pop = p.Population(1, p.SpikeSourceArray,
                           {'spike_times': [20., 40., 60.]})
    inh_pop = p.Population(1, p.SpikeSourceArray,
                           {'spike_times': [120., 140., 160.]})
    # setup excitatory and inhibitory connections
    listcon = p.FromListConnector([(0, 0, 0.01, 1.0)])
    p.Projection(exc_pop, if_pop, listcon, target='excitatory')
    p.Projection(inh_pop, if_pop, listcon, target='inhibitory')
    # setup recorder
    if_pop.record_v()
    p.run(200.)
    # read out voltage and plot
    V = if_pop.get_v()
    p.end()

    return V
Ejemplo n.º 9
0
    def _gate_neurons(self, network):
        """
        Connect the blocker populations to the collectors according to the scheme described in [cite paper].
        
        Args:
            network: a dict with 'blockers' and 'collectors' lists of populations.

        Returns:
            In-place method
        """
        logger.info("Gating blocker and collector populations.")
        # generate connection lists as follows:
        #   * neurons with id from 0 until the vertical retina resolution -1 (dy - 1) serve as the left blocking neurons
        #   * and neurons with id from dy to the end, i.e. 2dy - 1, serve as the right blocking neurons
        connection_list = []
        for y in range(self.retina_n_rows):
            connection_list.append((y, y, self.params['synapse']['wBC'],
                                    self.params['synapse']['dBC']))
            connection_list.append(
                (y + self.retina_n_rows, y, self.params['synapse']['wBC'],
                 self.params['synapse']['dBC']))

        logger.debug(
            "Generated gating connection list: {}".format(connection_list))
        # connect the inhibitory neurons (blockers) to the cell output (collector) neurons
        for blockers, collectors in zip(network['blockers'],
                                        network['collectors']):
            pyNN.Projection(blockers,
                            collectors,
                            pyNN.FromListConnector(connection_list),
                            target='inhibitory')
        logger.debug("Gating blocker and collector populations completed.")
Ejemplo n.º 10
0
    def connect_cores(self, w_range=[0.6, 1.2], d_range=[1.0, 1.2]):
        """Create internal excitatory connections between the neurons of each domain subpopulation of each variable.

        In the network representing the CSP, each neural population representing a variable contains a subpopulation
        for each possible value on its domain. This method connects all-to-all the neurons of each domain population
        of each variable using escitatory synapses.

        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, 'internally connnecting the neurons of each domain of each variable'
        delays = RandomDistribution('uniform', d_range)
        weights = RandomDistribution('uniform', w_range)
        connections = [
            (m, n, weights.next() if m // self.core_size == n // self.core_size
             and m != n else 0.0, delays.next())
            for n in range(self.domain_size * self.core_size)
            for m in range(self.domain_size * self.core_size)
        ]
        for variable in range(self.variables_number):
            synapses = p.Projection(self.var_pops[variable],
                                    self.var_pops[variable],
                                    p.FromListConnector(connections,
                                                        safe=True),
                                    target="excitatory")
            self.core_conns.append(synapses)
Ejemplo n.º 11
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)

    cell_params_lif = {
        'cm': 0.25,
        'i_offset': 0.0,
        'tau_m': 10.0,
        'tau_refrac': 2.0,
        'tau_syn_E': 0.5,
        'tau_syn_I': 0.5,
        'v_reset': -65.0,
        'v_rest': -65.0,
        'v_thresh': -64.4
    }

    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]]}
    for x in range(6):
        populations.append(
            p.Population(nNeurons, p.IF_curr_exp, cell_params_lif))
        populations.append(p.Population(1, p.SpikeSourceArray, spikeArray))

    for x in range(0, 12, 2):
        projections.append(
            p.Projection(populations[x], populations[x],
                         p.FromListConnector(connections)))
        connector = p.FromListConnector(injectionConnection)
        projections.append(
            p.Projection(populations[x + 1], populations[x], connector))
        populations[x].record()

    p.run(1000)

    p.end()
Ejemplo n.º 12
0
    def test_run(self):
        sim.setup()

        sim.Population(3, sim.SpikeSourcePoisson, {"rate": 100})
        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()
Ejemplo n.º 13
0
def do_run():
    sim.setup(timestep=1)
    pop_1 = sim.Population(1, sim.IF_curr_exp, {}, label="pop_1")
    inp = sim.Population(1,
                         sim.SpikeSourceArray, {'spike_times': [[0]]},
                         label="input")
    sim.Projection(pop_1, pop_1, sim.OneToOneConnector(weights=5.0, delays=1))

    pop_1.record("spikes")
    sim.run(20)
    first_spikes = pop_1.getSpikes()

    sim.Projection(inp, pop_1, sim.FromListConnector([[0, 0, 5, 5]]))

    sim.reset()
    sim.run(20)
    second_spikes = pop_1.getSpikes()

    return first_spikes, second_spikes
Ejemplo n.º 14
0
    def stimulate_cores(self,
                        w_range=[1.4, 1.4],
                        d_range=[1.0, 1.0],
                        w_clues=[1.4, 1.6]):  # w_clues=[0.0, 0.2]
        """Connect stimulating 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].
            w_clues: clues specific range for the random distribution of synaptic weights in the form [w_min, w_max].
        """
        p.set_number_of_neurons_per_core(p.IF_curr_exp, 150)
        print msg, 'connecting Poisson noise sources to neural populations for stimulation'
        delays = RandomDistribution('uniform', d_range)
        weights = RandomDistribution('uniform', w_range)
        weight_clues = RandomDistribution("uniform", w_clues)
        for stimulus in range(self.n_populations):
            for variable in range(self.variables_number):
                counter = 0
                if variable in self.clues[0]:
                    shift = self.clues[1][self.clues[0].index(
                        variable)] * self.core_size
                    connections = [(m, n + shift, weight_clues.next(),
                                    delays.next())
                                   for m in range(self.core_size)
                                   for n in range(self.clue_size)]
                    synapses = p.Projection(self.clues_stim[counter],
                                            self.var_pops[variable],
                                            p.FromListConnector(connections,
                                                                safe=True),
                                            target='excitatory')
                    counter += 1
                    self.stim_conns.append(synapses)
                else:
                    synapses = p.Projection(
                        self.stim_pops[stimulus][variable],
                        self.var_pops[variable],
                        p.OneToOneConnector(weights=weights, delays=delays),
                        target='excitatory')
                    self.stim_conns.append(synapses)
        self.stim_times += self.stims
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)
        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                                            |
# +-------------------------------------------------------------------+
Ejemplo n.º 17
0
        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)

if not args.lesion:
    print("No insults")
    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")
elif args.lesion == ONE_TO_ONE_LESION:
    # ff_pos = range(len(init_ff_connections))
    # lat_pos = range(len(init_lat_connections))
    # subsample_ff = np.random.choice(ff_pos, 10)
    # subsample_lat = np.random.choice(lat_pos, 10)
Ejemplo n.º 18
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.
    }

    populations = list()
    projections = list()

    weight_to_spike = 0.035
    delay = 17

    injectionConnection = [(0, 0, weight_to_spike, delay)]
    sinkConnection = [(0, 0, weight_to_spike, 1)]

    spikeArray = {'spike_times': [[0]]}

    populations.append(
        p.Population(nNeurons,
                     p.IF_cond_exp,
                     cell_params_cond,
                     label='pop_cond'))
    populations.append(
        p.Population(1, p.SpikeSourceArray, spikeArray, label='inputSpikes_1'))

    populations.append(
        p.Population(nNeurons,
                     p.IF_curr_exp,
                     cell_params_lif,
                     label='pop_curr'))
    populations.append(
        p.Population(1, p.SpikeSourceArray, spikeArray, label='inputSpikes_2'))

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

    projections.append(
        p.Projection(populations[1], populations[0],
                     p.FromListConnector(injectionConnection)))
    projections.append(
        p.Projection(populations[3], populations[2],
                     p.FromListConnector(injectionConnection)))
    projections.append(
        p.Projection(populations[0], populations[4],
                     p.FromListConnector(sinkConnection)))
    projections.append(
        p.Projection(populations[2], populations[4],
                     p.FromListConnector(sinkConnection)))
    populations[0].record_v()
    populations[0].record_gsyn()
    populations[0].record()

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

    p.run(500)

    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)

    curr_v = populations[2].get_v(compatible_output=True)
    curr_gsyn = populations[2].get_gsyn(compatible_output=True)
    curr_spikes = populations[2].getSpikes(compatible_output=True)

    p.end()

    return (cond_v, cond_gsyn, cond_spikes, curr_v, curr_gsyn, curr_spikes)
Ejemplo n.º 19
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."
        )
    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)
Ejemplo n.º 21
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()
Ejemplo n.º 22
0
def do_run(nNeurons, n_pops, neurons_per_core, runtime=25000):
    """

    :param nNeurons: Number of Neurons in chain
    :type  nNeurons: int
    :param n_pops: Number of populations
    ;type n_pops: int
    :param neurons_per_core: Number of neurons per core
    :type neurons_per_core: int
    """
    p.setup(timestep=1.0, min_delay=1.0, max_delay=144.0)
    p.set_number_of_neurons_per_core("IF_curr_exp", neurons_per_core)

    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 - 1):
        singleConnection = (i, i + 1, weight_to_spike, delay)
        connections.append(singleConnection)

    pop_jump_connection = [(nNeurons - 1, 0, weight_to_spike, 1)]

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

    spikeArray = {'spike_times': [[0]]}

    for i in range(0, n_pops):
        populations.append(
            p.Population(nNeurons,
                         p.IF_curr_exp,
                         cell_params_lif,
                         label='pop_{}'.format(i)))

    populations.append(
        p.Population(1, p.SpikeSourceArray, spikeArray, label='inputSpikes_1'))

    for i in range(0, n_pops):
        projections.append(
            p.Projection(populations[i], populations[i],
                         p.FromListConnector(connections)))
        connector = p.FromListConnector(pop_jump_connection)
        projections.append(
            p.Projection(populations[i], populations[((i + 1) % n_pops)],
                         connector))

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

    for pop_index in range(0, n_pops):
        populations[pop_index].record()

    p.run(runtime)

    total_spikes = None
    total_spikes = populations[0].getSpikes(compatible_output=True)
    for pop_index in range(1, n_pops):
        spikes = populations[pop_index].getSpikes(compatible_output=True)
        if spikes is not None:
            for spike in spikes:
                spike[0] += (nNeurons * pop_index)
            total_spikes = numpy.concatenate((total_spikes, spikes), axis=0)

    p.end()

    return total_spikes
Ejemplo n.º 23
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)
Ejemplo n.º 24
0
# Create a connection from the injector into the populations
Frontend.Projection(injector_forward, pop_forward,
                    Frontend.OneToOneConnector(weights=weight_to_spike))
Frontend.Projection(injector_backward, pop_backward,
                    Frontend.OneToOneConnector(weights=weight_to_spike))

# Synfire chain connections where each neuron is connected to its next neuron
# NOTE: there is no recurrent connection so that each chain stops once it
# reaches the end
loop_forward = list()
loop_backward = list()
for i in range(0, n_neurons - 1):
    loop_forward.append((i, (i + 1) % n_neurons, weight_to_spike, 3))
    loop_backward.append(((i + 1) % n_neurons, i, weight_to_spike, 3))
Frontend.Projection(pop_forward, pop_forward,
                    Frontend.FromListConnector(loop_forward))
Frontend.Projection(pop_backward, pop_backward,
                    Frontend.FromListConnector(loop_backward))

# record spikes from the synfire chains so that we can read off valid results
# in a safe way afterwards, and verify the behavior
pop_forward.record()
pop_backward.record()

# Activate the sending of live spikes
Frontend.external_devices.activate_live_output_for(
    pop_forward,
    database_notify_host="localhost",
    database_notify_port_num=19996)
Frontend.external_devices.activate_live_output_for(
    pop_backward,
Ejemplo n.º 25
0
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 = []

no_runs = simtime // t_record
Ejemplo n.º 26
0
                         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,
Ejemplo n.º 27
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:
Ejemplo n.º 28
0
    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
Ejemplo n.º 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)
Ejemplo n.º 30
0
    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