Changeset 1022 for trunk

Show
Ignore:
Timestamp:
12/02/11 01:26:26 (6 months ago)
Author:
pierre
Message:

Work with Dan and Andreas to fix last bugs in Brian and Nemo. For those that may use those backend, please report bugs, even if everything seems to look like normal. Nemo recording part should have been speed up

Location:
trunk/src
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/brian/simulator.py

    r998 r1022  
    319319            dA_post/dt = -A_post/taum : 1''', taup=taup, taum=taum, wmax=wmax, mu_m=mu_m, mu_p=mu_p) 
    320320        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' 
    325325        brian.STDP.__init__(self, C, eqs=eqs, pre=pre, post=post, wmin=wmin, wmax=wmax, delay_pre=None, delay_post=None, clock=None) 
    326326 
  • trunk/src/nemo/__init__.py

    r1019 r1022  
    153153                        params['v_thresh'], 
    154154                        params['i_offset'],                         
    155                         init['v'], 0., 0., -1.) 
     155                        init['v'], 0., 0., 1000.) 
    156156        else:             
    157157            init = celltype.default_initial_values 
     
    228228        if self.synapse_model is "stdp_synapse": 
    229229            self._is_plastic = True 
    230         self._connections = None 
     230        self._connections = [] 
    231231         
    232232        method.connect(self) 
     
    249249 
    250250    @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):         
    256252        return self._connections 
    257253 
     
    288284        synapses = simulator.state.net.add_synapse(source, targets, delays, weights, self._is_plastic) 
    289285        self._sources.append(source) 
     286        self._connections += synapses 
    290287 
    291288    def get(self, parameter_name, format, gather=True): 
  • trunk/src/nemo/recording.py

    r1018 r1022  
    2222        recording.Recorder.__init__(self, variable, population, file) 
    2323        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 !")     
    2630 
    2731    def write(self, file=None, gather=False, compatible_output=True, filter=None): 
     
    3236        """Add the cells in `ids` to the set of recorded cells.""" 
    3337        self.recorded = self.recorded.union(ids) 
    34         for id in self.recorded: 
    35             self.data[id] = [] 
    3638         
    3739    def _reset(self): 
     
    3941 
    4042    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))  
    4845        ## To file or memory ? ### 
    4946 
    5047    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)) 
    5450 
    5551    def _get(self, gather=False, compatible_output=True, filter=None): 
    5652        """Return the recorded data as a Numpy array.""" 
    5753        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] 
    7157        return data 
    7258 
     
    7763        filtered_ids = numpy.array(cells)    
    7864        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 
    8073        return N 
    8174