def _build(self): '''Create populations.''' def pos(idx): assert idx == 0, 'This population has only one node.' return (0.5, 0.5) # Source node is located at (0.5, 0.5) because csa.random2d() can # only scatter nodes on the unit square. self._g1 = pos self._g2 = csa.random2d(self._N) self._d = csa.euclidMetric2d(self._g1, self._g2)
def _connect(self): '''Connect populations.''' g1 = self._geometryFunction(self._ls) g2 = self._geometryFunction(self._lt) d = csa.euclidMetric2d(g1, g2) sigma = self._params['sigma'] cutoff = self._max_dist cs = csa.cset( csa.cross([0], xrange(self._N - 1)) * (csa.random * (csa.gaussian(sigma, cutoff) * d)), 1.0, 1.0) nest.CGConnect( nest.GetLeaves(self._ls)[0], nest.GetLeaves(self._lt)[0], cs, { 'weight': 0, 'delay': 1 })
def csa_topology_example(): # layers have 20x20 neurons and extent 1 x 1 pop1 = topo.CreateLayer({'elements': 'iaf_neuron', 'rows': 20, 'columns': 20}) pop2 = topo.CreateLayer({'elements': 'iaf_neuron', 'rows': 20, 'columns': 20}) # create CSA-style geometry functions and metric g1 = geometryFunction(pop1) g2 = geometryFunction(pop2) d = csa.euclidMetric2d(g1, g2) # Gaussian connectivity profile, sigma = 0.2, cutoff at 0.5 cs = csa.cset(csa.random * (csa.gaussian(0.2, 0.5) * d), 10000.0, 1.0) # create connections nest.CGConnect(pop1, pop2, cs, {"weight": 0, "delay": 1}) # show targets of center neuron topo.PlotTargets(topo.FindCenterElement(pop1), pop2)
'rows': 20, 'columns': 20 }) pop2 = topo.CreateLayer({ 'elements': 'iaf_psc_alpha', 'rows': 20, 'columns': 20 }) """ For each layer, we create a CSA-style geometry function and a CSA metric based on them. """ g1 = geometryFunction(pop1) g2 = geometryFunction(pop2) d = csa.euclidMetric2d(g1, g2) """ The connection set ``cs`` describes a Gaussian connectivity profile with sigma = 0.2 and cutoff at 0.5, and two values (10000.0 and 1.0) used as weight and delay, respectively. """ cs = csa.cset(csa.random * (csa.gaussian(0.2, 0.5) * d), 10000.0, 1.0) """ We can now connect the populations using the `CGConnect` function. It takes the IDs of pre- and postsynaptic neurons (``pop1`` and ``pop2``), the connection set (``cs``) and a dictionary that maps the parameters weight and delay to positions in the value set associated with the connection set. """
def do_run(plot): p.setup(timestep=1.0) 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': -40.0 } n = 13 # 10 # 5 p.set_number_of_neurons_per_core(p.IF_curr_exp, n) weight_to_spike = 2.0 delay = 5 runtime = 200 # Network grid = csa.grid2d(n, xScale=1.0 * n, yScale=1.0 * n) # SpikeInjector injectionConnection = [(0, 0)] spikeArray = {'spike_times': [[0]]} inj_pop = p.Population(1, p.SpikeSourceArray(**spikeArray), label='inputSpikes_1') # grid population grid_pop = p.Population(n * n, p.IF_curr_exp(**cell_params_lif), label='grid_pop') p.Projection(inj_pop, grid_pop, p.FromListConnector(injectionConnection), p.StaticSynapse(weight=weight_to_spike, delay=delay)) # Connectors exc_connector_set = csa.disc(2.5) * csa.euclidMetric2d(grid) exc_connector = p.CSAConnector(exc_connector_set) inh_connector_set = csa.disc(1.5) * csa.euclidMetric2d(grid) inh_connector = p.CSAConnector(inh_connector_set) # Wire grid p.Projection(grid_pop, grid_pop, exc_connector, p.StaticSynapse(weight=2.0, delay=10)) p.Projection(grid_pop, grid_pop, inh_connector, p.StaticSynapse(weight=0.5, delay=15)) grid_pop.record(['v', 'spikes']) p.run(runtime) v = grid_pop.spinnaker_get_data('v') spikes = grid_pop.spinnaker_get_data('spikes') if plot: # original grid csa.gplot2d(grid, n * n) # excitatory connector exc_connector.show_connection_set() csa.gplotsel2d(grid, exc_connector_set, range(n * n), range(n * n), N0=n * n) # inhibitory connector inh_connector.show_connection_set() csa.gplotsel2d(grid, inh_connector_set, range(n * n), range(n * n), N0=n * n) # Now plot spikes and v pylab.figure() pylab.plot([i[1] for i in spikes], [i[0] for i in spikes], "r.") pylab.xlabel('Time/ms') pylab.ylabel('spikes') pylab.title('spikes') pylab.show() pylab.figure() ticks = len(v) // (n * n) for pos in range(0, n * n): v_for_neuron = v[pos * ticks:(pos + 1) * ticks] pylab.plot([i[2] for i in v_for_neuron]) pylab.xlabel('Time/ms') pylab.ylabel('V') pylab.title('membrane voltages per neuron') pylab.show() p.end() return v, spikes
We create two layers that have 20x20 neurons of type `iaf_psc_alpha`. """ pop1 = topo.CreateLayer({'elements': 'iaf_psc_alpha', 'rows': 20, 'columns': 20}) pop2 = topo.CreateLayer({'elements': 'iaf_psc_alpha', 'rows': 20, 'columns': 20}) """ For each layer, we create a CSA-style geometry function and a CSA metric based on them. """ g1 = geometryFunction(pop1) g2 = geometryFunction(pop2) d = csa.euclidMetric2d(g1, g2) """ The connection set ``cs`` describes a Gaussian connectivity profile with sigma = 0.2 and cutoff at 0.5, and two values (10000.0 and 1.0) used as weight and delay, respectively. """ cs = csa.cset(csa.random * (csa.gaussian(0.2, 0.5) * d), 10000.0, 1.0) """ We can now connect the populations using the `CGConnect` function. It takes the IDs of pre- and postsynaptic neurons (``pop1`` and ``pop2``), the connection set (``cs``) and a dictionary that maps the parameters weight and delay to positions in the value set associated with the connection set.
node = setup(timestep=0.025, min_delay=1.0, max_delay=1.0, debug=True, quit_on_end=False) print "Process with rank %d running on %s" % (node, socket.gethostname()) rng = NumpyRNG(seed=seed, parallel_safe=True) print "[%d] Creating populations" % node n_spikes = int(2*tstop*input_rate/1000.0) spike_times = numpy.add.accumulate(rng.next(n_spikes, 'exponential', [1000.0/input_rate], mask_local=False)) input_population = Population(10, SpikeSourceArray, {'spike_times': spike_times }, label="input") output_population = Population(10, IF_curr_exp, cell_params, label="output") g=csa.grid2d(3) d=csa.euclidMetric2d(g,g) connector = CSAConnector(csa.cset(csa.random(0.5), csa.gaussian(0.1,1.0)*d, 1.0)) projection = Projection(input_population, output_population, connector, rng=rng) file_stem = "Results/simpleRandomNetwork_np%d_%s" % (num_processes(), simulator_name) projection.saveConnections('%s.conn' % file_stem) output_population.record_v() print "[%d] Running simulation" % node run(tstop) print "[%d] Writing Vm to disk" % node output_population.print_v('%s.v' % file_stem)