+ All Categories
Home > Documents > Romain Brette & Dan Goodman Ecole Normale Supérieure Equipe Audition

Romain Brette & Dan Goodman Ecole Normale Supérieure Equipe Audition

Date post: 01-Jan-2016
Category:
Upload: lesley-matthews
View: 23 times
Download: 2 times
Share this document with a friend
Description:
http://www.briansimulator.org. Romain Brette & Dan Goodman Ecole Normale Supérieure Equipe Audition. [email protected] [email protected]. The spirit of. Goals: Quick model coding Flexible. “ A simulator should not only save the time of processors, but also the time of scientists ”. - PowerPoint PPT Presentation
58
Romain Brette & Dan Goodman Ecole Normale Supérieure Equipe Audition http://www.briansimulator.org [email protected] [email protected]
Transcript
Page 1: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

Romain Brette & Dan Goodman Ecole Normale SupérieureEquipe Audition

http://www.briansimulator.org

[email protected] [email protected]

Page 2: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

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)

Page 3: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

An example

Pi Pe

Ce

CiP

briansimulator.orgbriansimulator.org

Page 4: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

briansimulator.org, click Download

We have Windows versions on USB sticks (ask Dan)We have Windows versions on USB sticks (ask Dan)

Installation

Download slides and examples: click Blog and Brian at NeuroComp

Download slides and examples: click Blog and Brian at NeuroComp

Page 5: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

does an adaptive threshold

from brian import *

eqs = '''dv/dt = -v/(10*ms) : voltdvt/dt = (10*mV-vt)/(15*ms) : volt'''

reset = '''v = 0*mVvt += 3*mV'''

IF = NeuronGroup(1, eqs, reset=reset, threshold='v>vt')IF.rest()PG = PoissonGroup(1, 500*Hz)

C = Connection(PG, IF, 'v', weight=3*mV)

run(100*ms)

Page 6: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

does synaptic plasticity

Song, S., K. D. Miller, and L. F. Abbott (2000). Competitive hebbian learning through spike timing-dependent synaptic plasticity. Nature Neurosci 3, 919-26.

Page 7: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

does systems neuroscience

Sturzl, W., R. Kempter, and J. L. van Hemmen (2000). Theory of arachnid prey localization. Physical Review Letters 84 (24), 5668

Page 8: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

Work in progress Parallel computing with graphics processing units

(GPUs) Up to 240 processors Up to 100x speed improvement Cheap hardware (a few €100) Good for vectorised code

If you want to contribute:http://groups.google.fr/group/brian-on-gpu

Page 9: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

Python in 15 minutes

see also: http://docs.python.org/tutorial/

Page 10: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

The Python console On Windows, open IDLE. On Linux: type python

interpreted language dynamic typing garbage collector space matters (signals structure) object-oriented many libraries

Page 11: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

Writing a script If you use IDLE, click on File>New window.

Otherwise use any text editor.

Press F5 to execute

Page 12: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

A simple program

# Factorial functiondef factorial(x): if x == 0: return 1 else: return x * factorial(x-1)

print factorial(5)

commentfunction definitionuntyped argument

condition

function calldisplay

structure by indentation(block = aligned instructions)

Page 13: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

Numerical objects Base types: int, long, float, complex

Other numerical types (vectors, matrices) defined in the Numpy library (in a few minutes)

x=3+2x+=1y=100Lz=x*(1+2j)u=2.3/7x,y,z = 1,2,3a = b = 123

Page 14: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

Control structures

x = 12if x < 5 or (x > 10 and x < 20): print "Good value."

if x < 5 or 10 < x < 20: print ‘Good value as well.'

for i in [0,1,2,3,4]: print "Number", i

for i in range(5): print "Number", i

while x >= 0: print "x is not always negative." x = x-1

list

the same list

Page 15: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

Lists

mylist = [1,7,8,3]name = ["Jean","Michel"]x = [1,2,3,[7,8],"fin"]

print name[0]name[1]="Robert"print mylist[1:3]print mylist[:3],mylist[:]print mylist[-1]print x[3][1]

name.append("Georges")print mylist+nameprint mylist*2

concatenate

heterogeneous list

first element = index 0

« slice »: index 3 not included

last element

x[3] is a list

method (list = object)

Other methods: extend, insert, reverse, sort, remove…

Page 16: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

List comprehensions

carres=[x**2 for i in range(10)]

pairs=[x for i in range(10) if i % 2 == 0]

= list of squares of integers from 0 to 9

= list of even integers between 0 and 9

Page 17: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

Stringsa="Bonjour"b='hello'c="""Une phrasequi n'en finit pas"""

