Changeset 350

Show
Ignore:
Timestamp:
06/09/08 17:59:04 (5 months ago)
Author:
apdavison
Message:

More work on Freiburg lectures

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • doc/Freiburg2008/freiburg_PyNN_lectures.tex

    r321 r350  
    11% $Id:  $ 
    22\documentclass[utf8]{beamer} 
     3 
     4\includeonly{small_networks} 
    35 
    46\mode<presentation> 
  • doc/Freiburg2008/larger_networks.tex

    r321 r350  
    55\frametitle{Populations and Projections} 
    66 
    7 While it is entirely possible to create very large networks using only the \verb|create()|, \verb|connect()|, \verb|set()| and \verb|record()| functions, this involves writing a lot of repetitive code, which is the same or similar for every model: iterating over lists of cells and connections, creating common projection patterns, recording from all or a subset of neurons... 
    8 This sort of 'book-keeping' code takes time to write, obscures the essential principles of the simulation script with details, and, of course, the more code that has to be written, the more bugs and errors will be introduced, and, if the code is only used for a single project, not all the bugs may be found. 
     7\begin{block}{Problems with creating very large networks using \texttt{create()} and \texttt{connect}} 
     8\begin{itemize} 
     9\item involves writing a lot of repetitive code, which is the same or similar for every model: iterating over lists of cells and connections, creating common projection patterns, recording from all or a subset of neurons... 
     10\item this sort of `book-keeping' code takes time to write, obscures the essential principles of the simulation script with details 
     11\item and, of course, the more code that has to be written, the more bugs and errors will be introduced 
     12\item and, if the code is only used for a single project, not all the bugs may be found. 
     13\end{itemize} 
     14\end{block} 
    915 
    1016For these reasons, PyNN provides the \verb|Population| object, representing a group of neurons all of the same type (although possibly with cell-to-cell variations in the values of parameters), and the \verb|Projection| object, repesenting the set of connections between two \verb|Population|s. 
  • doc/Freiburg2008/small_networks.tex

    r321 r350  
    66 
    77Before using any other functions or classes from PyNN, the user must call the \verb|setup()| function: 
    8     \begin{verbatim} 
    9     >>> setup() 
    10     \end{verbatim} 
    11 \verb|setup()| takes various optional arguments: setting the simulation timestep (there is currently no support in the API for variable timestep methods although native simulator code can be used to select this option where the simulator supports it), setting the minimum and maximum synaptic delays, and turning debugging output on and off, e.g.: 
    12     \begin{verbatim} 
    13     >>> setup(timestep=0.1, min_delay=0.1, max_delay=0.5, debug=False) 
    14     \end{verbatim}     
    15 Debugging information is written to a log file in the working directory. 
     8\begin{verbatim} 
     9>>> setup(timestep=0.1, min_delay=0.1,  
     10          max_delay=0.5, debug=False) 
     11\end{verbatim} 
     12 
     13Some simulators accept additional arguments, e.g. 
     14\begin{verbatim} 
     15>>> setup(threads=2)               # nest2, pcsim 
     16\end{verbatim} 
     17 
     18\begin{verbatim} 
     19>>> setup(rngseeds=[12345,67890])  # nest2 
     20\end{verbatim} 
    1621 
    1722\end{frame} 
     
    2530    >>> create(IF_curr_alpha) 
    2631    \end{verbatim} 
    27 Here, \verb|IF_curr_alpha| is a particular class of IF neuron with alpha-function shaped synaptic currents, that will work with any PyNN simulation engine, whether NEURON, NEST or PCSIM. 
    28 \verb|IF_curr_alpha| is a so-called 'standard cell', implemented as a Python class. 
    29 For more information, see the section StandardCells. 
     32Here, \verb|IF_curr_alpha| is a so-called 'standard cell', which will work with any PyNN backend, whether NEURON, NEST or PCSIM.\vspace{1ex} 
    3033 
    3134You don't have to use standard cells. 
    3235You can also use any neuron model that is available in an individual simulator, although of course your simulation will then only run with that simulator, for example: 
    3336    \begin{verbatim} 
    34     >>> create('iaf_neuron') 
    35     \end{verbatim}     
    36 \verb|iaf_neuron| is a neuron model available in the NEST simulator. 
    37 Note that the model name has to be given as a string for simulator-specific models. 
    38  
    39 To create many neurons at once, add the \verb|n| argument, e.g.     
    40     \begin{verbatim} 
    41     >>> create(IF_curr_alpha, n=10) 
    42     \end{verbatim}     
     37    >>> create("iaf_neuron")  # NEST only 
     38    \end{verbatim}     
     39 
     40\end{frame} 
     41 
     42 
     43\begin{frame}[fragile] % ------------------------------------------------------------ 
     44\frametitle{Creating neurons} 
     45 
     46To create many neurons at once, add the \verb|n| argument:     
     47    \begin{verbatim} 
     48    >>> create(IF_curr_alpha, n=10)\end{verbatim}     
    4349The neurons we have created so far have all had default parameter values,  
    44 stored in the \verb|default_values| of the standard cell class, e.g.: 
    45     \begin{verbatim} 
    46     >>> IF_curr_alpha.default_parameters #doctest" +NORMALIZE_WHITESPACE 
    47     {'tau_refrac': 0.0, 'tau_m': 20.0, 'i_offset': 0.0, 'cm': 1.0, 'v_init': -65.0, 
    48      'v_thresh': -50.0, 'tau_syn_E': 0.5, 'v_rest': -65.0, 'tau_syn_I': 0.5, 
    49      'v_reset': -65.0} 
    50     \end{verbatim} 
    51 To use different parameter values, use the \verb|param_dict| argument, e.g.: 
    52     \begin{verbatim} 
    53     >>> create(IF_curr_alpha, param_dict={'tau_m': 15.0, 'cm': 0.9}, n=10) 
    54     \end{verbatim} 
     50stored in the \verb|default_values| of the standard cell class: 
     51    \begin{verbatim} 
     52    >>> IF_curr_alpha.default_parameters 
     53    {'tau_refrac': 0.0, 'tau_m': 20.0, 'i_offset': 0.0,  
     54     'cm': 1.0, 'v_init': -65.0, 'v_thresh': -50.0,  
     55     'tau_syn_E': 0.5, 'v_rest': -65.0, 'tau_syn_I': 0.5, 
     56     'v_reset': -65.0}\end{verbatim} 
     57To use different parameter values, use the \verb|param_dict| argument: 
     58    \begin{verbatim} 
     59    >>> create(IF_curr_alpha,  
     60               param_dict={'tau_m': 15.0, 'cm': 0.9}, 
     61               n=10) 
     62    \end{verbatim} 
     63     
     64\end{frame} 
     65 
     66 
     67\begin{frame}[fragile] % ------------------------------------------------------------ 
     68\frametitle{Creating neurons} 
     69 
    5570If you try to set a non-existent parameter, or pass an invalid value, PyNN will raise an Exception, e.g.: 
    56     \begin{verbatim} 
    57     >>> create(IF_curr_alpha, param_dict={'foo': 15.0}) 
    58     Traceback (most recent call last): 
    59       File "<stdin>", line 1, in ? 
    60       File "/usr/lib/python/site-packages/pyNN/nest1.py", line 228, in create 
    61         celltype = cellclass(param_dict) 
    62       File "/usr/lib/python/site-packages/pyNN/nest1.py", line 68, in __init__ 
    63         common.IF_curr_alpha.__init__(self,parameters) # checks supplied parameters and adds default 
    64       File "/usr/lib/python/site-packages/pyNN/common.py", line 113, in __init__ 
    65         self.parameters = self.checkParameters(parameters, with_defaults=True) 
    66       File "/usr/lib/python/site-packages/pyNN/common.py", line 99, in checkParameters 
    67         raise NonExistentParameterError(k) 
    68     NonExistentParameterError: foo 
    69     >>> create(IF_curr_alpha, param_dict={'tau_m': 'bar'}) 
    70     Traceback (most recent call last): 
    71       File "/usr/lib/python/site-packages/pyNN/nest1.py", line 228, in create 
    72         celltype = cellclass(param_dict) 
    73       File "/usr/lib/python/site-packages/pyNN/nest1.py", line 68, in __init__ 
    74         common.IF_curr_alpha.__init__(self,parameters) # checks supplied parameters and adds default 
    75       File "/usr/lib/python/site-packages/pyNN/common.py", line 113, in __init__ 
    76         self.parameters = self.checkParameters(parameters, with_defaults=True) 
    77       File "/usr/lib/python/site-packages/pyNN/common.py", line 90, in checkParameters 
    78         raise InvalidParameterValueError, (type(supplied_parameters[k]), type(default_parameters[k])) 
    79     InvalidParameterValueError: (<type 'str'>, <type 'float'>) 
    80     \end{verbatim} 
    81      
     71   \begin{verbatim} 
     72>>> create(IF_curr_alpha, param_dict={'foo': 15.0}) 
     73Traceback (most recent call last): 
     74. . . 
     75NonExistentParameterError: foo 
     76    
     77>>> create(IF_curr_alpha, param_dict={'tau_m': 'bar'}) 
     78Traceback (most recent call last): 
     79. . . 
     80InvalidParameterValueError: (<type 'str'>, <type 'float'>) 
     81    \end{verbatim} 
     82 
     83\end{frame} 
     84 
     85 
     86\begin{frame}[fragile] % ------------------------------------------------------------ 
     87\frametitle{Creating neurons} 
    8288If you wish to do something with the cell after creating it: record from it, change a parameter, connect it to another cell, you should assign the return value of the function to a variable, e.g.: 
    8389    \begin{verbatim} 
     
    8591    >>> cell_list = create(IF_curr_alpha, n=10) 
    8692    \end{verbatim} 
    87 The \verb|create()| function returns either a cell id object or a list of id objects. 
     93 
    8894 
    8995\end{frame} 
     
    95101Any neuron that emits spikes can be connected to any neuron with at least one synapse using the \verb|connect()| function, e.g.: 
    96102    \begin{verbatim} 
    97     >>> spike_source = create(SpikeSourceArray, param_dict={'spike_times': [10.0, 20.0, 30.0]}) 
    98     >>> cell_list2 = create(IF_curr_exp, n=10) 
    99     >>> connect(spike_source, cell_list2) 
    100     \end{verbatim}     
    101 In this case we connect a spike-generating mechanism (\verb|SpikeSourceArray| is a 'standard cell' model that emits spikes at times specified by the \verb|spike_times| parameter) to each cell in the list \verb|cells|, i.e. we create 10 connections at once. 
     103>>> times = [10.0, 20.0, 30.0] 
     104>>> spike_source = create(SpikeSourceArray,  
     105                          {'spike_times': times}) 
     106>>> cell_list2 = create(IF_curr_exp, n=10) 
     107>>> connect(spike_source, cell_list2)\end{verbatim}     
     108In this case we connect a spike-generating mechanism to each cell in the list \verb|cells|, i.e. we create 10 connections at once. 
     109\end{frame} 
     110 
     111 
     112\begin{frame}[fragile] % -------------------------------------------------------------------- 
     113\frametitle{Connecting neurons} 
    102114For clarity, we could also have specified the argument names: 
    103115    \begin{verbatim} 
    104     >>> connect(source=spike_source, target=cell_list2) 
    105     \end{verbatim}     
     116  >>> connect(source=spike_source, target=cell_list2)\end{verbatim}     
    106117Either \verb|source| or \verb|target| or both may be individual cell ids or lists of ids. 
    107 In the latter case, each source (presynaptic) cell is connected to every target (postsynaptic) cell with probability given by the optional argument `p`, which defaults to 1, e.g.: 
    108     \begin{verbatim} 
    109     >>> source_list = cell_list 
    110     >>> target_list = cell_list2 
    111     >>> connect(source_list, target_list, p=0.5) 
    112     \end{verbatim}     
    113 When specifying connections as above, default values are given to the synaptic weight and delay. 
    114 These values are seldom very useful, and it is better to specify the \verb|weight| and \verb|delay| arguments of \verb|connect()|, e.g.: 
    115     \begin{verbatim} 
    116     >>> connect(source_list, target_list, weight=1.5, delay=0.5) 
    117     \end{verbatim}     
    118 Weights are specified in nA for 'current-based' synapses or $\mu$S for 'conductance-based' synapses. 
     118In the latter case, each source (presynaptic) cell is connected to every target (postsynaptic) cell with probability given by the optional argument \verb|p|, which defaults to 1, e.g.: 
     119    \begin{verbatim} 
     120  >>> source_list = cell_list 
     121  >>> target_list = cell_list2 
     122  >>> connect(source_list, target_list, p=0.5) 
     123    \end{verbatim} 
     124\end{frame} 
     125 
     126 
     127\begin{frame}[fragile] % -------------------------------------------------------------------- 
     128\frametitle{Connecting neurons} 
     129\framesubtitle{Specifying weights and delays} 
     130 
     131    \begin{verbatim} 
     132  >>> connect(source_list, target_list,  
     133              weight=1.5, delay=0.5)\end{verbatim}    
     134                
     135{\footnotesize (Weights are in nA for 'current-based' synapses or $\mu$S for 'conductance-based' synapses. 
    119136Delays are in ms. 
    120137For current-based synapses, weights should be negative for inhibitory synapses. 
    121 For conductance-based synapses, weights should always be positive, since the effect of a synapse is determined by its reversal potential. 
     138For conductance-based synapses, weights should always be positive, since the effect of a synapse is determined by its reversal potential.)} 
    122139 
    123140If the neuron model has more than one synapse mechanism, or more than one synaptic location, the particular synapse to which the connection should be made is specified with the \verb|synapse_type| argument, e.g.: 
    124141    \begin{verbatim} 
    125     >>> connect(source_list, target_list, weight=1.5, delay=0.5, synapse_type='inhibitory') 
    126     \end{verbatim} 
    127 [How to find out what synapse types a standard cell has?] 
     142    >>> connect(source_list, target_list,  
     143                weight=1.5, delay=0.5,  
     144                synapse_type='inhibitory') 
     145    \end{verbatim} 
    128146 
    129147\end{frame} 
     
    132150\begin{frame}[fragile] % -------------------------------------------------------------------- 
    133151\frametitle{Setting neuron parameters} 
    134  
    135 There are many ways to change the parameters for individual neurons and post-synaptic mechanisms after creation of the neuron. 
    136 To change a single parameter of a single neuron, just set the relevant attribute of the neuron ID object, e.g.: 
    137     \begin{verbatim} 
    138     >>> cells = create(IF_curr_exp, param_dict={'v_init': -70.0}, n=10) 
     152\framesubtitle{for a single cell} 
     153 
     154To change a single parameter of a single neuron, set the relevant attribute of the neuron ID object, e.g.: 
     155    \begin{verbatim} 
     156    >>> cells = create(IF_curr_exp, n=10) 
    139157    >>> cells[0].tau_m 
    140158    20.0 
    141159    >>> cells[0].tau_m = 15 
    142160    >>> cells[0].tau_m 
    143     15.0 
    144     \end{verbatim}     
     161    15.0\end{verbatim}     
    145162To change several parameters at once for a single neuron, use the \verb|set_parameters()| method of the neuron ID, e.g.: 
    146163    \begin{verbatim} 
     
    149166    10.0 
    150167    >>> cells[1].cm 
    151     0.5 
    152     \end{verbatim} 
     168    0.5\end{verbatim} 
     169     
     170\end{frame} 
     171 
     172\begin{frame}[fragile] % -------------------------------------------------------------------- 
     173\frametitle{Setting neuron parameters} 
     174\framesubtitle{for several cells at once} 
    153175To change parameters for several cells at once, use the \verb|set()| function, e.g.: 
    154176    \begin{verbatim} 
     
    157179    -65.0 
    158180    >>> print cells[5].v_init 
    159     -70.0 
    160     \end{verbatim}     
     181    -70.0\end{verbatim}     
    161182Individual parameters can be set using the \verb|param| and \verb|val| arguments, as above, or multiple parameters can be set at once by passing a dictionary of name:value pairs as the \verb|param| argument, with \verb|val| empty, e.g.: 
    162183    \begin{verbatim} 
    163     >>> set(cells, param={'tau_refrac': 2.0, 'tau_syn_E': 5.0}) 
     184    >>> set(cells, param={'tau_refrac': 2.0,  
     185                          'tau_syn_E': 5.0}) 
    164186    \end{verbatim} 
    165187\end{frame} 
     
    195217By default, all simulators write data files in the same format. 
    196218 
    197 The beginning of a typical spike file looks like: 
    198     \begin{verbatim} 
    199     # dt = 0.1 
    200     # n = 1000 
    201     0.0     2 
    202     0.3     5 
    203     0.4     3 
    204     0.9     2 
    205     1.0     1 
    206     . . . 
    207     \end{verbatim}     
    208 The beginning of a typical membrane potential file looks like: 
    209     \begin{verbatim} 
    210     # dt = 0.1 
    211     # n = 1000 
    212     -65.0   0 
    213     -64.9   0 
    214     -64.7   0 
    215     -64.5   0 
    216     . . . 
    217     \end{verbatim} 
    218 Both file types begin with header lines giving the timestep (there is currently no support for variable-time step recording) and the number of data points in the file. 
    219 Each line of the spike file then gives the occurence time of a spike (in ms) and the id of the neuron in which it was recorded. 
    220 Each line of the membrane potential file gives the membrane potential (in mV) followed by the id of the neuron in which it was recorded. 
    221 In both cases, whether the file is sorted by cell id or by time depends on the simulator: it is not standardised. 
    222  
    223 In some cases it is more efficient to write files in the simulator's native format, rather than the standard PyNN format. 
    224 In this case, use the \verb|compatible_output=False| argument to the \verb|end()| function. 
    225  
    226 Considerable enhancements to file formats are planned for future releases of PyNN, including recording to binary (HDF5) rather than text files, support for variable time-step recording, and user-specified output formats. 
    227  
     219Typical spike file  Typical membrane potential file 
     220    \begin{verbatim} 
     221    # dt = 0.1             # dt = 0.1 
     222    # n = 1000             # n = 10000 
     223    0.0     2              -65.0   0 
     224    0.3     5              -64.9   0 
     225    0.4     3              -64.7   0 
     226    0.9     2              -64.5   0 
     227    . . .                  . . . 
     228    \end{verbatim}     
     229 
     230\end{frame} 
     231 
     232 
     233\begin{frame}[fragile] % -------------------------------------------------------------------- 
     234\frametitle{Recording spikes and membrane potential} 
     235 
     236\small 
     237\begin{itemize} 
     238\item Header contains the timestep (no support for variable-timestep recording) and the number of data points in the file. 
     239\item Each line of the spike file gives the occurence time of a spike (in ms) and the id of the neuron in which it was recorded. 
     240\item Each line of the membrane potential file gives the membrane potential (in mV) followed by the id of the neuron in which it was recorded. 
     241\item Whether the file is sorted by cell id or by time depends on the simulator: it is not standardised. 
     242\item In some cases it is more efficient to write files in the simulator's native format, rather than the standard PyNN format. 
     243In this case, use \verb|end(compatible_output=False)| function. 
     244\item Enhancements to file formats in future releases of PyNN: recording to binary files (HDF5), support for variable time-step recording, and user-specified output formats. 
     245\end{itemize} 
    228246\end{frame} 
    229247 
     
    241259\begin{frame}[fragile] % -------------------------------------------------------------------- 
    242260\frametitle{Finishing up} 
    243  
    244 Just as a simulation must be begun with a call to \verb|setup()|, it must be ended with a call to \verb|end()|. 
    245  
    246 \end{frame} 
    247  
     261\centering 
     262\verb|>>> end()| 
     263 
     264\end{frame} 
     265 
  • doc/Freiburg2008/standard_celltypes.tex

    r321 r350  
    66\frametitle{Standard cell types} 
    77 
    8 Standard models are neuron models that are available in at least two of the simulation engines supported by PyNN. 
    9  
    10 PyNN performs automatic translation of parameter names, types and units. 
    11  
    12 To obtain a list of all the standard models available in a given simulator, use the \verb|list_standard_models()| function, e.g.: 
    13         \begin{verbatim} 
    14     >>> from pyNN import nest2, neuron 
    15     >>> nest2.list_standard_models() 
    16     [] 
     8\begin{itemize} 
     9\item Standard models are neuron models that are available in at least two of the simulation engines supported by PyNN. 
     10\item PyNN performs automatic translation of parameter names, types and units. 
     11\end{itemize}  
     12\begin{verbatim} 
     13    >>> from pyNN import neuron 
    1714    >>> neuron.list_standard_models() 
    18     [] 
     15    [<class 'pyNN.neuron.cells.IF_cond_alpha'>,  
     16     <class 'pyNN.neuron.cells.IF_curr_exp'>,  
     17     <class 'pyNN.neuron.cells.SpikeSourceArray'>,  
     18     <class 'pyNN.neuron.cells.IF_cond_exp'>,  
     19     <class 'pyNN.neuron.cells.IF_facets_hardware1'>,  
     20     <class 'pyNN.neuron.cells.SpikeSourcePoisson'>,  
     21     <class 'pyNN.neuron.cells.EIF_cond_alpha_isfa_ista'>,  
     22     <class 'pyNN.neuron.cells.IF_curr_alpha'>] 
    1923    \end{verbatim} 
    2024