Changeset 185

Show
Ignore:
Timestamp:
01/28/08 16:50:55 (10 months ago)
Author:
apdavison
Message:

Separated cells.py, connectors.py and synapses.py out from __init__.py for neuron, nest1 and nest2. Most of the tests still pass. neuron seems to be slightly broken because of the inadequacies of the Hoc2Py class, but it is past time this was updated to use HocObject anyway.

I haven't yet separated out pcsim/__init__.py.

Moved the hoc directory to within src.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/multifile/src/nest1/__init__.py

    r164 r185  
    1111import numpy, types, sys, shutil, os, logging, copy, tempfile 
    1212from math import * 
     13from pyNN.nest1.cells import * 
     14from pyNN.nest1.connectors import * 
    1315 
    1416ll_spike_files = [] 
     
    1820tempdirs       = [] 
    1921dt             = 0.1 
    20  
     22_min_delay     = 0.1 
    2123 
    2224 
     
    112114 
    113115 
    114 # ============================================================================== 
    115 #   Standard cells 
    116 # ============================================================================== 
    117   
    118 class IF_curr_alpha(common.IF_curr_alpha): 
    119     """Leaky integrate and fire model with fixed threshold and alpha-function- 
    120     shaped post-synaptic current.""" 
    121      
    122     translations = { 
    123             'v_rest'    : ('U0'    ,  "parameters['v_rest']"), 
    124             'v_reset'   : ('Vreset',  "parameters['v_reset']"), 
    125             'cm'        : ('C'     ,  "parameters['cm']*1000.0"), # C is in pF, cm in nF 
    126             'tau_m'     : ('Tau'   ,  "parameters['tau_m']"), 
    127             'tau_refrac': ('TauR'  ,  "max(dt,parameters['tau_refrac'])"), 
    128             'tau_syn_E' : ('TauSynE', "parameters['tau_syn_E']"), 
    129             'tau_syn_I' : ('TauSynI', "parameters['tau_syn_I']"), 
    130             'v_thresh'  : ('Theta' ,  "parameters['v_thresh']"), 
    131             'i_offset'  : ('I0'    ,  "parameters['i_offset']*1000.0"), # I0 is in pA, i_offset in nA 
    132             'v_init'    : ('u'     ,  "parameters['v_init']"), 
    133     } 
    134     nest_name = "iaf_neuron2" 
    135      
    136     def __init__(self,parameters): 
    137         common.IF_curr_alpha.__init__(self,parameters) # checks supplied parameters and adds default 
    138                                                        # values for not-specified parameters. 
    139         self.parameters = self.translate(self.parameters) 
    140  
    141 class IF_curr_exp(common.IF_curr_exp): 
    142     """Leaky integrate and fire model with fixed threshold and 
    143     decaying-exponential post-synaptic current. (Separate synaptic currents for 
    144     excitatory and inhibitory synapses.""" 
    145      
    146     translations = { 
    147         'v_rest'    : ('U0'     , "parameters['v_rest']"), 
    148         'v_reset'   : ('Vreset' , "parameters['v_reset']"), 
    149         'cm'        : ('C'      , "parameters['cm']*1000.0"), # C is in pF, cm in nF 
    150         'tau_m'     : ('Tau'    , "parameters['tau_m']"), 
    151         'tau_refrac': ('TauR'   , "max(dt,parameters['tau_refrac'])"), 
    152         'tau_syn_E' : ('TauSynE', "parameters['tau_syn_E']"), 
    153         'tau_syn_I' : ('TauSynI', "parameters['tau_syn_I']"), 
    154         'v_thresh'  : ('Theta'  , "parameters['v_thresh']"), 
    155         'i_offset'  : ('I0'     , "parameters['i_offset']*1000.0"), # I0 is in pA, i_offset in nA 
    156         'v_init'    : ('u'      , "parameters['v_init']"), 
    157     } 
    158     nest_name = 'iaf_exp_neuron2' 
    159      
    160     def __init__(self,parameters): 
    161         common.IF_curr_exp.__init__(self,parameters) 
    162         self.parameters = self.translate(self.parameters) 
    163  
    164 class IF_cond_alpha(common.IF_cond_alpha): 
    165     """Leaky integrate and fire model with fixed threshold and alpha-function- 
    166     shaped post-synaptic conductance.""" 
    167      
    168     translations = { 
    169             'v_rest'    : ('U0'          , "parameters['v_rest']"), 
    170             'v_reset'   : ('Vreset'      , "parameters['v_reset']"), 
    171             'cm'        : ('C'           , "parameters['cm']*1000.0"), # C is in pF, cm in nF 
    172             'tau_m'     : ('Tau'         , "parameters['tau_m']"), 
    173             'tau_refrac': ('TauR'        , "max(dt,parameters['tau_refrac'])"), 
    174             'tau_syn_E' : ('TauSyn_E'    , "parameters['tau_syn_E']"), 
    175             'tau_syn_I' : ('TauSyn_I'    , "parameters['tau_syn_I']"), 
    176             'v_thresh'  : ('Theta'       , "parameters['v_thresh']"), 
    177             'i_offset'  : ('Istim'       , "parameters['i_offset']*1000.0"), # I0 is in pA, i_offset in nA 
    178             'e_rev_E'   : ('V_reversal_E', "parameters['e_rev_E']"), 
    179             'e_rev_I'   : ('V_reversal_I', "parameters['e_rev_I']"), 
    180             'v_init'    : ('u'           , "parameters['v_init']"), 
    181     } 
    182     nest_name = "iaf_cond_alpha" 
    183      
    184     def __init__(self,parameters): 
    185         common.IF_cond_alpha.__init__(self,parameters) # checks supplied parameters and adds default 
    186                                                        # values for not-specified parameters. 
    187         self.parameters = self.translate(self.parameters) 
    188         self.parameters['gL'] = self.parameters['C']/self.parameters['Tau'] # Trick to fix the leak conductance 
    189  
    190  
    191 class IF_cond_exp(common.IF_cond_exp): 
    192     """Leaky integrate and fire model with fixed threshold and alpha-function- 
    193     shaped post-synaptic conductance.""" 
    194      
    195     translations = { 
    196             'v_rest'    : ('U0'          , "parameters['v_rest']"), 
    197             'v_reset'   : ('Vreset'      , "parameters['v_reset']"), 
    198             'cm'        : ('C'           , "parameters['cm']*1000.0"), # C is in pF, cm in nF 
    199             'tau_m'     : ('Tau'         , "parameters['tau_m']"), 
    200             'tau_refrac': ('TauR'        , "max(dt,parameters['tau_refrac'])"), 
    201             'tau_syn_E' : ('TauSyn_E'    , "parameters['tau_syn_E']"), 
    202             'tau_syn_I' : ('TauSyn_I'    , "parameters['tau_syn_I']"), 
    203             'v_thresh'  : ('Theta'       , "parameters['v_thresh']"), 
    204             'i_offset'  : ('Istim'       , "parameters['i_offset']*1000.0"), # I0 is in pA, i_offset in nA 
    205             'e_rev_E'   : ('V_reversal_E', "parameters['e_rev_E']"), 
    206             'e_rev_I'   : ('V_reversal_I', "parameters['e_rev_I']"), 
    207             'v_init'    : ('u'           , "parameters['v_init']"), 
    208     } 
    209     nest_name = "iaf_cond_exp" 
    210      
    211     def __init__(self,parameters): 
    212         common.IF_cond_exp.__init__(self,parameters) # checks supplied parameters and adds default 
    213                                                        # values for not-specified parameters. 
    214         self.parameters = self.translate(self.parameters) 
    215         self.parameters['gL'] = self.parameters['C']/self.parameters['Tau'] # Trick to fix the leak conductance 
    216  
    217  
    218 class SpikeSourcePoisson(common.SpikeSourcePoisson): 
    219     """Spike source, generating spikes according to a Poisson process.""" 
    220  
    221     translations = { 
    222         'rate'     : ('rate'   , "parameters['rate']"), 
    223         'start'    : ('start'  , "parameters['start']"), 
    224         'duration' : ('stop'   , "parameters['duration']+parameters['start']") 
    225     } 
    226     nest_name = 'poisson_generator' 
    227      
    228      
    229     def __init__(self,parameters): 
    230         common.SpikeSourcePoisson.__init__(self,parameters) 
    231         self.parameters = self.translate(self.parameters) 
    232         self.parameters['origin'] = 1.0 
    233      
    234 class SpikeSourceArray(common.SpikeSourceArray): 
    235     """Spike source generating spikes at the times given in the spike_times array.""" 
    236  
    237     translations = { 
    238         'spike_times' : ('spike_times' , "parameters['spike_times']"), 
    239     } 
    240     nest_name = 'spike_generator' 
    241      
    242     def __init__(self,parameters): 
    243         common.SpikeSourceArray.__init__(self,parameters) 
    244         self.parameters = self.translate(self.parameters)   
    245      
     116 
    246117 
    247118# ============================================================================== 
     
    16521523 
    16531524# ============================================================================== 
    1654 #   Connection method classes 
    1655 # ============================================================================== 
    1656  
    1657  
    1658 class AllToAllConnector(common.AllToAllConnector, WDManager):     
    1659      
    1660     def connect(self, projection): 
    1661         weight = self.getWeight(self.weights) 
    1662         weight = self.convertWeight(weight, projection.synapse_type) 
    1663         delay  = self.getDelay(self.delays) 
    1664         postsynaptic_neurons = numpy.reshape(projection.post.cell,(projection.post.cell.size,)) 
    1665         presynaptic_neurons  = numpy.reshape(projection.pre.cell,(projection.pre.cell.size,)) 
    1666         for post in postsynaptic_neurons: 
    1667             source_list = presynaptic_neurons.tolist() 
    1668             # if self connections are not allowed, check whether pre and post are the same 
    1669             if not self.allow_self_connections and post in source_list: 
    1670                 source_list.remove(post) 
    1671             N = len(source_list) 
    1672             if isinstance(weight, RandomDistribution): 
    1673                 weights = list(weight.next(N)) 
    1674             else: 
    1675                 weights = [weight]*N 
    1676             if isinstance(delay, RandomDistribution): 
    1677                 delays = list(delay.next(N)) 
    1678             else: 
    1679                 delays = [float(delay)]*N 
    1680             projection._targets += [post]*N 
    1681             projection._sources += source_list 
    1682             projection._targetPorts +=  pynest.convergentConnect(source_list,post,weights,delays) 
    1683         return len(projection._targets) 
    1684  
    1685 class OneToOneConnector(common.OneToOneConnector, WDManager): 
    1686      
    1687     def connect(self, projection): 
    1688         weight = self.getWeight(self.weights) 
    1689         weight = self.convertWeight(weight, projection.synapse_type) 
    1690         delay  = self.getDelay(self.delays) 
    1691         if projection.pre.dim == projection.post.dim: 
    1692             projection._sources = numpy.reshape(projection.pre.cell,(projection.pre.cell.size,)) 
    1693             projection._targets = numpy.reshape(projection.post.cell,(projection.post.cell.size,)) 
    1694             N = len(projection._sources) 
    1695             if isinstance(weight, RandomDistribution): 
    1696                 weights = list(weight.next(N)) 
    1697             else: 
    1698                 weights = [weight]*N 
    1699             if isinstance(delay, RandomDistribution): 
    1700                 delays = list(delay.next(N)) 
    1701             else: 
    1702                 delays = [float(delay)]*N 
    1703             for pre,post,w,d in zip(projection._sources,projection._targets,weights, delays): 
    1704                 pre_addr = pynest.getAddress(pre) 
    1705                 post_addr = pynest.getAddress(post) 
    1706                 projection._targetPorts.append(pynest.connectWD(pre_addr,post_addr,w,d)) 
    1707             return projection.pre.size 
    1708         else: 
    1709             raise Exception("Connection method not yet implemented for the case where presynaptic and postsynaptic Populations have different sizes.") 
    1710      
    1711 class FixedProbabilityConnector(common.FixedProbabilityConnector, WDManager): 
    1712      
    1713     def connect(self, projection): 
    1714         weight = self.getWeight(self.weights) 
    1715         weight = self.convertWeight(weight, projection.synapse_type) 
    1716         delay  = self.getDelay(self.delays) 
    1717         postsynaptic_neurons = numpy.reshape(projection.post.cell,(projection.post.cell.size,)) 
    1718         presynaptic_neurons  = numpy.reshape(projection.pre.cell,(projection.pre.cell.size,)) 
    1719         npre = projection.pre.size 
    1720         for post in postsynaptic_neurons: 
    1721             if projection.rng: 
    1722                 rarr = projection.rng.uniform(0,1,(npre,)) # what about NativeRNG? 
    1723             else: 
    1724                 rarr = numpy.random.uniform(0,1,(npre,)) 
    1725             source_list = numpy.compress(numpy.less(rarr,self.p_connect),presynaptic_neurons).tolist() 
    1726             # if self connections are not allowed, check whether pre and post are the same 
    1727             if not self.allow_self_connections and post in source_list: 
    1728                 source_list.remove(post) 
    1729             N = len(source_list) 
    1730             if isinstance(weight, RandomDistribution): 
    1731                 weights = list(weight.next(N)) 
    1732             else: 
    1733                 weights = [weight]*N 
    1734             if isinstance(delay, RandomDistribution): 
    1735                 delays = list(delay.next(N)) 
    1736             else: 
    1737                 delays = [float(delay)]*N 
    1738             projection._targets += [post]*N 
    1739             projection._sources += source_list 
    1740             projection._targetPorts += pynest.convergentConnect(source_list,post,weights,delays) 
    1741         return len(projection._sources) 
    1742      
    1743 class DistanceDependentProbabilityConnector(common.DistanceDependentProbabilityConnector, WDManager): 
    1744      
    1745     def connect(self, projection): 
    1746         weight = self.getWeight(self.weights) 
    1747         weight = self.convertWeight(weight, projection.synapse_type) 
    1748         delay  = self.getDelay(self.delays) 
    1749         periodic_boundaries = self.periodic_boundaries  
    1750         if periodic_boundaries is not None: 
    1751             dimensions = projection.post.dim 
    1752             periodic_boundaries = numpy.concatenate((dimensions,numpy.zeros(3-len(dimensions)))) 
    1753         postsynaptic_neurons = numpy.reshape(projection.post.cell,(projection.post.cell.size,)) 
    1754         presynaptic_neurons  = numpy.reshape(projection.pre.cell,(projection.pre.cell.size,)) 
    1755         # what about NativeRNG? 
    1756         if projection.rng: 
    1757             if isinstance(projection.rng, NativeRNG): 
    1758                 print "Warning: use of NativeRNG not implemented. Using NumpyRNG" 
    1759                 rarr = numpy.random.uniform(0,1,(projection.pre.size*projection.post.size,)) 
    1760             else: 
    1761                 rarr = projection.rng.uniform(0,1,(projection.pre.size*projection.post.size,)) 
    1762         else: 
    1763             rarr = numpy.random.uniform(0,1,(projection.pre.size*projection.post.size,)) 
    1764         j = 0 
    1765         for post in postsynaptic_neurons: 
    1766             source_list=[] 
    1767             idx_pre  = 0 
    1768             distances = common.distances(projection.pre, post, self.mask, self.scale_factor, self.offset, periodic_boundaries) 
    1769             for pre in presynaptic_neurons: 
    1770                 if self.allow_self_connections or pre != post:  
    1771                     # calculate the distance between the two cells : 
    1772                     d = distances[idx_pre][0] 
    1773                     p = eval(self.d_expression) 
    1774                     # calculate the addresses of cells 
    1775                     #pre_addr  = pynest.getAddress(pre) 
    1776                     #post_addr = pynest.getAddress(post) 
    1777                     if p >= 1 or (0 < p < 1 and rarr[j] < p): 
    1778                         source_list.append(pre) 
    1779                         #projection._targets.append(post) 
    1780                         #projection._targetPorts.append(pynest.connectWD(pre_addr,post_addr,weight,delay))  
    1781                 j += 1 
    1782                 idx_pre += 1 
    1783             N = len(source_list) 
    1784             if isinstance(weight, RandomDistribution): 
    1785                 weights = list(weight.next(N)) 
    1786             else: 
    1787                 weights = [weight]*N 
    1788             if isinstance(delay, RandomDistribution): 
    1789                 delays = list(delay.next(N)) 
    1790             else: 
    1791                 delays = [float(delay)]*N 
    1792             projection._targets += [post]*N 
    1793             projection._sources += source_list 
    1794             projection._targetPorts += pynest.convergentConnect(source_list,post,weights,delays) 
    1795         return len(projection._sources) 
    1796  
    1797  
    1798 class FixedNumberPreConnector(common.FixedNumberPreConnector): 
    1799      
    1800     def connect(self, projection): 
    1801         raise Exception("Not implemented yet !") 
    1802  
    1803  
    1804 class FixedNumberPostConnector(common.FixedNumberPostConnector): 
    1805      
    1806     def connect(self, projection): 
    1807         raise Exception("Not implemented yet !") 
    1808  
    1809  
    1810  
    1811  
    1812  
    1813 # ============================================================================== 
    18141525#   Utility classes 
    18151526# ============================================================================== 
  • branches/multifile/src/nest2/__init__.py

    r164 r185  
    1111import numpy, types, sys, shutil, os, logging, copy, tempfile 
    1212from math import * 
     13from pyNN.nest2.cells import * 
     14from pyNN.nest2.connectors import * 
    1315 
    1416#ll_spike_files = [] 
     
    2325                          'v': 'voltmeter', 
    2426                          'conductance': 'conductancemeter'} 
     27_min_delay = 0.1 
    2528 
    2629# ============================================================================== 
     
    167170def list_standard_models(): 
    168171    return [obj for obj in globals().values() if isinstance(obj, type) and issubclass(obj, common.StandardCellType)] 
    169  
    170 # ============================================================================== 
    171 #   Standard cells 
    172 # ============================================================================== 
    173   
    174 class IF_curr_alpha(common.IF_curr_alpha): 
    175     """Leaky integrate and fire model with fixed threshold and alpha-function- 
    176     shaped post-synaptic current.""" 
    177  
    178     translations = common.build_translations( 
    179         ('v_rest',     'E_L'), 
    180         ('v_reset',    'V_reset'), 
    181         ('cm',         'C_m',      1000.0), # C_m is in pF, cm in nF 
    182         ('tau_m',      'tau_m'), 
    183         ('tau_refrac', 't_ref',  "max(dt, tau_refrac)", "tau_ref"), 
    184         ('tau_syn_E',  'tau_syn_ex'), 
    185         ('tau_syn_I',  'tau_syn_in'), 
    186         ('v_thresh',   'V_th'), 
    187         ('i_offset',   'I_e',      1000.0), # I_e is in pA, i_offset in nA 
    188         ('v_init',     'V_m'), 
    189     ) 
    190     nest_name = "iaf_psc_alpha" 
    191     def __init__(self,parameters): 
    192         common.IF_curr_alpha.__init__(self,parameters) # checks supplied parameters and adds default 
    193                                                        # values for not-specified parameters. 
    194         self.parameters = self.translate1(self.parameters) 
    195  
    196 class IF_curr_exp(common.IF_curr_exp): 
    197     """Leaky integrate and fire model with fixed threshold and 
    198     decaying-exponential post-synaptic current. (Separate synaptic currents for 
    199     excitatory and inhibitory synapses.""" 
    200      
    201     translations = common.build_translations( 
    202         ('v_rest',     'E_L'), 
    203         ('v_reset',    'V_reset'), 
    204         ('cm',         'C_m',      1000.0), # C_m is in pF, cm in nF 
    205         ('tau_m',      'tau_m'), 
    206         ('tau_refrac', 't_ref_abs',  "max(dt, tau_refrac)", "tau_ref"), 
    207         ('tau_syn_E',  'tau_syn_ex'), 
    208         ('tau_syn_I',  'tau_syn_in'), 
    209         ('v_thresh',   'V_th'), 
    210         ('i_offset',   'I_e',      1000.0), # I_e is in pA, i_offset in nA 
    211         ('v_init',     'V_m'), 
    212     ) 
    213     nest_name = 'iaf_psc_exp' 
    214     def __init__(self,parameters): 
    215         common.IF_curr_exp.__init__(self,parameters) 
    216         self.parameters = self.translate1(self.parameters) 
    217  
    218 class IF_cond_alpha(common.IF_cond_alpha): 
    219     """Leaky integrate and fire model with fixed threshold and alpha-function- 
    220     shaped post-synaptic conductance.""" 
    221  
    222     translations = common.build_translations( 
    223         ('v_rest',     'E_L')    , 
    224         ('v_reset',    'V_reset'), 
    225         ('cm',         'C_m',        1000.0), # C_m is in pF, cm in nF 
    226         ('tau_m',      'g_L',        "cm/tau_m*1000.0", "C_m/g_L"), 
    227         ('tau_refrac', 't_ref',      "max(dt, tau_refrac)", "t_ref"), 
    228         ('tau_syn_E',  'tau_syn_ex'), 
    229         ('tau_syn_I',  'tau_syn_in'), 
    230         ('v_thresh',   'V_th'), 
    231         ('i_offset',   'I_e',        1000.0), # I_e is in pA, i_offset in nA 
    232         ('e_rev_E',    'E_ex'), 
    233         ('e_rev_I',    'E_in'), 
    234         ('v_init',     'V_m'), 
    235     ) 
    236     nest_name = "iaf_cond_alpha" 
    237     def __init__(self,parameters): 
    238         common.IF_cond_alpha.__init__(self,parameters) # checks supplied parameters and adds default 
    239                                                        # values for not-specified parameters. 
    240         self.parameters = self.translate1(self.parameters) 
    241          
    242  
    243 class IF_cond_exp(common.IF_cond_exp): 
    244     """Leaky integrate and fire model with fixed threshold and alpha-function- 
    245     shaped post-synaptic conductance.""" 
    246      
    247     translations = common.build_translations( 
    248         ('v_rest',     'E_L')    , 
    249         ('v_reset',    'V_reset'), 
    250         ('cm',         'C_m',        1000.0), # C_m is in pF, cm in nF 
    251         ('tau_m',      'g_L',        "cm/tau_m*1000.0", "C_m/g_L"), 
    252         ('tau_refrac', 't_ref',      "max(dt, tau_refrac)", "t_ref"), 
    253         ('tau_syn_E',  'tau_syn_ex'), 
    254         ('tau_syn_I',  'tau_syn_in'), 
    255         ('v_thresh',   'V_th'), 
    256         ('i_offset',   'I_e',        1000.0), # I_e is in pA, i_offset in nA 
    257         ('e_rev_E',    'E_ex'), 
    258         ('e_rev_I',    'E_in'), 
    259         ('v_init',     'V_m'), 
    260     ) 
    261     nest_name = "iaf_cond_exp" 
    262     def __init__(self,parameters): 
    263         common.IF_cond_exp.__init__(self,parameters) # checks supplied parameters and adds default 
    264                                                        # values for not-specified parameters. 
    265         self.parameters = self.translate1(self.parameters) 
    266          
    267  
    268 class HH_cond_exp(common.HH_cond_exp): 
    269     """docstring needed here.""" 
    270      
    271     translations = { 
    272         'gbar_Na'   : ('g_Na',   "parameters['gbar_Na']"),    
    273         'gbar_K'    : ('g_K',    "parameters['gbar_K']"),     
    274         'g_leak'    : ('g_L',    "parameters['g_leak']"),     
    275         'cm'        : ('C_m',    "parameters['cm']*1000.0"),   
    276         'v_offset'  : ('U_tr',   "parameters['v_offset']"), 
    277         'e_rev_Na'  : ('E_Na',   "parameters['e_rev_Na']"), 
    278         'e_rev_K'   : ('E_K',    "parameters['e_rev_K']"),  
    279         'e_rev_leak': ('E_L',    "parameters['e_rev_leak']"), 
    280         'e_rev_E'   : ('E_ex',   "parameters['e_rev_E']"), 
    281         'e_rev_I'   : ('E_in',   "parameters['e_rev_I']"), 
    282         'tau_syn_E' : ('tau_ex', "parameters['tau_syn_E']"), 
    283         'tau_syn_I' : ('tau_in', "parameters['tau_syn_I']"), 
    284         'i_offset'  : ('I_stim', "parameters['i_offset']*1000.0"), 
    285         'v_init'    : ('V_m',    "parameters['v_init']"), 
    286     } 
    287     nest_name = "hh_cond_exp_traub" 
    288      
    289     def __init__(self,parameters): 
    290         common.HH_cond_exp.__init__(self,parameters) # checks supplied parameters and adds default 
    291                                                      # values for not-specified parameters. 
    292         self.parameters = self.translate(self.parameters) 
    293          
    294 class AdaptiveExponentialIF_alpha(common.AdaptiveExponentialIF_alpha): 
    295     """adaptive exponential integrate and fire neuron according to Brette and Gerstner (2005)""" 
    296  
    297     translations = common.build_translations( 
    298         ('v_init'    , 'V_m'), 
    299         ('w_init'    , 'w',         1000.0),  # nA -> pA 
    300         ('cm'        , 'C_m',       1000.0),  # nF -> pF 
    301         ('tau_refrac', 't_ref'),  
    302         ('v_spike'   , 'V_peak'), 
    303         ('v_reset'   , 'V_reset'), 
    304         ('v_rest'    , 'E_L'), 
    305         ('tau_m'     , 'g_L',       "cm/tau_m*1000.0", "C_m/g_L"), 
    306         ('i_offset'  , 'I_e',       1000.0),  # nA -> pA 
    307         ('a'         , 'a'),        
    308         ('b'         , 'b',         1000.0),  # nA -> pA. 
    309         ('delta_T'   , 'Delta_T'),  
    310         ('tau_w'     , 'tau_w'),  
    311         ('v_thresh'  , 'V_th'),  
    312         ('e_rev_E'   , 'E_ex'), 
    313         ('tau_syn_E' , 'tau_syn_ex'),  
    314         ('e_rev_I'   , 'E_in'),  
    315         ('tau_syn_I' , 'tau_syn_in'), 
    316     ) 
    317     nest_name = "aeif_cond_alpha" 
    318      
    319     def __init__(self,parameters): 
    320         common.AdaptiveExponentialIF_alpha.__init__(self,parameters) 
    321         self.parameters = self.translate1(self.parameters) 
    322          
    323 class SpikeSourcePoisson(common.SpikeSourcePoisson): 
    324     """Spike source, generating spikes according to a Poisson process.""" 
    325  
    326     translations = { 
    327         'rate'     : ('rate'   , "parameters['rate']"), 
    328         'start'    : ('start'  , "parameters['start']"), 
    329         'duration' : ('stop'   , "parameters['duration']+parameters['start']") 
    330     } 
    331     nest_name = 'poisson_generator' 
    332      
    333     def __init__(self,parameters): 
    334         common.SpikeSourcePoisson.__init__(self,parameters) 
    335         self.parameters = self.translate(self.parameters) 
    336         self.parameters['origin'] = 1.0 
    337      
    338 class SpikeSourceArray(common.SpikeSourceArray): 
    339     """Spike source generating spikes at the times given in the spike_times array.""" 
    340  
    341     translations = { 
    342         'spike_times' : ('spike_times' , "parameters['spike_times']"), 
    343     } 
    344     nest_name = 'spike_generator' 
    345      
    346     def __init__(self,parameters): 
    347         common.SpikeSourceArray.__init__(self,parameters) 
    348         self.parameters = self.translate(self.parameters)   
    349      
    350172 
    351173# ============================================================================== 
     
    14891311        raise Exception("Method not yet implemented") 
    14901312 
    1491 # ============================================================================== 
    1492 #   Connection method classes 
    1493 # ============================================================================== 
    1494  
    1495 class AllToAllConnector(common.AllToAllConnector, WDManager):     
    1496  
    1497     def connect(self, projection): 
    1498         weight = self.getWeight(self.weights) 
    1499         weight = self.convertWeight(weight, projection.synapse_type) 
    1500         delay  = self.getDelay(self.delays) 
    1501         postsynaptic_neurons  = projection.post.cell.flatten() 
    1502         target_list = postsynaptic_neurons.tolist() 
    1503         for pre in projection.pre.cell.flat: 
    1504             # if self connections are not allowed, check whether pre and post are the same 
    1505             if not self.allow_self_connections: 
    1506                 target_list = postsynaptic_neurons.tolist() 
    1507                 if pre in target_list: 
    1508                     target_list.remove(pre) 
    1509             N = len(target_list) 
    1510             if isinstance(weight, RandomDistribution): 
    1511                 weights = list(weight.next(N)) 
    1512             else: 
    1513                 weights = [weight]*N 
    1514             if isinstance(delay, RandomDistribution): 
    1515                 delays = list(delay.next(N)) 
    1516             else: 
    1517                 delays = [float(delay)]*N 
    1518             projection._targets += target_list 
    1519             projection._sources += [pre]*N 
    1520             #conn_dict = nest.GetConnections([pre], 'static_synapse')[0] 
    1521             projection._targetPorts += target_list 
    1522             nest.DivergentConnectWD([pre], target_list, weights, delays) 
    1523         return len(projection._targets) 
    1524  
    1525 class OneToOneConnector(common.OneToOneConnector, WDManager): 
    1526      
    1527     def connect(self, projection): 
    1528         weight = self.getWeight(self.weights) 
    1529         weight = self.convertWeight(weight, projection.synapse_type) 
    1530         delay  = self.getDelay(self.delays) 
    1531         if projection.pre.dim == projection.post.dim: 
    1532             projection._sources = projection.pre.cell.flatten() 
    1533             projection._targets = projection.post.cell.flatten() 
    1534             projection._targetPorts = projection.post.cell.flatten() 
    1535             N = len(projection._sources) 
    1536             if isinstance(weight, RandomDistribution): 
    1537                 weights = list(weight.next(N)) 
    1538             else: 
    1539                 weights = [weight]*N 
    1540             if isinstance(delay, RandomDistribution): 
    1541                 delays = list(delay.next(N)) 
    1542             else: 
    1543                 delays = [float(delay)]*N 
    1544             nest.ConnectWD(projection._sources, projection._targets, weights, delays) 
    1545             return projection.pre.size 
    1546         else: 
    1547             raise Exception("Connection method not yet implemented for the case where presynaptic and postsynaptic Populations have different sizes.") 
    1548      
    1549 class FixedProbabilityConnector(common.FixedProbabilityConnector, WDManager): 
    1550      
    1551     def connect(self, projection): 
    1552         weight = self.getWeight(self.weights) 
    1553         weight = self.convertWeight(weight, projection.synapse_type) 
    1554         delay  = self.getDelay(self.delays) 
    1555         postsynaptic_neurons  = projection.post.cell.flatten() 
    1556         npost= projection.post.size 
    1557         for pre in projection.pre.cell.flat: 
    1558             if projection.rng: 
    1559                 rarr = projection.rng.uniform(0,1,(npost,)) # what about NativeRNG? 
    1560             else: 
    1561                 rarr = numpy.random.uniform(0,1,(npost,)) 
    1562             target_list = numpy.compress(numpy.less(rarr,self.p_connect),postsynaptic_neurons).tolist() 
    1563             # if self connections are not allowed, check whether pre and post are the same 
    1564             if not self.allow_self_connections and pre in target_list: 
    1565                 target_list.remove(pre) 
    1566             N=len(target_list) 
    1567             if isinstance(weight, RandomDistribution): 
    1568                 weights = list(weight.next(N)) 
    1569             else: 
    1570                 weights = [weight]*N 
    1571             if isinstance(delay, RandomDistribution): 
    1572                 delays = list(delay.next(N)) 
    1573             else: 
    1574                 delays = [float(delay)]*N 
    1575             projection._targets += target_list 
    1576             projection._sources += [pre]*N 
    1577             projection._targetPorts += target_list 
    1578             nest.DivergentConnectWD([pre], target_list, weights, delays) 
    1579         return len(projection._sources) 
    1580      
    1581 class DistanceDependentProbabilityConnector(common.DistanceDependentProbabilityConnector, WDManager): 
    1582      
    1583     def connect(self, projection): 
    1584         weight = self.getWeight(self.weights) 
    1585         weight = self.convertWeight(weight, projection.synapse_type) 
    1586         delay  = self.getDelay(self.delays) 
    1587         periodic_boundaries = self.periodic_boundaries 
    1588         if periodic_boundaries is not None: 
    1589             dimensions = projection.post.dim 
    1590             periodic_boundaries = numpy.concatenate((dimensions,numpy.zeros(3-len(dimensions)))) 
    1591         postsynaptic_neurons = projection.post.cell.flatten() # array 
    1592         presynaptic_neurons  = projection.pre.cell.flat # iterator  
    1593         # what about NativeRNG? 
    1594         if projection.rng: 
    1595             if isinstance(projection.rng, NativeRNG): 
    1596                 print "Warning: use of NativeRNG not implemented. Using NumpyRNG" 
    1597                 rarr = numpy.random.uniform(0,1,(projection.pre.size*projection.post.size,)) 
    1598             else: 
    1599                 rarr = projection.rng.uniform(0,1,(projection.pre.size*projection.post.size,)) 
    1600         else: 
    1601             rarr = numpy.random.uniform(0,1,(projection.pre.size*projection.post.size,)) 
    1602         j = 0 
    1603         idx_post = 0 
    1604         for pre in presynaptic_neurons: 
    1605             target_list = [] 
    1606             idx_post = 0 
    1607             distances = common.distances(pre, projection.post, self.mask, self.scale_factor, self.offset, periodic_boundaries) 
    1608             for post in postsynaptic_neurons: 
    1609                 if self.allow_self_connections or pre != post:  
    1610                     # calculate the distance between the two cells : 
    1611                     d = distances[0][idx_post] 
    1612                     p = eval(self.d_expression) 
    1613                     if p >= 1 or (0 < p < 1 and rarr[j] < p): 
    1614                         target_list.append(post) 
    1615                         #projection._targets.append(post) 
    1616                         #projection._targetPorts.append(nest.connect(pre_addr,post_addr)) 
    1617                         #nest.ConnectWD([pre],[post], [weight], [delay]) 
    1618                 j += 1 
    1619                 idx_post += 1 
    1620             N = len(target_list) 
    1621             if isinstance(weight, RandomDistribution): 
    1622                 weights = list(weight.next(N)) 
    1623             else: 
    1624                 weights = [weight]*N 
    1625             if isinstance(delay, RandomDistribution): 
    1626                 delays = list(delay.next(N)) 
    1627             else: 
    1628                 delays = [float(delay)]*N 
    1629             projection._targets += target_list 
    1630             projection._sources += [pre]*N  
    1631             projection._targetPorts += target_list 
    1632             nest.DivergentConnectWD([pre], target_list, weights, delays) 
    1633         return len(projection._sources) 
    1634  
    1635  
    1636 class FixedNumberPreConnector(common.FixedNumberPreConnector): 
    1637      
    1638     def connect(self, projection): 
    1639         raise Exception("Not implemented yet !") 
    1640  
    1641  
    1642 class FixedNumberPostConnector(common.FixedNumberPostConnector): 
    1643      
    1644     def connect(self, projection): 
    1645         raise Exception("Not implemented yet !") 
    1646  
    16471313 
    16481314# ============================================================================== 
  • branches/multifile/src/neuron/__init__.py

    r164 r185  
    1111from pyNN.random import * 
    1212from math import * 
    13 from pyNN import __path__, common 
     13from pyNN import common 
     14from pyNN.neuron.cells import * 
     15from pyNN.neuron.connectors import * 
     16from pyNN.neuron.synapses import * 
     17from pyNN import __path__ 
    1418import os.path 
    1519import types 
     
    203207    return paramDict 
    204208 
    205  
    206  
    207209class HocToPy: 
    208210    """Static class to simplify getting variables from hoc.""" 
     
    233235            raise HocError("caused by HocToPy.bool('%s')" % condition) 
    234236        return HocToPy.hocvar 
    235  
    236 # ============================================================================== 
    237 #   Standard cells 
    238 # ============================================================================== 
    239   
    240 class IF_curr_alpha(common.IF_curr_alpha): 
    241     """Leaky integrate and fire model with fixed threshold and alpha-function- 
    242     shaped post-synaptic current.""" 
    243      
    244     translations = { 
    245         'tau_m'     : ('tau_m'    , "parameters['tau_m']"), 
    246         'cm'        : ('CM'       , "parameters['cm']"), 
    247         'v_rest'    : ('v_rest'   , "parameters['v_rest']"), 
    248         'v_thresh'  : ('v_thresh' , "parameters['v_thresh']"), 
    249         'v_reset'   : ('v_reset'  , "parameters['v_reset']"), 
    250         'tau_refrac': ('t_refrac' , "parameters['tau_refrac']"), 
    251         'i_offset'  : ('i_offset' , "parameters['i_offset']"), 
    252         'tau_syn_E' : ('tau_e'    , "parameters['tau_syn_E']"), 
    253         'tau_syn_I' : ('tau_i'    , "parameters['tau_syn_I']"), 
    254         'v_init'    : ('v_init'   , "parameters['v_init']"), 
    255     } 
    256     hoc_name = "StandardIF" 
    257      
    258     def __init__(self,parameters): 
    259         common.IF_curr_alpha.__init__(self,parameters) # checks supplied parameters and adds default 
    260                                                        # values for not-specified parameters. 
    261         self.parameters = self.translate(self.parameters) 
    262         self.parameters['syn_type']  = 'current' 
    263         self.parameters['syn_shape'] = 'alpha' 
    264  
    265 class IF_curr_exp(common.IF_curr_exp): 
    266     """Leaky integrate and fire model with fixed threshold and 
    267     decaying-exponential post-synaptic current. (Separate synaptic currents for 
    268     excitatory and inhibitory synapses.""" 
    269      
    270     translations = { 
    271         'tau_m'     : ('tau_m'    , "parameters['tau_m']"), 
    272         'cm'        : ('CM'       , "parameters['cm']"), 
    273         'v_rest'    : ('v_rest'   , "parameters['v_rest']"), 
    274         'v_thresh'  : ('v_thresh' , "parameters['v_thresh']"), 
    275         'v_reset'   : ('v_reset'  , "parameters['v_reset']"), 
    276         'tau_refrac': ('t_refrac' , "parameters['tau_refrac']"), 
    277         'i_offset'  : ('i_offset' , "parameters['i_offset']"), 
    278         'tau_syn_E' : ('tau_e'    , "parameters['tau_syn_E']"), 
    279         'tau_syn_I' : ('tau_i'    , "parameters['tau_syn_I']"), 
    280         'v_init'    : ('v_init'   , "parameters['v_init']"), 
    281     } 
    282     hoc_name = "StandardIF" 
    283      
    284     def __init__(self,parameters): 
    285         common.IF_curr_exp.__init__(self,parameters) 
    286         self.parameters = self.translate(self.parameters) 
    287         self.parameters['syn_type']  = 'current' 
    288         self.parameters['syn_shape'] = 'exp' 
    289  
    290  
    291 class IF_cond_alpha(common.IF_cond_alpha): 
    292     """Leaky integrate and fire model with fixed threshold and alpha-function- 
    293     shaped post-synaptic conductance.""" 
    294      
    295     translations = { 
    296         'tau_m'     : ('tau_m'    , "parameters['tau_m']"), 
    297         'cm'        : ('CM'       , "parameters['cm']"), 
    298         'v_rest'    : ('v_rest'   , "parameters['v_rest']"), 
    299         'v_thresh'  : ('v_thresh' , "parameters['v_thresh']"), 
    300         'v_reset'   : ('v_reset'  , "parameters['v_reset']"), 
    301         'tau_refrac': ('t_refrac' , "parameters['tau_refrac']"), 
    302         'i_offset'  : ('i_offset' , "parameters['i_offset']"), 
    303         'tau_syn_E' : ('tau_e'    , "parameters['tau_syn_E']"), 
    304         'tau_syn_I' : ('tau_i'    , "parameters['tau_syn_I']"), 
    305         'v_init'    : ('v_init'   , "parameters['v_init']"), 
    306         'e_rev_E'   : ('e_e'      , "parameters['e_rev_E']"), 
    307         'e_rev_I'   : ('e_i'      , "parameters['e_rev_I']") 
    308     } 
    309     hoc_name = "StandardIF" 
    310      
    311     def __init__(self,parameters): 
    312         common.IF_cond_alpha.__init__(self,parameters) # checks supplied parameters and adds default 
    313                                                        # values for not-specified parameters. 
    314         self.parameters = self.translate(self.parameters) 
    315         self.parameters['syn_type']  = 'conductance' 
    316         self.parameters['syn_shape'] = 'alpha' 
    317  
    318  
    319 class IF_cond_exp(common.IF_cond_exp): 
    320     """Leaky integrate and fire model with fixed threshold and  
    321     decaying-exponential post-synaptic conductance.""" 
    322      
    323     translations = { 
    324         'tau_m'     : ('tau_m'    , "parameters['tau_m']"), 
    325         'cm'        : ('CM'       , "parameters['cm']"), 
    326         'v_rest'    : ('v_rest'   , "parameters['v_rest']"), 
    327         'v_thresh'  : ('v_thresh' , "parameters['v_thresh']"), 
    328         'v_reset'   : ('v_reset'  , "parameters['v_reset']"), 
    329         'tau_refrac': ('t_refrac' , "parameters['tau_refrac']"), 
    330         'i_offset'  : ('i_offset' , "parameters['i_offset']"), 
    331         'tau_syn_E' : ('tau_e'    , "parameters['tau_syn_E']"), 
    332         'tau_syn_I' : ('tau_i'    , "parameters['tau_syn_I']"), 
    333         'v_init'    : ('v_init'   , "parameters['v_init']"), 
    334         'e_rev_E'   : ('e_e'      , "parameters['e_rev_E']"), 
    335         'e_rev_I'   : ('e_i'      , "parameters['e_rev_I']") 
    336     } 
    337     hoc_name = "StandardIF" 
    338      
    339     def __init__(self,parameters): 
    340         common.IF_cond_exp.__init__(self,parameters) # checks supplied parameters and adds default 
    341                                                        # values for not-specified parameters. 
    342         self.parameters = self.translate(self.parameters) 
    343         self.parameters['syn_type']  = 'conductance' 
    344         self.parameters['syn_shape'] = 'exp' 
    345  
    346 class SpikeSourcePoisson(common.SpikeSourcePoisson): 
    347     """Spike source, generating spikes according to a Poisson process.""" 
    348  
    349     translations = { 
    350         'start'    : ('start'  , "parameters['start']"), 
    351         'rate'     : ('number' , "int((parameters['rate']/1000.0)*parameters['duration'])"), 
    352         'duration' : ('number' , "int((parameters['rate']/1000.0)*parameters['duration'])") 
    353     } 
    354     hoc_name = 'SpikeSource' 
    355     
    356     def __init__(self,parameters): 
    357         common.SpikeSourcePoisson.__init__(self,parameters) 
    358         self.parameters = self.translate(self.parameters) 
    359         self.parameters['source_type'] = 'NetStim'     
    360         self.parameters['noise'] = 1 
    361  
    362     def translate(self,parameters): 
    363         translated_parameters = common.SpikeSourcePoisson.translate(self,parameters) 
    364         if parameters.has_key('rate') and parameters['rate'] != 0: 
    365             translated_parameters['interval'] = 1000.0/parameters['rate'] 
    366         return translated_parameters 
    367  
    368 class SpikeSourceArray(common.SpikeSourceArray): 
    369     """Spike source generating spikes at the times given in the spike_times array.""" 
    370  
    371     translations = { 
    372         'spike_times' : ('spiketimes' , "parameters['spike_times']"), 
    373     } 
    374     hoc_name = 'SpikeSource' 
    375      
    376     def __init__(self,parameters): 
    377         common.SpikeSourceArray.__init__(self,parameters) 
    378         self.parameters = self.translate(self.parameters)   
    379         self.parameters['source_type'] = 'VecStim' 
    380          
    381 class AdaptiveExponentialIF_alpha(common.AdaptiveExponentialIF_alpha): 
    382     """Adaptive exponential integrate and fire neuron according to Brette and Gerstner (2005)""" 
    383      
    384     translations = { 
    385         'v_init'    : ('v_init',   "parameters['v_init']"), 
    386         'w_init'    : ('w_init',   "parameters['w_init']"), 
    387         'cm'        : ('CM',       "parameters['cm']"), 
    388         'tau_refrac': ('Ref',      "parameters['tau_refrac']"),  
    389         'v_spike'   : ('Vspike',     "parameters['v_spike']"), 
    390         'v_reset'   : ('Vbot',     "parameters['v_reset']"), 
    391