Brian: a simulator for spiking neural networks in Python

monkeybeetleSoftware and s/w Development

Dec 2, 2013 (3 years and 4 months ago)

41 views

Brian: a simulator for spiking neural networks

in Python

Dan Goodman, Romain Brette


I
NTRODUCTION


Brian is a new project to create a
clock driven spiking
neural network simulator with the goal
s of being

easy to
learn

and
use
, highly flexible, and easy to
extend.

It is ideally suited to rapid prototyping and
refinement of
networks of single compartment model neurons
.

Brian

is written entirely in the Python
programming language

and will run on any platform that supports
Python

(i.e. almost all platforms)
.
Th
e
way it works is that
it

is

a Python
package

providing functions, classes and objects
.
It

can be used either
interactively using a Python shell, or as part of a
Python
program (
module
)
.


Background.

One of the difficulties with current software for neural

network simulation is that you have to
learn and use custom scripting languages for each tool
:

for example
Neuron’s Hoc and NMODL, NEST’
s
SLI, and

Genesis’

SLI
.

Th
is increases the learning curve

and is less flexible than using an established
language with

strong

support and development tools such as IDEs, debuggers and profilers. Data analysis is
either limited to those functions provided by the tool, or has to be carried out in another application such as
Matlab, which can slow down the process of prototy
ping and refining models. Writing extensions to these
tools can be rather difficult or somewhat inflexible, depending on whether extensions are written in the
same language as the simulator itself.


Standardisation using Python
.
To address this problem,
th
ere are projects in various stages of completion
to provide a Python interface for
e
ach of the
tools mentioned above.

B
ecau
se it is both easy and powerful,

Python
is rapidly becoming a standard tool in the field and in scientific computing more generally.
In
addition, the PyNN project is working to provide a
unified

Python
interface to
each simulator (currently
supported are Neuron, NEST and PCSIM).
These projects have considerable benefits. Users will only need
to learn a single programming language rather

than one or more for each tool, and that language is easy to
learn, highly developed, very powerful, and has a large user base which provides excellent support and
tools. A great deal of time can be saved working in just one environment, rather than havin
g to switch back
and forth between different applications and GUIs for developing models, running simulations and
analysing data.


The advantages of Brian.
Being written entirely in Python itself, Brian has all the advantages of the
projects above and some

additional ones. Integration with Python is tighter because the implementation is
not in a separate language to the interface. This means that Brian can be used more flexibly, for example if
you wanted to write code which reads and modifies the variables
of the simulation as it runs. Additionally,
extensions to Brian are easy to write because everything is written in the same language.


B
RIAN IN ACTION


The code below

defines, runs and plots
a randomly connected network of integrate and fire neurons with
e
xponential inhibitory and excitatory currents (the CUBA network from [1]):


from

Brian
import

*

# Define differential equations of model

dv

=
lambda

v,ge,gi:
(
ge+gi
-
(
v
+49
*mV
))
/
(
20
*ms
)

dge =
lambda

v,ge,gi:
-
ge/
(
5
*ms
)

dgi =
lambda

v,ge,gi:
-
gi/
(
10
*ms
)

# Cr
eate groups of neurons

P = NeuronGroup
(
4000
,model=
(
dv,dge,dgi
)
,threshold=
-
50
*mV,















reset=
-
60
*mV,init=
(
-
60
*mV,
0
*mV,
0
*mV
))

Pe = P.
subgroup(
3200
)

Pi = P.
subgroup(
800
)

# Define network structure

Ce = Connection
(
Pe, P,
'ge'
)

Ci = Connection
(
Pi, P,
'
gi'
)

Ce.
connectRandom(
Pe, P,
0.02
, weight=
1.62
*mV
)

Ci.
connectRandom(
Pi, P,
0.02
, weight=
-
9
*mV
)

# Keep track of which neurons have spiked

M = SpikeMonitor
(
P,
True
)

# Run the simulation

run
(
1
*second
)

# Plot the results

rasterPlot
(
M
)

show
()


The output can be
seen in Figure 1 below.


Figure
1
.
Raster plot of the CUBA network


