def start_simulation(self): nest.Simulate(self.parameters['Time before stimulation']) nest.SetStatus(self.stim2_i, {'rate': self.parameters['Stimulus rate']}) nest.Simulate(self.parameters['Time of stimulation']) nest.SetStatus(self.stim2_i, {'rate': 0.0}) nest.Simulate(self.parameters['Time after Stimulation']) rec_ex_true = nest.GetLeaves(self.rec_ex, local_only=True)[0] rec_in_true = nest.GetLeaves(self.rec_in, local_only=True)[0] self.events_ex = nest.GetStatus(rec_ex_true, "events")[0] self.events_in = nest.GetStatus(rec_in_true, "events")[0] # self.events_ex = nest.GetStatus(self.rec_ex, "events")[0] # self.events_in = nest.GetStatus(self.rec_in, "events")[0] self.df_ex = makePandas(self.events_ex, tp.FindCenterElement(self.l)[0]) self.df_in = makePandas(self.events_in, tp.FindCenterElement(self.l)[0])
def test_GetCenterElement(self): """Interface and result check for finding center element. This function is Py only, so we also need to check results.""" # nodes at [-1,0,1]x[-1,0,1], column-wise ldict = {'elements': 'iaf_psc_alpha', 'rows': 3, 'columns': 3, 'extent': (2., 2.)} nest.ResetKernel() l = topo.CreateLayer(ldict) # single layer n = topo.FindCenterElement(l) self.assertEqual(n, (6,)) # two layers n = topo.FindCenterElement(l * 2) self.assertEqual(n, (6,) * 2)
def _build(self): '''Create populations.''' ldict_s = { 'elements': 'iaf_neuron', 'positions': [[0.] * self._dimensions], 'extent': [self._L] * self._dimensions, 'edge_wrap': True } x = rnd.uniform(-self._L / 2., self._L / 2., self._N) y = rnd.uniform(-self._L / 2., self._L / 2., self._N) if self._dimensions == 3: z = rnd.uniform(-self._L / 2., self._L / 2., self._N) pos = zip(x, y, z) else: pos = zip(x, y) ldict_t = { 'elements': 'iaf_neuron', 'positions': pos, 'extent': [self._L] * self._dimensions, 'edge_wrap': True } self._ls = topo.CreateLayer(ldict_s) self._lt = topo.CreateLayer(ldict_t) self._driver = topo.FindCenterElement(self._ls)
def test_PlotTargets(self): """Test plotting targets.""" ldict = {'elements': ['iaf_neuron', 'iaf_psc_alpha'], 'rows': 3, 'columns': 3, 'extent': [2., 2.], 'edge_wrap': True} cdict = {'connection_type': 'divergent', 'mask': {'grid': {'rows': 2, 'columns': 2}}} nest.ResetKernel() l = topo.CreateLayer(ldict) ian = [gid for gid in nest.GetLeaves(l)[0] if nest.GetStatus([gid], 'model')[0] == 'iaf_neuron'] ipa = [gid for gid in nest.GetLeaves(l)[0] if nest.GetStatus([gid], 'model')[0] == 'iaf_psc_alpha'] # connect ian -> all using static_synapse cdict.update({'sources': {'model': 'iaf_neuron'}, 'synapse_model': 'static_synapse'}) topo.ConnectLayers(l, l, cdict) for k in ['sources', 'synapse_model']: cdict.pop(k) # connect ipa -> ipa using stdp_synapse cdict.update({'sources': {'model': 'iaf_psc_alpha'}, 'targets': {'model': 'iaf_psc_alpha'}, 'synapse_model': 'stdp_synapse'}) topo.ConnectLayers(l, l, cdict) for k in ['sources', 'targets', 'synapse_model']: cdict.pop(k) ctr = topo.FindCenterElement(l) fig = topo.PlotTargets(ctr, l) fig.gca().set_title('Plain call') self.assertTrue(True)
def distancePlotsLazy(Start, End, Step, network, folder): for events, title, neurons_folder in zip([network.events_ex, network.events_in], ["Excitatory", "Inhibitory"], ['/excitatory_neurons', '/inhibitory_neurons']): for start, end in zip(np.arange(Start, End, Step), np.arange(Start + Step, End + Step, Step)): plt.close() currentTitle = title + 'Neurons from ' + str(start) + ' to ' + str(end) print(currentTitle) times, neurons = magic.distance(events, start, end, tp.FindCenterElement(network.l)[0]) magic.raster_plot(senders=times, timeS=neurons, title=currentTitle, gridSize=network.gridSize) plt.savefig(folder + neurons_folder + '/dist_' + str(end) + '_raster_' + title + '.png', dpi=300)
def plot_layer_targets(cds, savename): layer = topo.CreateLayer(layer_dict) for cd in cds: topo.ConnectLayers(layer, layer, cd) ctr = topo.FindCenterElement(layer) fig = topo.PlotLayer(layer, nodesize=20) topo.PlotTargets(ctr, layer, fig=fig, tgt_color="red") plt.savefig("%s.png" % savename) plt.close()
def plot_layer_targets(cds, savename): nest.ResetKernel() layer = topp.CreateLayer({"rows":rowcol, "columns":rowcol, "extent":extent, "elements":model}) for cd in cds: topp.ConnectLayers(layer, layer, cd) ctr = topp.FindCenterElement(layer) fig = topp.PlotLayer(layer, nodesize=20) topp.PlotTargets(ctr,layer, fig=fig, tgt_color="red") pylab.savefig("%s.png"%savename) pylab.close()
def plotKernel(self, folder): fig, ax = plt.subplots() tp.PlotLayer(self.l, fig, nodesize=10) ctr_elem = tp.FindCenterElement(self.l) # import ipdb; ipdb.set_trace() # tp.PlotKernel(ax, ctr_elem, mask=self.cdict_i2i['mask'], kern=self.cdict_i2i['kernel']) tp.PlotTargets(ctr_elem, self.l, fig=fig, tgt_color='red', mask=self.cdict_e2e['mask'], kernel=self.cdict_e2e['kernel'], kernel_color='green', mask_color='green', syn_type='exc_recurrent') # tp.PlotKernel(ax, ctr_elem, mask=self.cdict_e2e['mask'], mask_color='green') plt.xlabel(r'X') plt.ylabel(r'Y') plt.xlim(-.5, .5) plt.ylim(-.5, .5) plt.savefig(folder+'/kernel.pdf')
def plot_layer_targets(cds, savename): nest.ResetKernel() layer = topp.CreateLayer({ 'rows': rowcol, 'columns': rowcol, 'extent': extent, 'elements': model }) for cd in cds: topp.ConnectLayers(layer, layer, cd) ctr = topp.FindCenterElement(layer) fig = topp.PlotLayer(layer, nodesize=20) topp.PlotTargets(ctr, layer, fig=fig, tgt_color='red') pylab.savefig('%s.png' % savename) pylab.close()
def get_Relative_Weight(params, radius): # Create a fictional network and count the number of target connections layerProps = { 'rows': params['N'], 'columns': params['N'], 'extent': [params['visSize'], params['visSize']], 'edge_wrap': True, 'elements': 'iaf_cond_exp' } l = tp.CreateLayer(layerProps) dict = { "connection_type": "convergent", "mask": { "circular": { "radius": radius } }, "kernel": 1.0, "weights": { "gaussian": { "p_center": 1.0, "sigma": radius / 3.0 } } } tp.ConnectLayers(l, l, dict) ctr = tp.FindCenterElement(l) targets = tp.GetTargetNodes(ctr, l) # print ("Number of targets = ",len(targets[0])) conn = nest.GetConnections(ctr, targets[0]) st = nest.GetStatus(conn) w = 0.0 for n in np.arange(len(st)): w += st[n]['weight'] # print ("Total weight = ",w) return w, len(targets[0])
def plot_connections(layer_dict, conn_dict, file_name): conn_dict['synapse_model'] = 'static_synapse' layer = tp.CreateLayer(layer_dict) tp.ConnectLayers(layer, layer, conn_dict) fig = tp.PlotLayer(layer) tp.PlotTargets(tp.FindCenterElement(layer), layer, fig=fig, tgt_color='red') pylab.savefig(file_name) #pylab.show() tp.DumpLayerConnections(layer, conn_dict['synapse_model'], file_name + ".dump") positions = tp.GetTargetPositions(layer, layer)
def _build(self): '''Create populations.''' if self._open_bc: ldict_s = { 'elements': 'iaf_psc_alpha', 'positions': [[self._x_d, self._y_d]], 'extent': [self._L] * self._dimensions, 'edge_wrap': False } x = rnd.uniform(-self._L / 2., self._L / 2., self._N) y = rnd.uniform(-self._L / 2., self._L / 2., self._N) pos = list(zip(x, y)) ldict_t = { 'elements': 'iaf_psc_alpha', 'positions': pos, 'extent': [self._L] * self._dimensions, 'edge_wrap': False } self._ls = topo.CreateLayer(ldict_s) self._lt = topo.CreateLayer(ldict_t) self._driver = nest.GetLeaves(self._ls)[0] else: ldict_s = { 'elements': 'iaf_psc_alpha', 'positions': [[0.] * self._dimensions], 'extent': [self._L] * self._dimensions, 'edge_wrap': True } x = rnd.uniform(-self._L / 2., self._L / 2., self._N) y = rnd.uniform(-self._L / 2., self._L / 2., self._N) if self._dimensions == 3: z = rnd.uniform(-self._L / 2., self._L / 2., self._N) pos = list(zip(x, y, z)) else: pos = list(zip(x, y)) ldict_t = { 'elements': 'iaf_psc_alpha', 'positions': pos, 'extent': [self._L] * self._dimensions, 'edge_wrap': True } self._ls = topo.CreateLayer(ldict_s) self._lt = topo.CreateLayer(ldict_t) self._driver = topo.FindCenterElement(self._ls)
def conn_figure(fig, layer, connd, targets=None, showmask=True, showkern=False, xticks=range(-5, 6), yticks=range(-5, 6), xlim=[-5.5, 5.5], ylim=[-5.5, 5.5]): if targets is None: targets = ((tp.FindCenterElement(layer), 'red'), ) tp.PlotLayer(layer, fig=fig, nodesize=60) for src, clr in targets: if showmask: mask = connd['mask'] else: mask = None if showkern: kern = connd['kernel'] else: kern = None tp.PlotTargets(src, layer, fig=fig, mask=mask, kernel=kern, src_size=250, tgt_color=clr, tgt_size=20, kernel_color='green') beautify_layer(layer, fig, xlim=xlim, ylim=ylim, xticks=xticks, yticks=yticks, xlabel='', ylabel='') fig.gca().grid(False)
def _build(self): '''Create populations.''' ldict_s = { 'elements': 'iaf_neuron', 'positions': [(0., 0.)], 'extent': [self._L] * 2, 'edge_wrap': True } x = rnd.uniform(-self._L / 2., self._L / 2., self._N) y = rnd.uniform(-self._L / 2., self._L / 2., self._N) ldict_t = { 'elements': 'iaf_neuron', 'positions': zip(x, y), 'extent': [self._L] * 2, 'edge_wrap': True } self._ls = topo.CreateLayer(ldict_s) self._lt = topo.CreateLayer(ldict_t) self._driver = topo.FindCenterElement(self._ls)
def test_PlotKernel(self): """Test plotting kernels.""" ldict = {'elements': 'iaf_neuron', 'rows': 3, 'columns': 3, 'extent': [2., 2.], 'edge_wrap': True} nest.ResetKernel() l = topo.CreateLayer(ldict) f = plt.figure() a1 = f.add_subplot(221) ctr = topo.FindCenterElement(l) topo.PlotKernel(a1, ctr, {'circular': {'radius': 1.}}, {'gaussian': {'sigma': 0.2}}) a2 = f.add_subplot(222) topo.PlotKernel(a2, ctr, { 'doughnut': {'inner_radius': 0.5, 'outer_radius': 0.75}}) a3 = f.add_subplot(223) topo.PlotKernel(a3, ctr, {'rectangular': {'lower_left': [-.5, -.5], 'upper_right': [0.5, 0.5]}}) self.assertTrue(True)
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)
def conn_figure_3d(fig, layer, connd, targets=None, showmask=True, showkern=False, xticks=range(-5, 6), yticks=range(-5, 6), xlim=[-5.5, 5.5], ylim=[-5.5, 5.5]): if targets is None: targets = ((tp.FindCenterElement(layer), 'red'), ) tp.PlotLayer(layer, fig=fig, nodesize=20, nodecolor=(.5, .5, 1.)) for src, clr in targets: if showmask: mask = connd['mask'] else: mask = None if showkern: kern = connd['kernel'] else: kern = None tp.PlotTargets(src, layer, fig=fig, mask=mask, kernel=kern, src_size=250, tgt_color=clr, tgt_size=60, kernel_color='green') ax = fig.gca() ax.set_aspect('equal', 'box') plt.draw()
}, { "targets": { "model": "TpInter" } }]: retThal.update(conn) topo.ConnectLayers(retina, Tp, retThal) #! Checks on connections #! --------------------- #! As a very simple check on the connections created, we inspect #! the connections from the central node of various layers. #! Connections from Retina to TpRelay topo.PlotTargets(topo.FindCenterElement(retina), Tp, 'TpRelay', 'AMPA') pylab.title('Connections Retina -> TpRelay') pylab.show() #! Connections from TpRelay to L4pyr in Vp (horizontally tuned) topo.PlotTargets(topo.FindCenterElement(Tp), Vp_h, 'L4pyr', 'AMPA') pylab.title('Connections TpRelay -> Vp(h) L4pyr') pylab.show() #! Connections from TpRelay to L4pyr in Vp (vertically tuned) topo.PlotTargets(topo.FindCenterElement(Tp), Vp_v, 'L4pyr', 'AMPA') pylab.title('Connections TpRelay -> Vp(v) L4pyr') pylab.show() #! Recording devices #! =================
# l1_children is a work-around until NEST 3.0 is released l1_children = nest.hl_api.GetChildren(l1)[0] # extract position information, transpose to list of x, y and z positions xpos, ypos, zpos = zip(*topo.GetPosition(l1_children)) fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.scatter(xpos, ypos, zpos, s=15, facecolor='b', edgecolor='none') # Gaussian connections in full volume [-0.75,0.75]**3 topo.ConnectLayers(l1, l1, {'connection_type': 'divergent', 'allow_autapses': False, 'mask': {'volume': {'lower_left': [-0.75, -0.75, -0.75], 'upper_right': [0.75, 0.75, 0.75]}}, 'kernel': {'gaussian': {'p_center': 1., 'sigma': 0.25}}}) # show connections from center element # sender shown in red, targets in green ctr = topo.FindCenterElement(l1) xtgt, ytgt, ztgt = zip(*topo.GetTargetPositions(ctr, l1)[0]) xctr, yctr, zctr = topo.GetPosition(ctr)[0] ax.scatter([xctr], [yctr], [zctr], s=40, facecolor='r', edgecolor='none') ax.scatter(xtgt, ytgt, ztgt, s=40, facecolor='g', edgecolor='g') tgts = topo.GetTargetNodes(ctr, l1)[0] d = topo.Distance(ctr, tgts) plt.figure() plt.hist(d, 25) # plt.show()
'mask': { 'rectangular': { 'lower_left': [-2., -1.], 'upper_right': [2., 1.] } } } tp.ConnectLayers(l, l, conndict) # { end #} fig = plt.figure() fig.add_subplot(121) conn_figure(fig, l, conndict, targets=((tp.FindCenterElement(l), 'red'), (tp.FindNearestElement(l, [4., 5.]), 'yellow'))) # same another time, with periodic bcs lpbc = tp.CreateLayer({ 'rows': 11, 'columns': 11, 'extent': [11., 11.], 'elements': 'iaf_neuron', 'edge_wrap': True }) tp.ConnectLayers(lpbc, lpbc, conndict) fig.add_subplot(122) conn_figure(fig, lpbc, conndict,
# { vislayer #} l = tp.CreateLayer({'rows': 21, 'columns': 21, 'elements': 'iaf_neuron'}) conndict = { 'connection_type': 'divergent', 'mask': { 'circular': { 'radius': 0.4 } }, 'kernel': { 'gaussian': { 'p_center': 1.0, 'sigma': 0.15 } } } tp.ConnectLayers(l, l, conndict) fig = tp.PlotLayer(l, nodesize=80) ctr = tp.FindCenterElement(l) tp.PlotTargets(ctr, l, fig=fig, mask=conndict['mask'], kernel=conndict['kernel'], src_size=250, tgt_color='red', tgt_size=20, kernel_color='green') # { end #} plt.savefig('../user_manual_figures/vislayer.png', bbox_inches='tight')
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. """ # This is a work-around until NEST 3.0 is released. It will issue a deprecation # warning. pop1_gids = nest.GetLeaves(pop1)[0] pop2_gids = nest.GetLeaves(pop2)[0] nest.CGConnect(pop1_gids, pop2_gids, cs, {"weight": 0, "delay": 1}) """ Finally, we use the `PlotTargets` function to show all targets in ``pop2`` starting at the center neuron of ``pop1``. """ topo.PlotTargets(topo.FindCenterElement(pop1), pop2)
nest.Connect(Neuron_GIDs, sd_list[-1]) multimeter_exc.append( nest.Create("multimeter", params={ "interval": 0.1, "record_from": ["V_m", "g_ex", "g_in"], "withgid": True, "to_file": True, "label": "mm_vLSPS_postsynaptic_cell_%s_%s" % (vS1_Layer_Name[l], n_type) })) print(ntop.FindCenterElement(SubSubRegion_Excitatory[-1])) nest.Connect(multimeter_exc[-1], ntop.FindCenterElement(SubSubRegion_Excitatory[-1])) elif n_type_info['EorI'] == "I": pos = None pos = Neuron_pos[np.where(Neuron_pos[:, :, :, 3] == n_type_index)] nest.SetDefaults( elements, { "I_e": float(neuron_info['I_ex']), "V_th": float(neuron_info['spike_threshold']), "V_reset": float(neuron_info['reset_value']), "t_ref": float(neuron_info['absolute_refractory_period']) }) newlayer = CreateSubSubRegion(topo_extend, topo_center, pos, neuronmodel) SubSubRegion_Inhibitory.append(newlayer)