- Timestamp:
- 12/02/11 01:26:26 (6 months ago)
- Location:
- trunk/src
- Files:
-
- 3 modified
-
brian/simulator.py (modified) (1 diff)
-
nemo/__init__.py (modified) (4 diffs)
-
nemo/recording.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/brian/simulator.py
r998 r1022 319 319 dA_post/dt = -A_post/taum : 1''', taup=taup, taum=taum, wmax=wmax, mu_m=mu_m, mu_p=mu_p) 320 320 pre = 'A_pre += Ap' 321 pre += '\nw += A_post* pow(w/wmax, mu_m)'322 323 post = 'A_post += Am' 324 post += '\nw += A_pre* pow(1-w/wmax, mu_p)'321 pre += '\nw += A_post*(w/wmax)**mu_m' 322 323 post = 'A_post += Am' 324 post += '\nw += A_pre*(1-w/wmax)**mu_p' 325 325 brian.STDP.__init__(self, C, eqs=eqs, pre=pre, post=post, wmin=wmin, wmax=wmax, delay_pre=None, delay_post=None, clock=None) 326 326 -
trunk/src/nemo/__init__.py
r1019 r1022 153 153 params['v_thresh'], 154 154 params['i_offset'], 155 init['v'], 0., 0., -1.)155 init['v'], 0., 0., 1000.) 156 156 else: 157 157 init = celltype.default_initial_values … … 228 228 if self.synapse_model is "stdp_synapse": 229 229 self._is_plastic = True 230 self._connections = None230 self._connections = [] 231 231 232 232 method.connect(self) … … 249 249 250 250 @property 251 def connections(self): 252 if self._connections is None: 253 self._connections = [] 254 for source in numpy.unique(self._sources): 255 self._connections += list(simulator.state.sim.get_synapses_from(int(source))) 251 def connections(self): 256 252 return self._connections 257 253 … … 288 284 synapses = simulator.state.net.add_synapse(source, targets, delays, weights, self._is_plastic) 289 285 self._sources.append(source) 286 self._connections += synapses 290 287 291 288 def get(self, parameter_name, format, gather=True): -
trunk/src/nemo/recording.py
r1018 r1022 22 22 recording.Recorder.__init__(self, variable, population, file) 23 23 self._simulator.recorder_list.append(self) 24 self.data = {} 25 self.times = [] 24 if self.variable is "spikes": 25 self.data = numpy.empty([0, 2]) 26 elif self.variable is "v": 27 self.data = numpy.empty([0, 3]) 28 else: 29 raise Exception("Nemo can record only v and spikes for now !") 26 30 27 31 def write(self, file=None, gather=False, compatible_output=True, filter=None): … … 32 36 """Add the cells in `ids` to the set of recorded cells.""" 33 37 self.recorded = self.recorded.union(ids) 34 for id in self.recorded:35 self.data[id] = []36 38 37 39 def _reset(self): … … 39 41 40 42 def _add_spike(self, fired, time): 41 idx = list(self.recorded) 42 if len(fired > 0): 43 left = numpy.searchsorted(fired, idx, 'left') 44 right = numpy.searchsorted(fired, idx, 'right') 45 for id, l, r in zip(idx, left, right): 46 if l != r: 47 self.data[id] += [time] 43 ids = self.recorded.intersection(fired) 44 self.data = numpy.vstack((self.data, numpy.array([list(ids), [time]*len(ids)]).T)) 48 45 ## To file or memory ? ### 49 46 50 47 def _add_vm(self, time): 51 for id in list(self.recorded): 52 self.data[id] += [self._simulator.state.sim.get_membrane_potential(int(id))] 53 self.times += [time] 48 data = self._simulator.state.sim.get_membrane_potential(list(self.recorded)) 49 self.data = numpy.vstack((self.data, numpy.array([list(self.recorded), [time]*len(self.recorded), data]).T)) 54 50 55 51 def _get(self, gather=False, compatible_output=True, filter=None): 56 52 """Return the recorded data as a Numpy array.""" 57 53 filtered_ids = self.filter_recorded(filter) 58 if self.variable == 'spikes': 59 data = numpy.empty((0,2)) 60 for id in filtered_ids: 61 times = numpy.array(self.data[id]) 62 new_data = numpy.array([numpy.ones(times.shape)*id, times]).T 63 data = numpy.concatenate((data, new_data)) 64 elif self.variable == 'v': 65 data = numpy.empty((0,3)) 66 N = len(self.times) 67 for id in filtered_ids: 68 vm = self.data[id] 69 new_data = numpy.array([numpy.ones(N)*id, self.times, vm]).T 70 data = numpy.concatenate((data, new_data)) 54 if len(self.data) > 0: 55 mask = reduce(numpy.add, (self.data[:,0]==id for id in filtered_ids)) 56 data = self.data[mask] 71 57 return data 72 58 … … 77 63 filtered_ids = numpy.array(cells) 78 64 for id in filtered_ids: 79 N[id] = len(self.data[id]) 65 N[id] = 0 66 spikes = self._get(gather=False, compatible_output=False, filter=filter) 67 ids = numpy.sort(spikes[:,0].astype(int)) 68 idx = numpy.unique(ids) 69 left = numpy.searchsorted(ids, idx, 'left') 70 right = numpy.searchsorted(ids, idx, 'right') 71 for id, l, r in zip(idx, left, right): 72 N[id] = r-l 80 73 return N 81 74
