Changeset 427
- Timestamp:
- 07/27/08 18:22:35 (3 weeks ago)
- Files:
-
- trunk/src/brian/__init__.py (modified) (15 diffs)
- trunk/src/brian/cells.py (modified) (4 diffs)
- trunk/src/brian/connectors.py (modified) (3 diffs)
- trunk/src/brian/synapses.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/brian/__init__.py
r414 r427 36 36 int.__init__(n) 37 37 common.IDMixin.__init__(self) 38 39 def __getattr__(self, name): 40 try: 41 val = float(self.parent.brian_cells[int(self)].__getattr__(name)) 42 except KeyError: 43 raise NonExistentParameterError(name, self.cellclass) 44 return val 45 46 def set_native_parameters(self, parameters): 47 for key, value in parameters.items(): 48 self.parent.brian_cells[int(self)].__setattr__(key,value) 49 50 38 51 39 52 def list_standard_models(): … … 78 91 min_delay = 0.001*min_delay 79 92 max_delay = 0.001*max_delay 80 net = brian.Network()81 simclock = brian.Clock(dt=timestep)93 net = brian.Network() 94 simclock = brian.Clock(dt=timestep) 82 95 return 0 83 96 … … 225 238 if isinstance(self.celltype,SpikeSourcePoisson): 226 239 rate = self.cellparams['rate'] 227 self.cell = brian.PoissonGroup(self.size, rates = rate, clock=simclock) 240 fct = self.celltype.fct 241 self.brian_cells = brian.PoissonGroup(self.size, rates = fct, clock=simclock) 228 242 else: 229 243 v_thresh = self.cellparams['v_thresh'] 230 244 v_reset = self.cellparams['v_reset'] 231 245 tau_refrac = self.cellparams['tau_refrac'] 232 self. cell = brian.NeuronGroup(self.size,model=cellclass.eqs,threshold=v_thresh,reset=v_reset, refractory=tau_refrac, clock=simclock)246 self.brian_cells = brian.NeuronGroup(self.size,model=cellclass.eqs,threshold=v_thresh,reset=v_reset, refractory=tau_refrac, clock=simclock, compile=True) 233 247 234 248 elif isinstance(cellclass, str): 235 self.cell = brian.NeuronGroup(self.size,model=cellclass.eqs,threshold=v_thresh,reset=v_reset, clock=simclock) 249 v_thresh = self.cellparams['v_thresh'] 250 v_reset = self.cellparams['v_reset'] 251 tau_refrac = self.cellparams['tau_refrac'] 252 self.brian_cells = brian.NeuronGroup(self.size,model=cellclass,threshold=v_thresh,reset=v_reset, clock=simclock) 236 253 self.cellparams = self.celltype.parameters 237 254 238 u nchangeable_params=['v_thresh','v_reset','tau_refrac']255 useless_params=['v_thresh','v_reset','tau_refrac','cm'] 239 256 if self.cellparams: 240 257 for key, value in self.cellparams.items(): 241 258 if not key in unchangeable_params: 242 setattr(self.cell,key,value) 243 self.cell_id = numpy.arange(len(self.cell)) 244 self.cell_id = numpy.reshape(self.cell_id, self.dim) 259 setattr(self.brian_cells,key,value) 260 self.cell = numpy.array([ID(cell) for cell in xrange(len(self.brian_cells))],ID) 261 for id in self.cell: 262 id.parent = self 263 self.cell = numpy.reshape(self.cell, self.dim) 245 264 self.spike_recorder = None 246 265 self.vm_recorder = None 266 self.ce_recorder = None 267 self.ci_recorder = None 268 self.first_id = 0 247 269 248 270 if not self.label: 249 271 self.label = 'population%d' % Population.nPop 250 272 Population.nPop += 1 251 net.add(self. cell)273 net.add(self.brian_cells) 252 274 253 275 def __getitem__(self, addr): … … 261 283 addr = (addr,) 262 284 if len(addr) == self.ndim: 263 id = self.cell _id[addr]285 id = self.cell[addr] 264 286 else: 265 287 raise common.InvalidDimensionsError, "Population has %d dimensions. Address was %s" % (self.ndim, str(addr)) 266 288 if addr != self.locate(id): 267 289 raise IndexError, 'Invalid cell address %s' % str(addr) 268 return self.cell[id]290 return id 269 291 270 292 def __iter__(self): … … 322 344 Get the values of a parameter for every cell in the population. 323 345 """ 324 values = getattr(self. cell, parameter_name)346 values = getattr(self.brian_cells, parameter_name) 325 347 if as_array: 326 348 values = numpy.array(values) … … 346 368 raise common.InvalidParameterValueError 347 369 for key, value in para_dict.items(): 348 setattr(self. cell, key, value)370 setattr(self.brian_cells, key, value) 349 371 350 372 … … 385 407 else: 386 408 rarr = rand_distr.next(n=self.size) 387 assert len(rarr) == len(self. cell_id)388 setattr(self. cell, parametername, rarr)409 assert len(rarr) == len(self.brian_cells) 410 setattr(self.brian_cells, parametername, rarr) 389 411 390 412 def _call(self, methodname, arguments): … … 399 421 """ 400 422 `Topographic' call. Calls the method methodname() for every cell in the 401 population. The argument to the method depends on the coordinates of the423 population. The argument to the method depends on the coordinates of the 402 424 cell. objarr is an array with the same dimensions as the Population. 403 425 e.g. p.tcall("memb_init", vinitArray) calls … … 421 443 N = record_from 422 444 print "Warning: Brian can record only the %d first cells of the population" %N 423 self.spike_recorder = brian.SpikeMonitor(self. cell[0:N],True)424 else: 425 self.spike_recorder = brian.SpikeMonitor(self. cell,True)445 self.spike_recorder = brian.SpikeMonitor(self.brian_cells[0:N],True) 446 else: 447 self.spike_recorder = brian.SpikeMonitor(self.brian_cells,True) 426 448 net.add(self.spike_recorder) 427 449 … … 436 458 global net 437 459 if record_from: 438 if isinstance(record_from,list):439 N = len(record_from)440 460 if isinstance(record_from,int): 441 461 N = record_from 442 print "Warning: Brian can record only the %d first cells of the population" %N443 self.vm_recorder = brian.StateMonitor(self. cell[0:N],'v',record=True)444 else: 445 self.vm_recorder = brian.StateMonitor(self. cell,'v',record=True)462 record_from = numpy.random.permutation(self.cell.flatten()[0:N]) 463 self.vm_recorder = brian.StateMonitor(self.brian_cells,'v',record=record_from) 464 else: 465 self.vm_recorder = brian.StateMonitor(self.brian_cells,'v',record=True) 446 466 net.add(self.vm_recorder) 467 468 def record_c(self, record_from=None, rng=None, to_file=True): 469 """ 470 If record_from is not given, record the conductances/currents for all cells in 471 the Population. 472 record_from can be an integer - the number of cells to record from, chosen 473 at random (in this case a random number generator can also be supplied) 474 - or a list containing the ids of the cells to record. 475 """ 476 global net 477 if record_from: 478 if isinstance(record_from,int): 479 N = record_from 480 record_from = numpy.random.permutation(self.cell.flatten()[0:N]) 481 self.ce_recorder = brian.StateMonitor(self.brian_cells,'ge',record=record_from) 482 self.ci_recorder = brian.StateMonitor(self.brian_cells,'gi',record=record_from) 483 else: 484 self.ce_recorder = brian.StateMonitor(self.brian_cells,'ge',record=True) 485 self.ci_recorder = brian.StateMonitor(self.brian_cells,'gi',record=True) 486 net.add(self.ce_recorder) 487 net.add(self.ci_recorder) 447 488 448 489 def printSpikes(self, filename, gather=True, compatible_output=True): … … 471 512 f = open(filename,"w", DEFAULT_BUFFER_SIZE) 472 513 f.write("# dimensions =" + "\t".join([str(d) for d in self.dim]) + "\n") 514 f.write("# first_id = %d\n" % self.first_id) 515 f.write("# last_id = %d\n" % (self.first_id+len(self)-1,)) 473 516 f.write("# dt = %g\n" % dt) 474 for item in self.spike_recorder.spikes: 475 f.write("%g\t%d\n" %(1000*item[1], item[0])) 517 spikes = numpy.array(self.spike_recorder.spikes) 518 spikes[:,1]=1000*spikes[:,1] 519 for item in spikes: 520 f.write("%g\t%d\n" %(item[1], item[0])) 476 521 f.close() 477 522 … … 490 535 """ 491 536 # gather is not relevant, but is needed for API consistency 492 return float(self.spike_recorder.nspikes)/len(self.cell) 537 538 # TO DO : add a recordede list otherwise wrong 539 540 return float(self.spike_recorder.nspikes)/len(self) 493 541 494 542 def randomInit(self, rand_distr): … … 497 545 random values. 498 546 """ 499 self.rset('v _init', rand_distr)547 self.rset('v', rand_distr) 500 548 501 549 … … 524 572 N = len(self.vm_recorder[0]) 525 573 f.write("# dimensions =" + "\t".join([str(d) for d in self.dim]) + "\n") 574 f.write("# first_id = %d\n" % self.first_id) 575 f.write("# last_id = %d\n" % (self.first_id+len(self)-1,)) 526 576 f.write("# dt = %g\n" % dt) 527 577 f.write("# n = %d\n" % N) 528 578 cells = self.vm_recorder.get_record_indices() 529 579 for cell in cells: 580 vm = 1000*self.vm_recorder[cell] 530 581 for idx in xrange(N): 531 f.write("%g\t%g\n" %( self.vm_recorder[cell][idx]*1000.,cell))582 f.write("%g\t%g\n" %(vm[idx],cell)) 532 583 f.close() 533 pass534 584 535 585 … … 546 596 547 597 source - string specifying which attribute of the presynaptic cell 548 signals action potentials 598 signals action potentialss 549 599 550 600 target - string specifying which synapse on the postsynaptic cell to trunk/src/brian/cells.py
r317 r427 14 14 shaped post-synaptic current.""" 15 15 translations = common.build_translations( 16 ('v_rest', 'v_rest', mV), 17 ('v_reset', 'v_reset', mV), 18 ('cm', 'cm'), # C is in pF, cm in nF 19 ('tau_m', 'tau_m', ms), 20 ('tau_refrac', 'tau_refrac',"max(get_time_step(), tau_refrac*0.001)", "tau_refrac"), 21 ('tau_syn_E', 'tau_syn_E', ms), 22 ('tau_syn_I', 'tau_syn_I', ms), 23 ('v_thresh', 'v_thresh', mV), 24 ('i_offset', 'i_offset', pA), # I0 is in pA, i_offset in nA 25 ('v_init', 'v', mV), 26 ) 27 eqs= brian.Equations(''' 28 dv/dt = (ge + gi + (v_rest-v))/tau_m : volt 29 dge/dt = (ye-ge)/tau_syn_E : 1 30 dye/dt = -ye/tau_syn_E : 1 31 dgi/dt = (yi-gi)/tau_syn_I : 1 32 dyi/dt = -yi/tau_syn_I : 1 33 tau_syn_E : second 34 tau_syn_I : second 35 tau_m : second 36 v_rest : volt 37 ''' 38 ) 39 40 41 class IF_curr_exp(common.IF_curr_exp): 42 """Leaky integrate and fire model with fixed threshold and 43 decaying-exponential post-synaptic current. (Separate synaptic currents for 44 excitatory and inhibitory synapses.""" 45 46 translations = common.build_translations( 16 47 ('v_rest', 'v_rest', 0.001), 17 48 ('v_reset', 'v_reset', 0.001), 18 49 ('cm', 'cm'), # C is in pF, cm in nF 19 50 ('tau_m', 'tau_m', 0.001), 20 ('tau_refrac', 'tau_refrac', "max(get_time_step(), tau_refrac)", "tau_refrac"),51 ('tau_refrac', 'tau_refrac',"max(get_time_step(), tau_refrac*0.001)", "tau_refrac"), 21 52 ('tau_syn_E', 'tau_syn_E', 0.001), 22 53 ('tau_syn_I', 'tau_syn_I', 0.001), … … 26 57 ) 27 58 eqs= brian.Equations(''' 28 dv/dt = (ge + gi-(v-v_rest))/tau_m : volt 29 dge/dt = (y-ge)/tau_syn_E : volt 30 dy/dt = -y/tau_syn_E : volt 31 dgi/dt = (y-gi)/tau_syn_I : volt 32 dy/dt = -y/tau_syn_I : volt 33 tau_syn_E : second 34 tau_syn_I : second 35 tau_m : second 36 v_rest : volt 37 ''' 38 ) 39 40 41 class IF_curr_exp(common.IF_curr_exp): 42 """Leaky integrate and fire model with fixed threshold and 43 decaying-exponential post-synaptic current. (Separate synaptic currents for 44 excitatory and inhibitory synapses.""" 45 46 translations = common.build_translations( 47 ('v_rest', 'v_rest', 0.001), 48 ('v_reset', 'v_reset', 0.001), 49 ('cm', 'cm'), # C is in pF, cm in nF 50 ('tau_m', 'tau_m', 0.001), 51 ('tau_refrac', 'tau_refrac', "max(get_time_step(), tau_refrac)*0.001", "tau_refrac"), 52 ('tau_syn_E', 'tau_syn_E', 0.001), 53 ('tau_syn_I', 'tau_syn_I', 0.001), 54 ('v_thresh', 'v_thresh', 0.001), 55 ('i_offset', 'i_offset'), # I0 is in pA, i_offset in nA 56 ('v_init', 'v', 0.001), 57 ) 58 eqs= brian.Equations(''' 59 dv/dt = (ge + gi-(v-v_rest))/tau_m : volt 60 dge/dt = -ge/tau_syn_E : volt 61 dgi/dt = -gi/tau_syn_I : volt 62 tau_syn_E : second 63 tau_syn_I : second 64 tau_m : second 65 v_rest : volt 66 ''' 67 ) 68 59 dv/dt = (ge + gi + (v_rest-v))/tau_m : volt 60 dge/dt = -ge/tau_syn_E : 1 61 dgi/dt = -gi/tau_syn_I : 1 62 tau_syn_E : second 63 tau_syn_I : second 64 tau_m : second 65 v_rest : volt 66 ''' 67 ) 69 68 70 69 71 70 class IF_cond_alpha(common.ModelNotAvailable): 72 pass 71 translations = common.build_translations( 72 ('v_rest', 'v_rest',0.001) , 73 ('v_reset', 'v_reset',0.001), 74 ('cm', 'cm'), # C_m is in pF, cm in nF 75 ('tau_m', 'tau_m',0.001), 76 ('tau_refrac', 'tau_refrac',"max(get_time_step(), tau_refrac*0.001)", "tau_refrac"), 77 ('tau_syn_E', 'tau_syn_E',0.001), 78 ('tau_syn_I', 'tau_syn_I',0.001), 79 ('v_thresh', 'v_thresh',0.001), 80 ('i_offset', 'i_offset',0.001), # I_e is in pA, i_offset in nA 81 ('e_rev_E', 'e_rev_E',0.001), 82 ('e_rev_I', 'e_rev_I',0.001), 83 ('v_init', 'v',0.001), 84 ) 85 eqs= brian.Equations(''' 86 dv/dt = ((v_rest-v) + ge*(e_rev_E-v) + gi*(e_rev_I-v))/tau_m : volt 87 dge/dt = ye-ge/tau_syn_E : 1 88 dye/dt = -ye/tau_syn_E : 1 89 dgi/dt = yi-gi/tau_syn_I : 1 90 dyi/dt = -yi/tau_syn_I : 1 91 tau_syn_E : second 92 tau_syn_I : second 93 tau_m : second 94 v_rest : volt 95 e_rev_E : volt 96 e_rev_I : volt 97 ''' 98 ) 73 99 74 100 … … 76 102 """Leaky integrate and fire model with fixed threshold and 77 103 exponentially-decaying post-synaptic conductance.""" 78 pass 79 104 translations = common.build_translations( 105 ('v_rest', 'v_rest',0.001) , 106 ('v_reset', 'v_reset',0.001), 107 ('cm', 'cm'), # C_m is in pF, cm in nF 108 ('tau_m', 'tau_m',0.001), 109 ('tau_refrac', 'tau_refrac',"max(get_time_step(), tau_refrac*0.001)", "tau_refrac"), 110 ('tau_syn_E', 'tau_syn_E',0.001), 111 ('tau_syn_I', 'tau_syn_I',0.001), 112 ('v_thresh', 'v_thresh',0.001), 113 ('i_offset', 'i_offset',0.001), # I_e is in pA, i_offset in nA 114 ('e_rev_E', 'e_rev_E',0.001), 115 ('e_rev_I', 'e_rev_I',0.001), 116 ('v_init', 'v',0.001), 117 ) 118 eqs= brian.Equations(''' 119 dv/dt = ((v_rest-v) + ge*(e_rev_E-v) + gi*(e_rev_I-v))/tau_m : volt 120 dge/dt = -ge/tau_syn_E : 1 121 dgi/dt = -gi/tau_syn_I : 1 122 tau_syn_E : second 123 tau_syn_I : second 124 tau_m : second 125 v_rest : volt 126 e_rev_E : volt 127 e_rev_I : volt 128 ''' 129 ) 80 130 81 131 class IF_facets_hardware1(common.IF_facets_hardware1): … … 92 142 translations = common.build_translations( 93 143 ('rate', 'rate'), 94 ('start', 'start'), 95 ('duration', 'duration'), 96 ) 144 ('start', 'start', 0.001), 145 ('duration', 'duration', 0.001), 146 ) 147 148 def __init__(self, parameters): 149 common.SpikeSourcePoisson.__init__(self, parameters) 150 start = self.parameters['start'] 151 duration = self.parameters['duration'] 152 rate = self.parameters['rate'] 153 self.fct = lambda t: (start <= t <= start + duration and rate) 97 154 98 155 class SpikeSourceArray(common.SpikeSourceArray): 99 156 """Spike source generating spikes at the times given in the spike_times array.""" 100 pass 101 102 157 158 103 159 class EIF_cond_alpha_isfa_ista(common.ModelNotAvailable): 104 160 pass 105 161 106 class HH_cond_exp(common.ModelNotAvailable): 107 pass 162 class HH_cond_exp(common.HH_cond_exp): 163 164 translations = common.build_translations( 165 ('gbar_Na', 'gbar_Na'), 166 ('gbar_K', 'gbar_K'), 167 ('g_leak', 'g_leak'), 168 ('cm', 'cm'), 169 ('v_offset', 'v_offset'), 170 ('e_rev_Na', 'e_rev_Na'), 171 ('e_rev_K', 'e_rev_K'), 172 ('e_rev_leak', 'e_rev_leak'), 173 ('e_rev_E', 'e_rev_E'), 174 ('e_rev_I', 'e_rev_I'), 175 ('tau_syn_E', 'tau_syn_E'), 176 ('tau_syn_I', 'tau_syn_I'), 177 ('i_offset', 'i_offset'), 178 ('v_init', 'v'), 179 ) 180 181 eqs= brian.Equations(''' 182 dv/dt = (g_leak*(e_rev_leak-v)+ge*(e_rev_E-v)+gi*(e_rev_I-v)-gbar_Na*(m*m*m)*h*(v-e_rev_Na)-gbar_K*(n*n*n*n)*(v-e_rev_K))/cm : volt 183 dm/dt = alpham*(1-m)-betam*m : 1 184 dn/dt = alphan*(1-n)-betan*n : 1 185 dh/dt = alphah*(1-h)-betah*h : 1 186 dge/dt = -ge/tau_syn_E : siemens 187 dgi/dt = -gi/tau_syn_I : siemens 188 alpham = 0.32*(mV**-1)*(13*mV-v+VT)/(exp((13*mV-v+VT)/(4*mV))-1.)/ms : Hz 189 betam = 0.28*(mV**-1)*(v-VT-40*mV)/(exp((v-VT-40*mV)/(5*mV))-1)/ms : Hz 190 alphah = 0.128*exp((17*mV-v+VT)/(18*mV))/ms : Hz 191 betah = 4./(1+exp((40*mV-v+VT)/(5*mV)))/ms : Hz 192 alphan = 0.032*(mV**-1)*(15*mV-v+VT)/(exp((15*mV-v+VT)/(5*mV))-1.)/ms : Hz 193 betan = .5*exp((10*mV-v+VT)/(40*mV))/ms : Hz 194 tau_syn_E : second 195 tau_syn_I : second 196 e_rev_E : volt 197 e_rev_I : volt 198 e_rev_Na : volt 199 e_rev_K : volt 200 e_rev_leak : volt 201 gbar_Na : nS 202 gbar_K : nS 203 gbar_leak : nS 204 v_offset : volt 205 cm : nF 206 ''') 108 207 109 208 class SpikeSourceInhGamma(common.ModelNotAvailable): trunk/src/brian/connectors.py
r317 r427 10 10 from pyNN.random import RandomDistribution, NativeRNG 11 11 from math import * 12 from numpy import arccos, arcsin, arctan, arctan2, ceil, cos, cosh, e, exp, \ 13 fabs, floor, fmod, hypot, ldexp, log, log10, modf, pi, power, \ 14 sin, sinh, sqrt, tan, tanh 15 16 def _targetConnection(Connector, projection): 17 if projection.synapse_type == "excitatory": 18 target="ge" 19 else: 20 target="gi" 21 return brian.Connection(projection.pre.brian_cells,projection.post.brian_cells,target, delay=Connector.delays*0.001) 12 22 13 23 class AllToAllConnector(common.AllToAllConnector): 14 24 15 25 def connect(self, projection): 16 if projection.synapse_type == "excitatory": 17 projection._connections = brian.Connection(projection.pre.cell, projection.post.cell,'ge', delay=self.delays*0.001) 18 else: 19 projection._connections = brian.Connection(projection.pre.cell, projection.post.cell,'gi', delay=self.delays*0.001) 20 projection._connections.connect_full(projection.pre.cell,projection.post.cell, weight=self.weights) 26 projection._connections = _targetConnection(self, projection) 27 projection._connections.connect_full(projection.pre.brian_cells,projection.post.brian_cells, weight=self.weights) 21 28 return projection._connections.W.getnnz() 22 29 … … 24 31 25 32 def connect(self, projection): 26 raise Exception("Not implemented yet !") 33 projection._connections = _targetConnection(self, projection) 34 projection._connections.connect_one_to_one(projection.pre.brian_cells,projection.post.brian_cells, weight=self.weights) 35 return projection._connections.W.getnnz() 27 36 28 37 class FixedProbabilityConnector(common.FixedProbabilityConnector): 29 38 30 39 def connect(self, projection): 31 if projection.synapse_type == "excitatory": 32 projection._connections = brian.Connection(projection.pre.cell,projection.post.cell,'ge', delay=self.delays*0.001) 33 else: 34 projection._connections = brian.Connection(projection.pre.cell,projection.post.cell,'gi', delay=self.delays*0.001) 35 projection._connections.connect_random(projection.pre.cell,projection.post.cell, self.p_connect, weight=self.weights) 40 projection._connections = _targetConnection(self, projection) 41 projection._connections.connect_random(projection.pre.brian_cells,projection.post.brian_cells, self.p_connect, weight=self.weights) 36 42 return projection._connections.W.getnnz() 37 43 … … 39 45 40 46 def connect(self, projection): 41 raise Exception("Not implemented yet !") 47 48 periodic_boundaries = self.periodic_boundaries 49 if periodic_boundaries is True: 50 dimensions = projection.post.dim 51 periodic_boundaries = tuple(numpy.concatenate((dimensions, numpy.zeros(3-len(dimensions))))) 52 if periodic_boundaries: 53 print "Periodic boundaries activated and set to size ", periodic_boundaries 54 if projection.rng: 55 if isinstance(projection.rng, NativeRNG): 56 print "Warning: use of NativeRNG not implemented. Using NumpyRNG" 57 rng = numpy.random 58 else: 59 rng = projection.rng 60 else: 61 rng = numpy.random 62 global nb_conn, post, N 63 # This is just a temporary counter implemented to be sure the 64 # connections are build as wanted. Because now, for the moment, 65 # the connect_full method of Brian established all the connections, 66 # and not only those with non zero elements. 67 # The -2 comes from the fact that brian will make 2 tests calls before 68 # using the function. 69 nb_conn = -2 70 post = projection.post 71 N = len(post) 72 73 def topoconnect(i,j): 74 global nb_conn, post, N 75 pre = projection.pre.cell.flatten()[i] 76 distances = common.distances(pre, post, self.mask, 77 self.scale_factor, self.offset, 78 periodic_boundaries) 79 func = eval("lambda d: %s" %self.d_expression) 80 p = func(distances[0]) 81 # We get the list of cells that will established a connection 82 rarr = rng.uniform(0, 1, N) 83 conn = ((p >= 1) | ((0 < p) & (p < 1) & (rarr <= p))) 84 if isinstance(self.weights,str): 85 func = eval("lambda d: %s" %self.weights) 86 weights = func(distances[0]) 87 else: 88 weights = self.weights*numpy.ones(N) 89 if isinstance(self.delays,str): 90 raise Exception('''The string definition for delays in Brian is not 91 implemented since Brian does not support yet 92 heterogeneous delays''') 93 if not self.allow_self_connections and conn[i]: 94 conn[i] = False 95 #non_conn = numpy.where(conn == False)[0] 96 #nb_conn += N - len(non_conn) 97 weights[numpy.equal(conn, False)] = 0. 98 return weights 99 projection._connections = _targetConnection(self, projection) 100 projection._connections.connect_full(projection.pre.brian_cells,projection.post.brian_cells,weight=topoconnect) 101 return projection._connections.W.getnnz() 42 102 43 103 trunk/src/brian/synapses.py
r314 r427 8 8 9 9 class SynapseDynamics(common.SynapseDynamics): 10 def __init__(self, *args, **kwargs):11 raise NotImplementedError("Dynamic synapses are not available for this simulator.")10 def __init__(self, fast=None, slow=None): 11 common.SynapseDynamics.__init__(self, fast, slow) 12 12 13 13 class STDPMechanism(common.STDPMechanism): 14 def __init__(self, *args, **kwargs): 15 raise NotImplementedError("STDP is not available for this simulator.") 14 def __init__(self, timing_dependence=None, weight_dependence=None, 15 voltage_dependence=None, dendritic_delay_fraction=1.0): 16 assert dendritic_delay_fraction == 1, """Brian does not currently support axonal delays: 17 for the purpose of STDP calculations all delays 18 are assumed to be dendritic.""" 19 common.STDPMechanism.__init__(self, timing_dependence, weight_dependence, 20 voltage_dependence, dendritic_delay_fraction) 16 21 17 22 class TsodkysMarkramMechanism(common.ModelNotAvailable): 18 pass 23 24 def __init__(self, U=0.5, tau_rec=100.0, tau_facil=0.0, u0=0.0, x0=1.0, y0=0.0): 25 common.TsodyksMarkramMechanism.__init__(self, U, tau_rec, tau_facil, u0, x0, y0) 26 self.parameters = self.translate(parameters) 27 self.eqs = ''' 28 dR/dt=(1-R)/%g : 1 29 tau_rec : ms 30 ''' %tau_rec 31 32 def reset(population,spikes, v_reset): 33 population.R_[spikes]-=U_SE*population.R_[spikes] 34 population.v_[spikes]= v_reset 19 35 20 36 class AdditiveWeightDependence(common.ModelNotAvailable):
