def test_csa_block_connector(): MockSimulator.setup() try: # This creates a block of size (2, 5) with a probability of 0.5; then # within the block an individual connection has a probability of 0.3 connector = CSAConnector( csa.block(2, 5) * csa.random(0.5) * csa.random(0.3)) weight = 1.0 delay = 2.0 mock_synapse_info = MockSynapseInfo(MockPopulation(10, "pre"), MockPopulation(10, "post"), weight, delay) connector.set_projection_information(1000.0, mock_synapse_info) pre_vertex_slice = Slice(0, 10) post_vertex_slice = Slice(0, 10) block = connector.create_synaptic_block([pre_vertex_slice], 0, [post_vertex_slice], 0, pre_vertex_slice, post_vertex_slice, 0, mock_synapse_info) assert (len(block) >= 0) assert (all(item["weight"] == 1.0 for item in block)) assert (all(item["delay"] == 2.0 for item in block)) except TypeError: raise SkipTest("https://github.com/INCF/csa/issues/17") except RuntimeError: if sys.version_info >= (3, 7): raise SkipTest("https://github.com/INCF/csa/issues/16") raise
def _connect(self): '''Connect populations.''' finite_set = csa.cross(xrange(self._N_s), xrange(self._N_t)) if self._fan == 'in': self._cs = csa.cset(csa.random(fanIn=self._C) * finite_set) else: self._cs = csa.cset(csa.random(fanOut=self._C) * finite_set)
def _connect(self): '''Connect populations.''' finite_set = csa.cross(xrange(self._N_s), xrange(self._N_t)) if self._fan == 'in': cs = csa.cset(csa.random(fanIn=self._C) * finite_set) else: cs = csa.cset(csa.random(fanOut=self._C) * finite_set) nest.CGConnect(self._source_pop, self._target_pop, csa.cset(cs))
def csa_example(): cs = csa.cset(csa.random(0.1), 10000.0, 1.0) pop1 = nest.LayoutNetwork("iaf_neuron", [16]) pop2 = nest.LayoutNetwork("iaf_neuron", [16]) nest.PrintNetwork(10) nest.CGConnect(pop1, pop2, cs, {"weight": 0, "delay": 1}) pg = nest.Create("poisson_generator", params={"rate": 80000.0}) nest.DivergentConnect(pg, nest.GetLeaves(pop1)[0], 1.2, 1.0) vm_params = { "record_to": ["memory"], "withgid": True, "withtime": True, "interval": 0.1 } vm = nest.Create("voltmeter", params=vm_params) nest.DivergentConnect(vm, nest.GetLeaves(pop2)[0]) nest.Simulate(50.0) from nest import visualization allnodes = pg + nest.GetLeaves(pop1)[0] + nest.GetLeaves(pop2)[0] + vm visualization.plot_network(allnodes, "test_csa.png") if havePIL: im = Image.open("test_csa.png") im.show() from nest import voltage_trace voltage_trace.from_device(vm)
def csa_example(): cs = csa.cset(csa.random(0.1), 10000.0, 1.0) pop1 = nest.LayoutNetwork("iaf_neuron", [16]) pop2 = nest.LayoutNetwork("iaf_neuron", [16]) nest.PrintNetwork(10) nest.CGConnect(pop1, pop2, cs, {"weight": 0, "delay": 1}) pg = nest.Create("poisson_generator", params={"rate": 80000.0}) nest.DivergentConnect(pg, nest.GetLeaves(pop1)[0], 1.2, 1.0) vm_params = {"record_to": ["memory"], "withgid": True, "withtime": True, "interval": 0.1} vm = nest.Create("voltmeter", params=vm_params) nest.DivergentConnect(vm, nest.GetLeaves(pop2)[0]) nest.Simulate(50.0) from nest import visualization allnodes = pg + nest.GetLeaves(pop1)[0] + nest.GetLeaves(pop2)[0] + vm visualization.plot_network(allnodes, "test_csa.png") if havePIL: im = Image.open("test_csa.png") im.show() from nest import voltage_trace voltage_trace.from_device(vm)
def test_csa_random_connector(): unittest_setup() connector = CSAConnector(csa.random(0.05)) weight = 1.0 delay = 2.0 mock_synapse_info = SynapseInformation( connector=None, pre_population=MockPopulation(10, "Pre"), post_population=MockPopulation(10, "Post"), prepop_is_view=False, postpop_is_view=False, rng=None, synapse_dynamics=None, synapse_type=None, is_virtual_machine=False, weights=weight, delays=delay) connector.set_projection_information(mock_synapse_info) pre_vertex_slice = Slice(0, 10) post_vertex_slice = Slice(0, 10) block = connector.create_synaptic_block([pre_vertex_slice], [post_vertex_slice], pre_vertex_slice, post_vertex_slice, 0, mock_synapse_info) assert (len(block) >= 0) assert (all(item["weight"] == 1.0 for item in block)) assert (all(item["delay"] == 2.0 for item in block))
def test_csa_block_connector(): MockSimulator.setup() # This creates a block of size (2, 5) with a probability of 0.5; then # within the block an individual connection has a probability of 0.3 connector = CSAConnector( csa.block(2, 5) * csa.random(0.5) * csa.random(0.3)) connector.set_projection_information( MockPopulation(10, "pre"), MockPopulation(10, "post"), MockRNG(), 1000.0) pre_vertex_slice = Slice(0, 10) post_vertex_slice = Slice(0, 10) block = connector.create_synaptic_block( 1.0, 2.0, [pre_vertex_slice], 0, [post_vertex_slice], 0, pre_vertex_slice, post_vertex_slice, 0) assert(len(block) >= 0) assert(all(item["weight"] == 1.0 for item in block)) assert(all(item["delay"] == 2.0 for item in block))
def test_csa_block_connector(): unittest_setup() try: # This creates a block of size (2, 5) with a probability of 0.5; then # within the block an individual connection has a probability of 0.3 connector = CSAConnector( csa.block(2, 5) * csa.random(0.5) * csa.random(0.3)) weight = 1.0 delay = 2.0 mock_synapse_info = SynapseInformation( connector=None, pre_population=MockPopulation(10, "Pre"), post_population=MockPopulation(10, "Post"), prepop_is_view=False, postpop_is_view=False, rng=None, synapse_dynamics=None, synapse_type=None, receptor_type=None, is_virtual_machine=False, synapse_type_from_dynamics=False, weights=weight, delays=delay) connector.set_projection_information(mock_synapse_info) pre_vertex_slice = Slice(0, 10) post_vertex_slice = Slice(0, 10) block = connector.create_synaptic_block([pre_vertex_slice], 0, [post_vertex_slice], 0, pre_vertex_slice, post_vertex_slice, 0, mock_synapse_info) assert (len(block) >= 0) assert (all(item["weight"] == 1.0 for item in block)) assert (all(item["delay"] == 2.0 for item in block)) except TypeError as e: raise SkipTest("https://github.com/INCF/csa/issues/17") from e except RuntimeError as e: if sys.version_info >= (3, 7): raise SkipTest("https://github.com/INCF/csa/issues/16") from e raise e
def test_csa_random_connector(): MockSimulator.setup() connector = CSAConnector(csa.random(0.05)) connector.set_projection_information( MockPopulation(10, "pre"), MockPopulation(10, "post"), MockRNG(), 1000.0) pre_vertex_slice = Slice(0, 10) post_vertex_slice = Slice(0, 10) block = connector.create_synaptic_block( 1.0, 2.0, [pre_vertex_slice], 0, [post_vertex_slice], 0, pre_vertex_slice, post_vertex_slice, 0) assert(len(block) >= 0) assert(all(item["weight"] == 1.0 for item in block)) assert(all(item["delay"] == 2.0 for item in block))
def csa_example(): cs = csa.cset(csa.random(0.1), 10000.0, 1.0) # This does not work yet, as the implementation does not yet # support nested subnets. # #pop1 = nest.LayoutNetwork("iaf_neuron", [4,4]) #pop2 = nest.LayoutNetwork("iaf_neuron", [4,4]) pop1 = nest.LayoutNetwork("iaf_neuron", [16]) pop2 = nest.LayoutNetwork("iaf_neuron", [16]) nest.PrintNetwork(10) nest.CGConnect(pop1, pop2, cs, {"weight": 0, "delay": 1}) pg = nest.Create("poisson_generator", params={"rate": 80000.0}) nest.DivergentConnect(pg, nest.GetLeaves(pop1)[0], 1.2, 1.0) vm = nest.Create("voltmeter", params={ "record_to": ["memory"], "withgid": True, "withtime": True, "interval": 0.1 }) nest.DivergentConnect(vm, nest.GetLeaves(pop2)[0]) nest.Simulate(50.0) # Not yet supported in NEST #from nest import visualization #allnodes = [pg, nest.GetLeaves(pop1)[0], nest.GetLeaves(pop2)[0], vm] #visualization.plot_network(allnodes, "test_csa.png", "png", plot_modelnames=True #if havePIL: # im = Image.open("test_csa.png") # im.show() from nest import voltage_trace voltage_trace.from_device(vm)
def csa_example(): cs = csa.cset(csa.random(0.1), 10000.0, 1.0) # This does not work yet, as the implementation does not yet # support nested subnets. # # pop1 = nest.LayoutNetwork("iaf_neuron", [4,4]) # pop2 = nest.LayoutNetwork("iaf_neuron", [4,4]) pop1 = nest.LayoutNetwork("iaf_neuron", [16]) pop2 = nest.LayoutNetwork("iaf_neuron", [16]) nest.PrintNetwork(10) nest.CGConnect(pop1, pop2, cs, {"weight": 0, "delay": 1}) pg = nest.Create("poisson_generator", params={"rate": 80000.0}) nest.DivergentConnect(pg, nest.GetLeaves(pop1)[0], 1.2, 1.0) vm = nest.Create("voltmeter", params={"record_to": ["memory"], "withgid": True, "withtime": True, "interval": 0.1}) nest.DivergentConnect(vm, nest.GetLeaves(pop2)[0]) nest.Simulate(50.0) # Not yet supported in NEST # from nest import visualization # allnodes = [pg, nest.GetLeaves(pop1)[0], nest.GetLeaves(pop2)[0], vm] # visualization.plot_network(allnodes, "test_csa.png", "png", plot_modelnames=True # if havePIL: # im = Image.open("test_csa.png") # im.show() from nest import voltage_trace voltage_trace.from_device(vm)
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(100, SpikeSourceArray(spike_times=spike_times), label="input") output_population = Population(10, IF_curr_exp(**cell_params), label="output") print "[%d] input_population cells: %s" % (node, input_population.local_cells) print "[%d] output_population cells: %s" % (node, output_population.local_cells) print "[%d] Connecting populations" % node timer.start() connector = CSAConnector(csa.random(0.5), weights=0.1) #connector = CSAConnector(csa.cset(csa.random(0.5), 0.123, 1.6)) projection = Projection(input_population, output_population, connector, StaticSynapse()) print connector.describe(), timer.elapsedTime() file_stem = "Results/simpleRandomNetwork_csa_np%d_%s" % (num_processes(), simulator_name) projection.save('all', '%s.conn' % file_stem) input_population.record('spikes') output_population.record('spikes') output_population.sample(n_record, rng).record('v') print "[%d] Running simulation" % node
from time import time from sys import argv, exit from pyNN.nest import setup, Population, IF_cond_alpha, CSAConnector, Projection, nest import csa if len(argv) != 3: print "usage: nest_CSAConnector_csa_scaling.py <num_neurons> <num_procs>" exit() n = int(argv[1]) np = int(argv[2]) setup(timestep=0.1, min_delay=0.1, max_delay=4.0) pop = Population(n, IF_cond_alpha, {}) # measure random connectivity start = time() cset = csa.random(0.1) connector = CSAConnector(cset) proj = Projection(pop, pop, connector) rank = nest.Rank() nc = nest.GetKernelStatus("num_connections") nest.sli_run("preptime"); preptime = nest.sli_pop() nest.sli_run("itertime"); itertime = nest.sli_pop() print "nest CSAConnector random(0.1) csa %i %i %f %f %f %i %i" % (n, nc, time() - start, preptime, itertime, rank, np) #import nest.visualization as vis #vis.plot_network(pop.all_cells, "nest_CSAConnector_csa_scaling.pdf")
ext_conn = sim.FixedProbabilityConnector(rconn) ext_syn = sim.StaticSynapse(weight=0.1) print("%s Initialising membrane potential to random values..." % node_id) rng = NumpyRNG(seed=rngseed, parallel_safe=parallel_safe) uniformDistr = RandomDistribution('uniform', low=v_reset, high=v_thresh, rng=rng) if options.use_views: all_cells.initialize(v=uniformDistr) else: exc_cells.initialize(v=uniformDistr) inh_cells.initialize(v=uniformDistr) print("%s Connecting populations..." % node_id) progress_bar = ProgressBar(width=20) if options.use_csa: connector = CSAConnector(csa.cset(csa.random(pconn))) else: connector = sim.FixedProbabilityConnector(pconn, rng=rng, callback=progress_bar) exc_syn = sim.StaticSynapse(weight=w_exc, delay=delay) inh_syn = sim.StaticSynapse(weight=w_inh, delay=delay) connections = {} if options.use_views or options.use_assembly: connections['exc'] = sim.Projection(exc_cells, all_cells, connector, exc_syn, receptor_type='excitatory') connections['inh'] = sim.Projection(inh_cells, all_cells, connector, inh_syn, receptor_type='inhibitory') if (options.benchmark == "COBA"): connections['ext'] = sim.Projection(ext_stim, all_cells, ext_conn, ext_syn, receptor_type='excitatory') else: connections['e2e'] = sim.Projection(exc_cells, exc_cells, connector, exc_syn, receptor_type='excitatory') connections['e2i'] = sim.Projection(exc_cells, inh_cells, connector, exc_syn, receptor_type='excitatory') connections['i2e'] = sim.Projection(inh_cells, exc_cells, connector, inh_syn, receptor_type='inhibitory')
'rate': rate, 'duration': stim_dur }, label="expoisson") rconn = 0.01 ext_conn = FixedProbabilityConnector(rconn, weights=0.1) print "%s Initialising membrane potential to random values..." % node_id rng = NumpyRNG(seed=rngseed, parallel_safe=parallel_safe) uniformDistr = RandomDistribution('uniform', [v_reset, v_thresh], rng=rng) all_cells.initialize('v', uniformDistr) print "%s Connecting populations..." % node_id #exc_conn = FixedProbabilityConnector(pconn, weights=w_exc, delays=delay) #inh_conn = FixedProbabilityConnector(pconn, weights=w_inh, delays=delay) exc_conn = CSAConnector(csa.cset(csa.random(pconn), w_exc, delay)) inh_conn = CSAConnector(csa.cset(csa.random(pconn), w_inh, delay)) connections = {} connections['exc'] = Projection(exc_cells, all_cells, exc_conn, target='excitatory', rng=rng) connections['inh'] = Projection(inh_cells, all_cells, inh_conn, target='inhibitory', rng=rng) if (benchmark == "COBA"): connections['ext'] = Projection(ext_stim,
def do_run(plot): runtime = 3000 p.setup(timestep=1.0, min_delay=1.0, max_delay=144.0) nNeurons = 200 # number of neurons in each population p.set_number_of_neurons_per_core(p.IF_curr_exp, nNeurons / 10) 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 = 10 # connection list in a loop for first population loopConnections = [] for i in range(0, nNeurons): singleConnection = ((i, (i + 1) % nNeurons)) loopConnections.append(singleConnection) # injection list to set the chain going injectionConnection = [(0, 0)] spikeArray = {'spike_times': [[0]]} # list of populations populations.append( p.Population(nNeurons, p.IF_curr_exp(**cell_params_lif), label='pop_1')) populations.append( p.Population(nNeurons, p.IF_curr_exp(**cell_params_lif), label='pop_2')) populations.append( p.Population(nNeurons, p.IF_curr_exp(**cell_params_lif), label='pop_3')) populations.append( p.Population(nNeurons, p.IF_curr_exp(**cell_params_lif), label='pop_4')) populations.append( p.Population(1, p.SpikeSourceArray(**spikeArray), label='inputSpikes_1')) # Loop connector: we can just pass in the list we made earlier CSA_loop_connector = p.CSAConnector(loopConnections) # random connector: each connection has a probability of 0.05 CSA_random_connector = p.CSAConnector(csa.random(0.05)) # one-to-one connector: do I really need to explain? CSA_onetoone_connector = p.CSAConnector(csa.oneToOne) # This creates a block of size (5,10) with a probability of 0.05; then # within the block an individual connection has a probability of 0.3 csa_block_random = csa.block(15, 10) * csa.random(0.05) * csa.random(0.3) CSA_randomblock_connector = p.CSAConnector(csa_block_random) # list of projections using the connectors above projections.append( p.Projection(populations[0], populations[0], CSA_loop_connector, p.StaticSynapse(weight=weight_to_spike, delay=delay))) projections.append( p.Projection(populations[0], populations[1], CSA_random_connector, p.StaticSynapse(weight=weight_to_spike, delay=delay))) projections.append( p.Projection(populations[1], populations[2], CSA_onetoone_connector, p.StaticSynapse(weight=weight_to_spike, delay=delay))) projections.append( p.Projection(populations[2], populations[3], CSA_randomblock_connector, p.StaticSynapse(weight=weight_to_spike, delay=delay))) projections.append( p.Projection(populations[4], populations[0], p.FromListConnector(injectionConnection), p.StaticSynapse(weight=weight_to_spike, delay=1))) populations[0].record(['v', 'spikes']) populations[1].record(['v', 'spikes']) populations[2].record(['v', 'spikes']) populations[3].record(['v', 'spikes']) p.run(runtime) # get data (could be done as one, but can be done bit by bit as well) v = populations[0].spinnaker_get_data('v') v2 = populations[1].spinnaker_get_data('v') v3 = populations[2].spinnaker_get_data('v') v4 = populations[3].spinnaker_get_data('v') spikes = populations[0].spinnaker_get_data('spikes') spikes2 = populations[1].spinnaker_get_data('spikes') spikes3 = populations[2].spinnaker_get_data('spikes') spikes4 = populations[3].spinnaker_get_data('spikes') if plot: # Use the show functionality of CSA to display connection sets CSA_loop_connector.show_connection_set() CSA_random_connector.show_connection_set() CSA_onetoone_connector.show_connection_set() CSA_randomblock_connector.show_connection_set() # Now plot some spikes 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: population 1') pylab.show() pylab.figure() pylab.plot([i[1] for i in spikes3], [i[0] for i in spikes3], "g.") pylab.plot([i[1] for i in spikes4], [i[0] for i in spikes4], "r.") pylab.plot([i[1] for i in spikes2], [i[0] for i in spikes2], "b.") pylab.xlabel('Time/ms') pylab.ylabel('spikes') pylab.title('spikes: populations 2, 3, 4') pylab.show() p.end() return v, v2, v3, v4, spikes, spikes2, spikes3, spikes4
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(100, SpikeSourceArray(spike_times=spike_times), label="input") output_population = Population(10, IF_curr_exp(**cell_params), label="output") print "[%d] input_population cells: %s" % (node, input_population.local_cells) print "[%d] output_population cells: %s" % (node, output_population.local_cells) print "[%d] Connecting populations" % node timer.start() connector = CSAConnector(csa.random(0.5), weights=0.1) #connector = CSAConnector(csa.cset(csa.random(0.5), 0.123, 1.6)) projection = Projection(input_population, output_population, connector, StaticSynapse()) print connector.describe(), timer.elapsedTime() file_stem = "Results/simpleRandomNetwork_csa_np%d_%s" % (num_processes(), simulator_name) projection.save('all', '%s.conn' % file_stem) input_population.record('spikes') output_population.record('spikes') output_population.sample(n_record, rng).record('v') print "[%d] Running simulation" % node run(tstop)
def _connect(self): '''Connect populations.''' finite_set = csa.cross(xrange(self._N_s), xrange(self._N_t)) self._cs = csa.cset(csa.random(p=self._p) * finite_set)
import csa haveCSA = True except ImportError: print( "This example requires CSA to be installed in order to run.\n" + "Please make sure you compiled NEST using --with-libneurosim=PATH\n" + "and CSA and libneurosim are available from PYTHONPATH.") import sys sys.exit() """ To set up the connectivity, We create a ``random`` connection set with a probability of 0.1 and two associated values (10000.0 and 1.0) used as weight and delay, respectively. """ cs = csa.cset(csa.random(0.1), 10000.0, 1.0) """ Using the `Create` command from PyNEST, we create the neurons of the pre- and postsynaptic populations, each of which containing 16 neurons. """ pre = nest.Create("iaf_neuron", 16) post = nest.Create("iaf_neuron", 16) """ We can now connect the populations using the `CGConnect` function. It takes the IDs of pre- and postsynaptic neurons (``pre`` and ``post``), 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. """
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', {'beta': 1000.0/input_rate}, mask_local=False)) input_population = Population(100, SpikeSourceArray(spike_times=spike_times), label="input") output_population = Population(10, IF_curr_exp(**cell_params), label="output") print "[%d] input_population cells: %s" % (node, input_population.local_cells) print "[%d] output_population cells: %s" % (node, output_population.local_cells) print "[%d] Connecting populations" % node timer.start() connector = CSAConnector(csa.random(0.5)) syn = StaticSynapse(weight=0.1) projection = Projection(input_population, output_population, connector, syn) print connector.describe(), timer.elapsedTime() file_stem = "Results/simpleRandomNetwork_csa_np%d_%s" % (num_processes(), simulator_name) projection.save('all', '%s.conn' % file_stem) input_population.record('spikes') output_population.record('spikes') output_population.sample(n_record, rng).record('v') print "[%d] Running simulation" % node run(tstop)
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', {'beta': 1000.0 / input_rate}, mask_local=False)) input_population = Population(100, SpikeSourceArray(spike_times=spike_times), label="input") output_population = Population(10, IF_curr_exp(**cell_params), label="output") print("[%d] input_population cells: %s" % (node, input_population.local_cells)) print("[%d] output_population cells: %s" % (node, output_population.local_cells)) print("[%d] Connecting populations" % node) timer.start() connector = CSAConnector(csa.random(0.5)) syn = StaticSynapse(weight=0.1) projection = Projection(input_population, output_population, connector, syn) print(connector.describe(), timer.elapsedTime()) file_stem = "Results/simpleRandomNetwork_csa_np%d_%s" % (num_processes(), simulator_name) projection.save('all', '%s.conn' % file_stem) input_population.record('spikes') output_population.record('spikes') output_population.sample(n_record, rng).record('v') print("[%d] Running simulation" % node) run(tstop)
import csa haveCSA = True except ImportError: print("This example requires CSA to be installed in order to run.\n" + "Please make sure you compiled NEST using --with-libneurosim=PATH\n" + "and CSA and libneurosim are available from PYTHONPATH.") import sys sys.exit() """ To set up the connectivity, We create a ``random`` connection set with a probability of 0.1 and two associated values (10000.0 and 1.0) used as weight and delay, respectively. """ cs = csa.cset(csa.random(0.1), 10000.0, 1.0) """ Using the `Create` command from PyNEST, we create the neurons of the pre- and postsynaptic populations, each of which containing 16 neurons. """ pre = nest.Create("iaf_neuron", 16) post = nest.Create("iaf_neuron", 16) """ We can now connect the populations using the `CGConnect` function. It takes the IDs of pre- and postsynaptic neurons (``pre`` and ``post``), the connection set (``cs``) and a dictionary that maps the parameters weight and delay to positions in the value set
exc_cells = all_cells[:n_exc] inh_cells = all_cells[n_exc:] if benchmark == "COBA": ext_stim = Population(20, SpikeSourcePoisson, {'rate' : rate, 'duration' : stim_dur}, label="expoisson") rconn = 0.01 ext_conn = FixedProbabilityConnector(rconn, weights=0.1) print "%s Initialising membrane potential to random values..." % node_id rng = NumpyRNG(seed=rngseed, parallel_safe=parallel_safe) uniformDistr = RandomDistribution('uniform', [v_reset,v_thresh], rng=rng) all_cells.initialize('v', uniformDistr) print "%s Connecting populations..." % node_id #exc_conn = FixedProbabilityConnector(pconn, weights=w_exc, delays=delay) #inh_conn = FixedProbabilityConnector(pconn, weights=w_inh, delays=delay) exc_conn = CSAConnector(csa.cset (csa.random (pconn), w_exc, delay)) inh_conn = CSAConnector(csa.cset (csa.random (pconn), w_inh, delay)) connections={} connections['exc'] = Projection(exc_cells, all_cells, exc_conn, target='excitatory', rng=rng) connections['inh'] = Projection(inh_cells, all_cells, inh_conn, target='inhibitory', rng=rng) if (benchmark == "COBA"): connections['ext'] = Projection(ext_stim, all_cells, ext_conn, target='excitatory') # === Setup recording ========================================================== print "%s Setting up recording..." % node_id all_cells.record() vrecord_list = [exc_cells[0],exc_cells[1]] exc_cells.record_v(vrecord_list) buildCPUTime = timer.diff()
def _connect(self): '''Connect populations.''' finite_set = csa.cross(xrange(self._N_s), xrange(self._N_t)) cs = csa.cset(csa.random(p=self._p) * finite_set) nest.CGConnect(self._source_pop, self._target_pop, csa.cset(cs))
print("%s Initialising membrane potential to random values..." % node_id) rng = NumpyRNG(seed=rngseed, parallel_safe=parallel_safe) uniformDistr = RandomDistribution('uniform', low=v_reset, high=v_thresh, rng=rng) if options.use_views: all_cells.initialize(v=uniformDistr) else: exc_cells.initialize(v=uniformDistr) inh_cells.initialize(v=uniformDistr) print("%s Connecting populations..." % node_id) progress_bar = ProgressBar(width=20) if options.use_csa: connector = sim.CSAConnector(csa.cset(csa.random(pconn))) else: connector = sim.FixedProbabilityConnector(pconn, rng=rng, callback=progress_bar) exc_syn = sim.StaticSynapse(weight=w_exc, delay=delay) inh_syn = sim.StaticSynapse(weight=w_inh, delay=delay) connections = {} if options.use_views or options.use_assembly: connections['exc'] = sim.Projection(exc_cells, all_cells, connector, exc_syn, receptor_type='excitatory') connections['inh'] = sim.Projection(inh_cells,
ext_stim = Population(20, SpikeSourcePoisson(rate=rate, duration=stim_dur), label="expoisson") rconn = 0.01 ext_conn = FixedProbabilityConnector(rconn) syn = StaticSynapse(weight=0.1) print "%s Initialising membrane potential to random values..." % node_id rng = NumpyRNG(seed=rngseed, parallel_safe=parallel_safe) uniformDistr = RandomDistribution('uniform', low=v_reset, high=v_thresh, rng=rng) all_cells.initialize(v=uniformDistr) print "%s Connecting populations..." % node_id #exc_conn = FixedProbabilityConnector(pconn, weights=w_exc, delays=delay) #inh_conn = FixedProbabilityConnector(pconn, weights=w_inh, delays=delay) exc_syn = StaticSynapse(weight=w_exc, delay=delay) inh_syn = StaticSynapse(weight=w_inh, delay=delay) exc_conn = CSAConnector(csa.cset (csa.random (pconn))) inh_conn = CSAConnector(csa.cset (csa.random (pconn))) connections={} connections['exc'] = Projection(exc_cells, all_cells, exc_conn, exc_syn, receptor_type='excitatory') connections['inh'] = Projection(inh_cells, all_cells, inh_conn, inh_syn, receptor_type='inhibitory') if (benchmark == "COBA"): connections['ext'] = Projection(ext_stim, all_cells, ext_conn, syn, receptor_type='excitatory') # === Setup recording ========================================================== print "%s Setting up recording..." % node_id all_cells.record('spikes') exc_cells[0:2].record('v') buildCPUTime = timer.diff()
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) print "[%d] Finishing" % node