Changeset 435
- Timestamp:
- 08/07/08 19:19:34 (2 months ago)
- Files:
-
- trunk/src/brian/__init__.py (modified) (11 diffs)
- trunk/src/brian/cells.py (modified) (7 diffs)
- trunk/src/brian/connectors.py (modified) (6 diffs)
- trunk/test/VAbenchmarks.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/brian/__init__.py
r432 r435 39 39 def __getattr__(self, name): 40 40 try: 41 val = float(self.parent.brian_cells[int(self)].__getattr__(name)) 41 if isinstance(self.parent.brian_cells,brian.MultipleSpikeGeneratorGroup): 42 if name == "spike_times": 43 return 1000*numpy.array(self.parent.brian_cells._threshold.spiketimes[int(self)]) 44 else: 45 val = float(self.parent.brian_cells[int(self)].__getattr__(name)) 46 return val 42 47 except KeyError: 43 48 raise NonExistentParameterError(name, self.cellclass) 44 return val45 49 46 50 def set_native_parameters(self, parameters): 47 51 for key, value in parameters.items(): 48 self.parent.brian_cells[int(self)].__setattr__(key,value) 49 50 52 if isinstance(self.parent.brian_cells,brian.MultipleSpikeGeneratorGroup): 53 if key == "spike_times": 54 spike_times = 0.001*numpy.array(value) 55 self.parent.brian_cells._threshold.spiketimes[int(self)] = spike_times 56 else: 57 self.parent.brian_cells[int(self)].__setattr__(key,value) 51 58 52 59 def list_standard_models(): … … 71 78 simulator but not by others. 72 79 """ 80 global net, simclock, _max_delay, _min_delay 73 81 common.setup(timestep, min_delay, max_delay, debug, **extra_params) 74 global tempdir, net, simclock 75 82 76 83 # Initialisation of the log module. To write in the logfile, simply enter 77 84 # logging.critical(), logging.debug(), logging.info(), logging.warning() … … 88 95 89 96 logging.info("Initialization of Brian") 90 timestep = 0.001*timestep 91 min_delay = 0.001*min_delay 92 max_delay = 0.001*max_delay 97 _min_delay = 0.001*min_delay 98 _max_delay = 0.001*max_delay 93 99 net = brian.Network() 94 simclock = brian.Clock(dt= timestep)100 simclock = brian.Clock(dt=0.001*timestep) 95 101 return 0 96 102 … … 105 111 106 112 def get_min_delay(): 107 return 0.1*brian.ms 113 global _min_delay 114 return _min_delay 108 115 common.get_min_delay = get_min_delay 109 116 117 def get_max_delay(): 118 global _max_delay 119 return _max_delay 120 common.get_max_delay = get_max_delay 121 110 122 def get_time_step(): 111 return 0.1*brian.ms 123 global simclock 124 return simclock.dt 112 125 common.get_time_step = get_time_step 113 126 114 127 def get_current_time(): 115 pass 128 global simclock 129 return simclock.t 116 130 117 131 def num_processes(): … … 231 245 common.Population.__init__(self, dims, cellclass, cellparams, label) # move this to common.Population.__init__() 232 246 233 # Should perhaps use "LayoutNetwork"?234 235 247 if isinstance(cellclass, type): 236 248 self.celltype = cellclass(cellparams) 237 249 self.cellparams = self.celltype.parameters 238 if isinstance(self.celltype, SpikeSourcePoisson):239 rate = self.cellparams['rate']240 fct = self.celltype.fct250 if isinstance(self.celltype, SpikeSourcePoisson): 251 rate = self.cellparams['rate'] 252 fct = self.celltype.fct 241 253 self.brian_cells = brian.PoissonGroup(self.size, rates = fct, clock=simclock) 254 #self.brian_cells._max_delay = get_max_delay()/get_time_step() 255 elif isinstance(self.celltype, SpikeSourceArray): 256 spike_times = 0.001*numpy.array(self.cellparams['spike_times']) 257 self.brian_cells = brian.MultipleSpikeGeneratorGroup([spike_times for i in xrange(self.size)]) 258 #self.brian_cells._max_delay = get_max_delay()/get_time_step() 242 259 else: 243 260 v_thresh = self.cellparams['v_thresh'] 244 261 v_reset = self.cellparams['v_reset'] 245 262 tau_refrac = self.cellparams['tau_refrac'] 246 self.brian_cells = brian.NeuronGroup(self.size,model=cellclass.eqs,threshold=v_thresh,reset=v_reset, refractory=tau_refrac, clock=simclock, compile=True )263 self.brian_cells = brian.NeuronGroup(self.size,model=cellclass.eqs,threshold=v_thresh,reset=v_reset, refractory=tau_refrac, clock=simclock, compile=True, max_delay=get_max_delay()) 247 264 248 265 elif isinstance(cellclass, str): … … 250 267 v_reset = self.cellparams['v_reset'] 251 268 tau_refrac = self.cellparams['tau_refrac'] 252 self.brian_cells = brian.NeuronGroup(self.size,model=cellclass,threshold=v_thresh,reset=v_reset, clock=simclock )269 self.brian_cells = brian.NeuronGroup(self.size,model=cellclass,threshold=v_thresh,reset=v_reset, clock=simclock, compile=True, max_delay=get_max_delay()) 253 270 self.cellparams = self.celltype.parameters 254 271 255 useless_params=['v_thresh', 'v_reset','tau_refrac','cm']272 useless_params=['v_thresh', 'v_reset', 'tau_refrac', 'spike_times'] 256 273 if self.cellparams: 257 274 for key, value in self.cellparams.items(): … … 273 290 net.add(self.brian_cells) 274 291 292 275 293 def __getitem__(self, addr): 276 294 """Return a representation of the cell with coordinates given by addr, … … 470 488 N = record_from 471 489 record_from = numpy.random.permutation(self.cell.flatten()[0:N]) 472 self.vm_recorder = brian.StateMonitor(self.brian_cells,'v',record=record_from)473 else:474 self.vm_recorder = brian.StateMonitor(self.brian_cells,'v',record=True)490 else: 491 record_from = True 492 self.vm_recorder = brian.StateMonitor(self.brian_cells,'v',record=record_from) 475 493 net.add(self.vm_recorder) 476 494 … … 488 506 N = record_from 489 507 record_from = numpy.random.permutation(self.cell.flatten()[0:N]) 490 self.ce_recorder = brian.StateMonitor(self.brian_cells,'ge',record=record_from) 491 self.ci_recorder = brian.StateMonitor(self.brian_cells,'gi',record=record_from) 492 else: 493 self.ce_recorder = brian.StateMonitor(self.brian_cells,'ge',record=True) 494 self.ci_recorder = brian.StateMonitor(self.brian_cells,'gi',record=True) 508 else: 509 record_from = True 510 self.ce_recorder = brian.StateMonitor(self.brian_cells,'ge',record=record_from) 511 self.ci_recorder = brian.StateMonitor(self.brian_cells,'gi',record=record_from) 495 512 net.add(self.ce_recorder) 496 513 net.add(self.ci_recorder) … … 525 542 f.write("# dt = %g\n" % dt) 526 543 spikes = numpy.array(self.spike_recorder.spikes) 527 spikes[:,1]=1000*spikes[:,1] 544 try: 545 spikes[:,1]=1000*spikes[:,1] 546 except Exception: 547 pass 528 548 for item in spikes: 529 549 f.write("%g\t%d\n" %(item[1], item[0])) … … 545 565 # gather is not relevant, but is needed for API consistency 546 566 547 # TO DO : add a recordede list otherwise wrong567 # TO DO : add a recordeded list otherwise wrong 548 568 549 569 return float(self.spike_recorder.nspikes)/len(self) trunk/src/brian/cells.py
r432 r435 26 26 ) 27 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 28 dv/dt = (ge + gi)/cm + (v_rest-v)/tau_m : volt 29 dge/dt = (2.7182818284590451*ye-ge)/tau_syn_E : 1 30 dye/dt = -ye/tau_syn_E : 1 31 dgi/dt = (2.7182818284590451*yi-gi)/tau_syn_I : 1 32 dyi/dt = -yi/tau_syn_I : 1 33 cm : farad 34 tau_syn_E : second 35 tau_syn_I : second 36 tau_m : second 37 v_rest : volt 38 ''' 39 ) 40 41 synapses = {'exc' : 'ye', 'inh' : 'yi'} 40 42 41 43 class IF_curr_exp(common.IF_curr_exp): … … 57 59 ) 58 60 eqs= brian.Equations(''' 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 ) 68 69 70 class IF_cond_alpha(common.ModelNotAvailable): 61 dv/dt = (ge + gi)/cm + (v_rest-v)/tau_m : volt 62 dge/dt = -ge/tau_syn_E : 1 63 dgi/dt = -gi/tau_syn_I : 1 64 tau_syn_E : second 65 tau_syn_I : second 66 tau_m : second 67 cm : farad 68 v_rest : volt 69 ''' 70 ) 71 72 synapses = {'exc' : 'ge', 'inh' : 'gi'} 73 74 75 class IF_cond_alpha(common.IF_cond_alpha): 71 76 translations = common.build_translations( 72 77 ('v_rest', 'v_rest',0.001) , … … 84 89 ) 85 90 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 ) 99 91 dv/dt = (v_rest-v)/tau_m + (ge*(e_rev_E-v) + gi*(e_rev_I-v))/(0.001*cm) : volt 92 dge/dt = (2.7182818284590451*ye-ge)/tau_syn_E : 1 93 dye/dt = -ye/tau_syn_E : 1 94 dgi/dt = (2.7182818284590451*yi-gi)/tau_syn_I : 1 95 dyi/dt = -yi/tau_syn_I : 1 96 tau_syn_E : second 97 tau_syn_I : second 98 tau_m : second 99 v_rest : volt 100 e_rev_E : volt 101 e_rev_I : volt 102 cm : farad 103 ''' 104 ) 105 106 synapses = {'exc' : 'ye', 'inh' : 'yi'} 100 107 101 108 class IF_cond_exp(common.IF_cond_exp): … … 117 124 ) 118 125 eqs= brian.Equations(''' 119 dv/dt = ( (v_rest-v) + ge*(e_rev_E-v) + gi*(e_rev_I-v))/tau_m: volt126 dv/dt = (v_rest-v)/tau_m + (ge*(e_rev_E-v) + gi*(e_rev_I-v))/(0.001*cm) : volt 120 127 dge/dt = -ge/tau_syn_E : 1 121 128 dgi/dt = -gi/tau_syn_I : 1 … … 123 130 tau_syn_I : second 124 131 tau_m : second 132 cm : farad 125 133 v_rest : volt 126 134 e_rev_E : volt … … 128 136 ''' 129 137 ) 138 139 synapses = {'exc' : 'ge', 'inh' : 'gi'} 130 140 131 141 class IF_facets_hardware1(common.IF_facets_hardware1): … … 155 165 class SpikeSourceArray(common.SpikeSourceArray): 156 166 """Spike source generating spikes at the times given in the spike_times array.""" 167 translations = common.build_translations( 168 ('spike_times', 'spike_times'), 169 ) 170 171 def __init__(self, parameters): 172 common.SpikeSourceArray.__init__(self, parameters) 157 173 158 174 trunk/src/brian/connectors.py
r427 r435 7 7 from pyNN.brian.__init__ import numpy 8 8 import brian_no_units_no_warnings 9 import brian 9 import brian, types 10 10 from pyNN.random import RandomDistribution, NativeRNG 11 11 from math import * … … 14 14 sin, sinh, sqrt, tan, tanh 15 15 16 def is_number(n): 17 return type(n) == types.FloatType or type(n) == types.IntType or type(n) == numpy.float64 18 16 19 def _targetConnection(Connector, projection): 17 if projection.synapse_type == "excitatory" :18 target= "ge"20 if projection.synapse_type == "excitatory" or projection.synapse_type is None: 21 target=projection.post.celltype.synapses['exc'] 19 22 else: 20 target= "gi"23 target=projection.post.celltype.synapses['inh'] 21 24 return brian.Connection(projection.pre.brian_cells,projection.post.brian_cells,target, delay=Connector.delays*0.001) 25 26 def _convertWeight(weight, projection): 27 #if isinstance(projection.pre.brian_cells, brian.PoissonGroup): 28 #weight *= projection.pre.brian_cells.rate[0]*projection.pre.brian_cells.clock.dt 29 if isinstance(weight, numpy.ndarray): 30 all_negative = (weight<=0).all() 31 all_positive = (weight>=0).all() 32 assert all_negative or all_positive, "Weights must be either all positive or all negative" 33 if not projection.post.celltype.default_parameters.has_key('e_rev_E'): 34 if projection.synapse_type == 'inhibitory' and all_positive: 35 weight *= -1 36 else: 37 if projection.synapse_type == "inhibitory" and all_negative: 38 weight *= 1 39 elif is_number(weight): 40 if not projection.post.celltype.default_parameters.has_key('e_rev_E'): 41 if projection.synapse_type == 'inhibitory' and weight > 0: 42 weight *= -1 43 else: 44 if projection.synapse_type == 'inhibitory' and weight < 0: 45 weight *= -1 46 return weight 22 47 23 48 class AllToAllConnector(common.AllToAllConnector): … … 25 50 def connect(self, projection): 26 51 projection._connections = _targetConnection(self, projection) 27 projection._connections.connect_full(projection.pre.brian_cells,projection.post.brian_cells, weight=self.weights) 52 weight = _convertWeight(self.weights, projection) 53 projection._connections.connect_full(projection.pre.brian_cells,projection.post.brian_cells, weight=weight) 28 54 return projection._connections.W.getnnz() 29 55 … … 32 58 def connect(self, projection): 33 59 projection._connections = _targetConnection(self, projection) 34 projection._connections.connect_one_to_one(projection.pre.brian_cells,projection.post.brian_cells, weight=self.weights) 60 weight = _convertWeight(self.weights, projection) 61 projection._connections.connect_one_to_one(projection.pre.brian_cells,projection.post.brian_cells, weight=weight) 35 62 return projection._connections.W.getnnz() 36 63 … … 39 66 def connect(self, projection): 40 67 projection._connections = _targetConnection(self, projection) 41 projection._connections.connect_random(projection.pre.brian_cells,projection.post.brian_cells, self.p_connect, weight=self.weights) 68 weight = _convertWeight(self.weights, projection) 69 projection._connections.connect_random(projection.pre.brian_cells,projection.post.brian_cells, self.p_connect, weight=weight) 42 70 return projection._connections.W.getnnz() 43 71 … … 87 115 else: 88 116 weights = self.weights*numpy.ones(N) 117 weights = _convertWeight(weights, projection) 89 118 if isinstance(self.delays,str): 90 119 raise Exception('''The string definition for delays in Brian is not trunk/test/VAbenchmarks.py
r433 r435 92 92 w_exc = 1e-3*Gexc*(Erev_exc - v_mean) # (nA) weight of excitatory synapses 93 93 w_inh = 1e-3*Ginh*(Erev_inh - v_mean) # (nA) 94 if simulator == "brian":95 w_exc = w_exc*0.196 w_inh = w_inh*0.197 94 assert w_exc > 0; assert w_inh < 0 98 95