print a+bprint a[3:7]

print b.capitalize()

multiline string

≈ list of characters

many methods (find, replace, split…)

Page 18: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

Dictionariesdico={‘one':1,‘two':2,‘three':‘several'}

print dico[‘three']

dico[‘four']=‘many‘del dico[‘one']

key value

for key in dico: print key,'->',dico[key]

iterate all keys

Page 19: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

Functions

def power(x,exponent=2): return x**exponent

print power(3,2)

print power(7)

print power(exponent=3,x=2)

carre=lambda x:x**2 inline definition

default value

call with named arguments

Page 20: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

Modulesimport mathprint math.exp(1)

from math import expprint exp(1)

from math import *print exp(1)

import only the exp object

import everything

You can work with several files (= modules), each one can define any number of objects (= variables, functions, classes)

loads the file ‘math.py’ or ‘math.pyc’ (compiled)

Page 21: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

Scipy & Pylab

Page 22: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

Scipy & Numpy Scientific libraries

Syntax ≈ Matlab Many mathematical functions

from scipy import *x=array([1,2,3])M=array([[1,2,3],[4,5,6]])M=ones((3,3))z=2*xy=dot(M,x)

from scipy.optimize import *print fsolve(lambda x:(x-1)*(x-3),2)

vector

matrix

matrix product

Page 23: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

Vectors et matrices Base type in SciPy: array

(= vector or matrix)

from scipy import *x=array([1,2,3])M=array([[1,2,3],[4,5,6]])

M=ones((3,2))

z=2*x+1

y=dot(M,x)

vector (1,2,3)

matrix1 2 34 5 6

matrix1 11 11 1

matrix product

Page 24: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

Operationsx+yx-yx*yx/yx**2exp(x)sqrt(x)

dot(x,y)dot(M,x)

M.TM.max()M.sum()

size(x)M.shape

element-wise

dot productmatrix product

transpose

total number of elements

Page 25: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

Indexing

x[i]M[i,j]x[i:j]M[i,:]M[:,i]x[[1,3]]

x[1:3]=[0,1]M[1,:]+=x

Vector indexing lists (first element= 0)

(i+1)th element

slice from x[i] to x[j-1](i+1)th row(i+1)th columnelements x[1] and x[3]

x[1]=0, x[3]=1add vector x to the 2nd row of M

M[i,:] is a « view » on matrix M copy ( reference)

y=M[0,:]y[2]=5

x=zx[1]=3

M[0,2] is 5

z[1] is 3 x=z.copy()copy:

Page 26: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

Construction

x=array([1,2,3])M=array([[1,2,3],[4,5,6]])

x=ones(5)M=zeros((3,2))M=eye(3)M=diag([1,3,7])

x=rand(5)x=randn(5)

x=arange(10)

x=linspace(0,1,100)

from lists

vector of 1szero matrixidentity matrixdiagonal matrix

random vector in (0,1)random gaussian vector

0,1,2,...,9

100 numbers between 0 and 1

Page 27: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

SciPy example: optimisation

Simple example, least squares polynomial fit

Page 28: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

Vectorisation How to write efficient programs? Replace loops by vector operations

for i in range(1000000): X[i]=1

X=ones(1000000)

for i in range(1000000): X[i]=X[i]*2

X=X*2

for i in range(999999): Y[i]=X[i+1]-X[i]

Y=X[1:]-X[:-1]

for i in range(1000000): if X[i]>0.5: Y[i]=1

Y[X>.5]=1

Page 29: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

Pylab

Page 30: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

Pylab Plotting library Syntax ≈ Matlab

Many plotting functions

from pylab import *plot([1,2,3],[4,5,6])show()

x y

last instruction of script

plot

polar

more examples:http://matplotlib.sourceforge.net/gallery.html

Page 31: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

Plotting with PyLab

hist(randn(1000)) contour(gaussian_filter(randn(100, 100), 5))

imshow(gaussian_filter(randn(100, 100), 5))

specgram(sin(10000*2*pi*linspace(0,1,44100)),

Fs=44100)

Page 32: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

Brian

At last!

Page 33: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition
Page 34: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition
Page 35: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition
Page 36: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

Online help

Page 37: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

Anatomy of a Brian scriptImport the Brian package+ Scipy and Pylab

Define some parameters, you can use physical unitsDefine neuron equations, the “volt” term says that V has units of volts, and Brian checks the consistency of your equations.Create neurons with given equations and fixed threshold and reset value.

Create synapses – here recurrent random connectivity with probability .1 for each pair of neurons and given synaptic weight, spikes cause an instantaneous increase of amount weight in variable V of the target neuron

Record spiking activity

Initialise state variables to random values.Run simulationAnalyse results – do a raster plot

Page 38: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

Model equationstau=10*mseqs='''dv/dt = (v0-v)/tau : voltu=v*v : volt**2x=uv0 : volt'''

units

differential equationequationaliasparameter

Non-autonomous equations, use the reserved symbol “t” for time

Stochastic DEs Use the term “xi” for noise with: Has units s-1/2. Use typically as “sigma*xi*(2/tau)**0.5”

Solvers: Exact for linear DEs (detected automatically, method=‘linear’) Euler for nonlinear DEs (default, method=‘Euler’) 2nd order Runge-Kutta (default, method=‘RK’) Exponential Euler (implicit=True, method=‘exponential_Euler’)

)()(),( tsts

Page 39: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

Neuron groupsgroup=NeuronGroup(N, model=’dv/dt = -v/tau : volt’,

threshold=’v>15*mV’,

reset=’v=0*mV’,

refractory=2*ms,

method=’implicit’)

model equations

threshold condition

what happens after spiking

refractory period

integration method

optional

units of v

group.v is a vector with values of v for all neurons

group.v[5] is the value of v for neuron 5

P=group[:100]P=group.subgroup(100)

defines a subgroup of 100 neurons

Special groups:

PoissonGroup(N,rates=10*Hz)

SpikeGeneratorGroup(N,spikes)

N Poisson processes

fires at specific times

spikes=[(3,2*ms),(1,10*ms),(2,15*ms)]

Page 40: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

Connections

synapses=Connection(P,Q,’v’)

synapses[5,7]=2*mV

modified variable

P Q

synapses.connect_full(P,Q,weight=2*mV)synapses.connect_random(P,Q,sparseness=.02,weight=2*mV)synapses.connect_full(P[50:100],Q[20:40], weight=lambda i,j:w0*exp(-(i-j)**2))

when neuron 5 spikes: Q.v[7]+=2*mV

Building connections

synapses=Connection(P,Q,’v’,sparseness=.02,weight=2*mV)

Page 41: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

Delays

synapses=Connection(P,Q,’v’,delay=2*ms)

Homogeneous delays

synapses=Connection(P,Q,’v’,delay=True,max_delay=10*ms)synapses.delay[5,7]=2*ms

synapses.connect_full(P,Q,weight=2*mV,delay=(1*ms,2*ms))synapses.connect_full(P,Q,weight=2*mV, delay=lambda i,j:w0*exp(-(i-j)**2))

Heterogeneous delays

Page 42: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

Monitors Recording spike trains

Recording variables

M=SpikeMonitor(P)run(100*ms)raster_plot(M)show()

M=StateMonitor(P,'v',record=True)run(100*ms)plot(M.times/ms,M[0]/mV)show()

Page 43: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

Network operations…M=SpikeMonitor(G)…@network_operationdef check_too_many_spikes(): if M.nspikes>1000: stop()…run(10*second)

this function is called at every time step

Page 44: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

Examples

Page 45: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

Integrate-and-fire model Stimulate an integrate-and-fire model with

regularly spaced spikes

Tip: use SpikeGeneratorGroup

Page 46: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

Integrate-and-fire model

Page 47: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

Current-frequency curve Plot the firing rate of an IF model as a function

of input current

Tip: counter=SpikeCounter(group) counts spikes for every neuron

Page 48: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

Current-frequency curve

Page 49: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

Cortical column Ring of noisy IF neurons with distance-

dependent connections

dv/dt=(v0-v)/ + / (t)

w(i,j)=cos(2(i-j)/N)w0

Page 50: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

Cortical column

Page 51: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

Reliability Response of a noisy IF neuron to repeated

injections of the same noisy current

Page 52: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

Reliability

Page 53: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

Jeffress model

décalage temporel δ

δ+dleft=dright

synchronous inputs neuron fires

Page 54: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

Jeffress model

dela

ys(sound turning around the head)

Page 55: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition
Page 56: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

Interactive session

Page 57: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

Interactive session Try writing your own models with Python,

NumPy, SciPy and Brian We’ll be around to help solve any problems Take a look at the online documentation too:

http://www.python.org/doc/2.5.4/tut/tut.html http://www.python.org/doc/2.5.4/ http://docs.scipy.org/doc/ http://matplotlib.sourceforge.net/contents.html http://www.briansimulator.org/docs/

Page 58: Romain Brette & Dan Goodman  Ecole Normale Supérieure Equipe Audition

http://www.briansimulator.org

Thanks!


Recommended