O
VERVIEW


The procedure for writing a simulation with Brian is the same as for most neural network software. First
you define a neuron model, then you create some

neurons with that model, and finally you connect them
together.


Models.

At the moment, Brian provides three main ways of defining a neuron model: directly specifying
the differential equations

(including stochastic DEs)
, threshold

conditions and reset va
lues; using a standard
model or combination of standard components such as
ion channels and alpha function postsynaptic
currents; or providing code for the integration step directly. If you specify a differential equation, Brian can
automatically select an

appropriate integration method. For example linear DEs can be integrated exactly
and Brian will do this automatically (this is what happens when you run the CUBA network example
above).

Threshold conditions can be specified either statically, dynamically,

empirically or functionally.
Refractoriness and synaptic delays can also be used.
Connections can be specified by standard types (all to
all and random connectivity), by providing a connectivity matrix directly, or by writing a function to
generate the co
nnectivity matrix.


Performance.

Brian uses the NumPy and SciPy packages for Python to do highly optimized linear algebra.
Consequently, although there is a computational overhead for using Python


an interpreted language


compared to a compiled language

like C++, for large networks the performance is comparable. The CUBA
network example takes 3.5s to simulate 1s of biological time, which is 60% faster than using Matlab, and
only 25% slower than using C++.


A
SSORTED FEATURES


Units.

Brian has a system for

defining quantities with physical dimensions. Arithmetical operations and
equations are checked for dimensional consistency, which can help to eliminate hard to debug scaling
errors and mistakes in entering equations.


Automatic optimisation.

In some situ
ations, Brian can automatically and transparently generate and use
optimised C++ code from the definition of the model, providing a significant acceleration.


Control and monitoring.

All the internal variables of the simulator can be directly accessed to i
nitialise
the network or control it as it runs. Spikes and state variables can be monitored and either saved to a file or
used directly. Special neuron models are provided which allow you to specify exactly when a neuron fires a
spike either by code or by
passing a list of spike times.


Analysis and plotting.
Any Python package can be used in combination with Brian. This includes the
NumPy and SciPy scientific computing packages, and the PyLab graphics package which mirrors the
syntax of the Matlab plotting

commands.


L
IMITATIONS AND FUTUR
E DIRECTIONS


STDP.

One of the major missing features in the first release of Brian is STDP. Work is already under way
and this will be included in Brian as soon as possible.


Speed.

Although for large networks of linear ne
urons the performance of Brian is comparable to C++ code,
it is still slower for many tasks. Work is underway to provide more extensive use of automatic generation
of C++ code. In theory, by dynamically analysing the structure of the network before generat
ing the code,
and using optimisations tailored directly to that structure, Brian could do better than code written directly in
C++
.


Distributed computing.
Python has no built in support for distributed computing. There are various
packages that provide so
me support for it, but these are somewhat limited at the time of writing. One
possibility is to use the GPU for very fast vector computations. A Python package is being developed to
implement this, and Brian will use it when a more stable release is ready.


Multi
-
compartment

models.

Although it is theoretically possible to use these in Brian, it would not be
easy or efficient. This may be included in subsequent releases of Brian depending on feasibility and
demand.


Static analysis.

It should be possible in

some situations to provide mathematical analysis of the behaviour
of a network without actually running the simulation, based on its defining equations. This would be a
useful counterpart to running simulations, and to our knowledge is not included in any

existing software.


Standardisation.

We plan to implement the PyNN interface, and the NeuroML and FacetsML
specifications.


Realtime plotting.

We plan to add real
-
time plotting and other visualisation tools.


Database.
Depending on feasibility and demand,

we would like to implement an online searchable
database of models, networks, etc. This would be accessible directly from the Python command line or via
a web site.


R
EFERENCES


1.

Brette R, Rudolph M, Carnevale T, Hines M, Beeman D, Bower JM, Diesmann M, Mo
rrison A,
Goodman PH, Harris FC, et al.:
Simulation of networks of spiking neurons: a review of tools
and strategies
. J Comput Neurosci
2007,
23(3):
349
-
398.