Changeset 436

Show
Ignore:
Timestamp:
08/10/08 12:31:00 (3 months ago)
Author:
pierre
Message:

Add the possibility of having delays for SpikeSourceArray? and SpikeSourcePoisson? in brian. Also simplify the weights conversion by just defining the same convention as in nest : all inhibitory target should now have negative values

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/brian/__init__.py

    r435 r436  
    2020DEFAULT_BUFFER_SIZE = 10000 
    2121 
     22class MultipleSpikeGeneratorGroupWithDelays(brian.MultipleSpikeGeneratorGroup): 
     23   def __init__(self,spiketimes,clock=None,max_delay=0): 
     24       clock = brian.guess_clock(clock) 
     25       thresh = brian.directcontrol.MultipleSpikeGeneratorThreshold(spiketimes) 
     26       brian.NeuronGroup.__init__(self,len(spiketimes),model=brian.LazyStateUpdater(),threshold=thresh,clock=clock,max_delay=max_delay) 
     27        
     28 
     29class PoissonGroupWithDelays(brian.NeuronGroup): 
     30    def __init__(self,N,rates=0,clock=None,max_delay=0): 
     31        brian.NeuronGroup.__init__(self,N,model=brian.LazyStateUpdater(),threshold=brian.PoissonThreshold(),clock=clock,max_delay=max_delay) 
     32        if callable(rates): # a function is passed 
     33            self._variable_rate=True 
     34            self.rates=rates 
     35            self._S0[0]=self.rates(self.clock.t) 
     36        else: 
     37            self._variable_rate=False 
     38            self._S[0,:]=rates 
     39            self._S0[0]=rates 
     40        self.var_index={'rate':0} 
     41 
    2242# ============================================================================== 
    2343#   Utility classes and functions 
     
    3959    def __getattr__(self, name): 
    4060        try: 
    41             if isinstance(self.parent.brian_cells,brian.MultipleSpikeGeneratorGroup): 
     61            if isinstance(self.parent.brian_cells,MultipleSpikeGeneratorGroupWithDelays): 
    4262                if name == "spike_times": 
    4363                    return 1000*numpy.array(self.parent.brian_cells._threshold.spiketimes[int(self)]) 
     
    5070    def set_native_parameters(self, parameters): 
    5171        for key, value in parameters.items(): 
    52             if isinstance(self.parent.brian_cells,brian.MultipleSpikeGeneratorGroup): 
     72            if isinstance(self.parent.brian_cells,MultipleSpikeGeneratorGroupWithDelays): 
    5373                if key == "spike_times": 
    5474                    spike_times = 0.001*numpy.array(value) 
     
    128148    global simclock 
    129149    return simclock.t 
     150 
     151def get_net_status(): 
     152    global net 
     153    return net 
    130154 
    131155def num_processes(): 
     
    251275                rate              = self.cellparams['rate'] 
    252276                fct               = self.celltype.fct 
    253                 self.brian_cells  = brian.PoissonGroup(self.size, rates = fct, clock=simclock) 
    254                 #self.brian_cells._max_delay = get_max_delay()/get_time_step() 
     277                self.brian_cells  = brian.PoissonGroup(self.size, rates = fct, clock=simclock, ) 
    255278            elif isinstance(self.celltype, SpikeSourceArray): 
    256279                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() 
     280                self.brian_cells  = MultipleSpikeGeneratorGroupWithDelays([spike_times for i in xrange(self.size)], max_delay=get_max_delay()) 
    259281            else: 
    260282                v_thresh   = self.cellparams['v_thresh'] 
     
    483505        - or a list containing the ids of the cells to record. 
    484506        """ 
    485         global net 
     507        global net, simclock 
    486508        if record_from: 
    487509            if isinstance(record_from,int): 
     
    490512        else: 
    491513            record_from = True 
    492         self.vm_recorder = brian.StateMonitor(self.brian_cells,'v',record=record_from
     514        self.vm_recorder = brian.StateMonitor(self.brian_cells,'v',record=record_from, clock=simclock
    493515        net.add(self.vm_recorder) 
    494516     
     
    501523        - or a list containing the ids of the cells to record. 
    502524        """ 
    503         global net 
     525        global net, simclock 
    504526        if record_from: 
    505527            if isinstance(record_from,int): 
     
    508530        else: 
    509531            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
     532        self.ce_recorder = brian.StateMonitor(self.brian_cells,'ge',record=record_from, clock=simclock
     533        self.ci_recorder = brian.StateMonitor(self.brian_cells,'gi',record=record_from, clock=simclock
    512534        net.add(self.ce_recorder) 
    513535        net.add(self.ci_recorder) 
     
    557579        Useful for small populations, for example for single neuron Monte-Carlo. 
    558580        """ 
    559         return self.spike_recorder.spikes 
     581        spikes = numpy.array(self.spike_recorder.spikes) 
     582        try: 
     583            spikes[:,1] = 1000*spikes[:,1] 
     584        except Exception: 
     585            spikes = [] 
     586        return spikes 
    560587 
    561588    def meanSpikeCount(self, gather=True): 
  • trunk/src/brian/cells.py

    r435 r436  
    8989    ) 
    9090    eqs= brian.Equations(''' 
    91         dv/dt  = (v_rest-v)/tau_m + (ge*(e_rev_E-v) + gi*(e_rev_I-v))/(0.001*cm) : volt 
     91        dv/dt  = (v_rest-v)/tau_m + (ge*(e_rev_E-v) - gi*(e_rev_I-v))/(0.001*cm) : volt 
    9292        dge/dt = (2.7182818284590451*ye-ge)/tau_syn_E  : 1  
    9393        dye/dt = -ye/tau_syn_E                         : 1 
     
    124124    ) 
    125125    eqs= brian.Equations(''' 
    126         dv/dt  = (v_rest-v)/tau_m + (ge*(e_rev_E-v) + gi*(e_rev_I-v))/(0.001*cm) : volt 
     126        dv/dt  = (v_rest-v)/tau_m + (ge*(e_rev_E-v) - gi*(e_rev_I-v))/(0.001*cm) : volt 
    127127        dge/dt = -ge/tau_syn_E : 1 
    128128        dgi/dt = -gi/tau_syn_I : 1 
  • trunk/src/brian/connectors.py

    r435 r436  
    55 
    66from pyNN import common 
    7 from pyNN.brian.__init__ import numpy 
     7from pyNN.brian.__init__ import numpy, PoissonGroupWithDelays 
    88import brian_no_units_no_warnings 
    99import brian, types 
     
    2222    else: 
    2323        target=projection.post.celltype.synapses['inh'] 
    24     return brian.Connection(projection.pre.brian_cells,projection.post.brian_cells,target, delay=Connector.delays*0.001) 
     24    src   = projection.pre.brian_cells 
     25    tgt   = projection.post.brian_cells 
     26    delay = Connector.delays*0.001 
     27    connection = brian.Connection(src, tgt, target, delay=delay) 
     28    return connection 
    2529 
    2630def _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 
     31    #if isinstance(projection.pre.brian_cells, PoissonGroupWithDelays): 
     32        #weight *= 10*projection.pre.brian_cells.clock.dt 
    2933    if isinstance(weight, numpy.ndarray): 
    3034        all_negative = (weight<=0).all() 
    3135        all_positive = (weight>=0).all() 
    3236        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 
     37        if projection.synapse_type == 'inhibitory' and all_positive: 
     38            weight *= -1 
    3939    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 
     40        if projection.synapse_type == 'inhibitory' and weight > 0: 
     41            weight *= -1 
     42    else: 
     43        raise TypeError("we must be either a number or a numpy array") 
    4644    return weight 
    4745