Powerpoint slides without audio

advertisement
Simulation of spiking neural networks
BRIAN
http://www.briansimulator.org
The spirit of
“A simulator should not only save the time of
processors, but also the time of scientists”
scientist
computer
Writing code often takes more time than running it
Goals:
• Quick model coding
• Flexible
models are defined by equations
(rather than pre-defined)
An example from systems
neuroscience
Sturzl, W., R. Kempter, and J. L. van Hemmen (2000, June). Theory of
arachnid prey localization. Physical Review Letters 84 (24), 5668{71. PMID:
10991021
Learning Brian
• 1 hour is not long enough for me to say everything
• Will include detailed slides, but talk in a more general
way
• You can download the slides and go through it in
more detail later (from Telluride website or Brian
website)
• Also look at the documentation page on the Brian
website
• Use the Brian email list for questions
Installing Brian
• Instructions for installing Brian on our webpage:
– http://www.briansimulator.org/docs/installation.html
• Recommend using Python(x,y) for Windows users
– http://www.pythonxy.com
– Includes all packages, various IDEs, etc.
– Brian available as a plugin, or can be downloaded
separately.
Python
• No time to introduce Python programming language,
but there is an excellent tutorial online:
– http://docs.python.org/tutorial/
• For scientific work, use the NumPy (numerical), SciPy
(scientific) and Pylab/Matplotlib (plotting) libraries.
Documentation (including tutorials) available online:
– http://docs.scipy.org/doc/
Anatomy of a Brian script
Import the Brian package
Define some parameters, you
Define neuron equations,
can use physical units
the “volt” term says that V
has units of volts, and
Brian
the – here
Createchecks
synapses
Create
neurons
with given
consistency
of your
recurrent random
equations
and fixed threshold
equations.
connectivity with probability
and reset value.
.1 for each pair of neurons
and given synaptic weight,
spikes cause an
Record spiking activity
instantaneous increase of
amount
in variable
Initialiseweight
state variables
to V
of
the target
neuron
random
values.
Run simulation
Analyse results – do a raster
plot
Units system
•
•
•
•
Standard SI names like volt, amp, etc.
Standard SI prefixes, mvolt, namp, etc.
Some short names: mV, ms, nA, etc.
Consistency checking:
– 3*mV+2*nA will raise an exception
– “dV/dt = -V” will raise an exception (RHS should have units
of volt/second)
– Useful for catching hard to find bugs
– Can be switched off globally:
• import brian_no_units before importing Brian
Defining a neuron model: Equations
• Equations, each of one of the following forms:
–
–
–
–
dx/dt = -x/tau : volt
y = x*x : volt2
z = y
w : unit
differential equation
equation
alias
parameter
• Non-autonomous equations, use the reserved symbol “t” for time
• Stochastic DEs
– Use the term “xi” for noise with:  (s), (t )   (s  t )
– Has units s-1/2 - use typically as “sigma*xi*(2/tau)**0.5”
• Can also get equations from brian.library, but won’t cover
this here
• Solvers:
–
–
–
–
Exact for linear DEs (detected automatically)
Euler for nonlinear DEs (method=‘Euler’)
2nd order Runge-Kutta (method=‘RK’)
Exponential Euler (method=‘exponential_Euler’)
NeuronGroup creation
group = NeuronGroup(N, eqs, reset=…, threshold=…, refractory=…, method=…)
• Resets
– Single value
– String with Python statement(s),
e.g.
• ‘V=Vr’ where Vr could be a constant
or another state variable
• ‘Vt += dVt; V=Vr’ where Vt is another
state variable
• ‘V=Vr+rand()*sigma’ (rand and randn
are known)
– Arbitrary Python function f(group,
spikes)
• Refractory
– Single value, note that this only
works with single valued resets,
otherwise it is ambiguous. In other
cases, use CustomRefractoriness
(see docs)
• Threshold
– Single value
– String with Python expression, e.g.
• ‘V>=Vt’ where Vt could be a constant
or another state variable
• ‘V+sigma*rand()>=Vt’ (will be in the
next release of Brian)
– Arbitrary Python function f(var1,
var2, …) should return array of
spike indices
– EmpiricalThreshold(thresh, refrac)
fires a spike if V>thresh but won’t
fire another spike for period refrac,
used for models without an
instantaneous reset (e.g. HH)
Example: adaptive threshold
More on groups
• Subgroups
–
–
–
–
–
subgp = group.subgroup(N)
subgp = group[i:j]
Can be used whenever a group is used
Use to structure network (e.g. into layers)
More computationally efficient to use one large group with several
subgroups than to use several small groups
• State variables
– Access by name, e.g. group.V, group.ge, group.I
• Standard groups
– PoissonGroup(N, rates) – N neurons firing with given rates (scalar or
vector, can be changed during a run)
– SpikeGeneratorGroup(N, spikes) – N neurons that fire spikes specified
by the user in the form spikes=[(i1, t1), (i2, t2), …]
– PulsePacket(t, N, sigma) – N neurons firing at Gaussian dist. times
Connections
• C = Connection(source, target, var)
– Synapses from source group to target group acting on
state variable var.
– Weight matrix C.W
– When neuron i in source fires:
• target.var[j] += C.W[i, j] for each j
• Features (next slides):
– Building connectivity (full, random, custom)
– Delays (homogeneous, heterogeneous)
– Weight matrix structures (dense, sparse)
Building connectivity
• C.connect_full(source, target, weight)
– Source and target can be whole group or subgroups
– weight can be single value, matrix or function w(i,j)
• C.connect_random(source, target, p, weight)
– p is the probability of synapse between i and j.
– weight can be single value or function w(i, j)
• C.connect_one_to_one(source, target, weight)
– weight has to be a single value
• Multiple connect_* calls allowed for different subgroups,
etc.
• Can build or modify connectivity by hand, e.g.:
– for i in range(N): C.W[i, :] = N-abs(i-arange(N))
Delays
• Connection(…, delay=…, max_delay=…)
– Fixed constant, all synapses have the same (axonal) delay – no
need to specify max_delay
– delay=True, each synapse has its own delay, have to specify the
maximum delay (larger uses more memory)
• Specifying delays
– Each C.connect_* method has a new delay keyword, which can
have different values:
•
•
•
•
•
Scalar, all delays equal
Pair (min, max) uniformly distributed
Function f() called for each synapse
Function f(i, j) called for each synapse
Matrix
– Specify by hand, C.delay[i,j] = …
Matrix structures
• C = Connection(…, structure=…)
• ‘dense’
– Numpy 2D array
– Uses 8NM bytes for matrix of shape (N,M)
• ‘sparse’
– Sparse matrix class with fast row access and reasonable column access
– Uses 20 bytes per nonzero entry (12 bytes if column access not
required)
– Cannot be changed at runtime
• ‘dynamic’
– Sparse matrix class with reasonable row and column access speeds
– Uses 24 bytes per nonzero entry
– Can be changed at runtime
Example: synfire chain
Plasticity
• STDP
– stdp = ExponentialSTDP(C,
taupre, taupost, deltapre,
deltapost, …)
– stdp = STDP(C, …)
• See docs
• STP
– stp = STP(C, taud, tauf, U)
• Tsodyks-Markram model (see docs)
Recording activity
• Spikes
– M = SpikeMonitor(group)
• M.spikes = [(i1, t1), (i2, t2), …]
– M = SpikeCounter(group)
• M.count = [count0, count1, …]
• M.nspikes
– PopulationSpikeCounter,
StateSpikeMonitor
• See docs
• Others
– ISIHistogramMonitor
– PopulationRateMonitor
– See docs
• State variables
– M=StateMonitor(group, var,
record=…)
• Records values of variable var
in group
• Record=
– True, record all neurons (lots
of memory)
– [i1,i2,…], record given
neurons
– False (default), only record
summary stats
• M.plot()
• M[i] array of recorded values
for neuron i
• M.times array of recording
times
• M.var, M.std summary stats
Network operations
• Generic mechanism for online control of simulation
• @network_operation(when=‘start’)
def f():
…
• Function f is called every time step, can do anything
• Example: stop a network from running if too many spikes
being produced:
– …
M=PopulationSpikeCounter(G)
…
@network_operation
def check_too_many_spikes():
if M.nspikes>1000:
stop()
Simulation control
• run(duration) creates network of all created objects
• net = Network(obj1, obj2, …) for finer control, then call
net.run(duration)
• stop() and net.stop()
• reinit() and net.reinit()
• forget(obj) stops run() from using obj
• recall(obj) lets run() use obj again
• clear() forgets all objects, clear(True) forgets and
deletes memory associated to all objects (useful for
doing multiple runs)
Clocks
• By default, Brian uses ‘defaultclock’:
– defaultclock.t = 0*ms
– defaultclock.dt = 0.1*ms
• Can use multiple clocks if some objects need to
be simulated with smaller dt than others
• Create clock with clk = Clock(dt=1*ms)
• Use clock for object with obj=Obj(…, clock=clk)
• If using only one clock, don’t need to specify, if
using multiple clocks, you have to specify for
every object
Analysis packages
• Brian has some statistical tools for spike trains:
CVs, correlelograms, etc.
– http://www.briansimulator.org/docs/analysis.html#st
atistics
• NeuroTools is a set of Python packages for
analysing neuroscientific data
– http://neuralensemble.org/trac/NeuroTools
– Disclaimer: I haven’t used it myself
• The INCF maintains a list of relevant software
– http://software.incf.org/software/
– Disclaimer: likewise
Optimisations
• Use C code
– Build optional C modules
– Set the global preference useweave=True for more C code
if you have gcc or Visual Studio installed
– http://www.briansimulator.org/docs/compiledcode.html
• Vectorise your code
– http://www.briansimulator.org/docs/efficient.html
• Soon: use ‘code generation’ (not yet documented)
Model fitting toolbox
• Automatically fit
spiking neuron
models to
electrophysiological
data
• Uses particle swarm
optimisation
• Adding genetic
algorithms and
others
• Can use GPU for 60x
speed improvement
Rossant et al., Automatic fitting of spiking neuron
models to electrophysiological recordings, Front.
Neuroinformatics (2010)
“Brian hears” (soon)
• Library for auditory modelling
• Filtering
– High pass, low pass, band pass, etc.
– Gammatone, gammachirp, etc.
– Head related transfer functions (HRTFs)
• Standard neuron models
– Meddis, Lyons, etc.
• All in Brian framework
GPUs
• Graphics processing units
– Originally made for computer games (and therefore
cheap)
– Now being used for high-performance scientific
computing
– Many cores (up to 240 at the moment) but each must
do similar computations (like SIMD, but slightly better)
• Huge potential speed improvements
– Existing papers (early work) show 8-80x improvement
– In model fitting library we have 60x improvement
– Currently shows a 30x improvement in general case
Thanks!
http://www.briansimulator.org
Download