a neuron + python tutorial learn how to use neuron with python · #import matplotlib for plotting...
TRANSCRIPT
A NEURON + PYTHON TUTORIAL
I Learn how to use NEURON with Python
I Show that neurons are capable of linearly non-separablecomputations.
A NEURON + PYTHON TUTORIAL
I Learn how to use NEURON with PythonI Show that neurons are capable of linearly non-separable
computations.
WHY NOT NEURON ALONE?
I Python is clearer than Hoc and easier to work with
I Generate, process and plot the data using same language
WHY NOT NEURON ALONE?
I Python is clearer than Hoc and easier to work withI Generate, process and plot the data using same language
USING SPYDER
I Create a new project folder called NEURON in Spyder andcreate a file called neurhon.py
I You can run this script with F5I You might need to restart the ipython kernel . . .
USING SPYDER
I Create a new project folder called NEURON in Spyder andcreate a file called neurhon.py
I You can run this script with F5
I You might need to restart the ipython kernel . . .
USING SPYDER
I Create a new project folder called NEURON in Spyder andcreate a file called neurhon.py
I You can run this script with F5I You might need to restart the ipython kernel . . .
START BY IMPORTING NEURON AND MATPLOTLIB IN
PYTHON
#Import m a t p l o t l i b f o r p l o t t i n gimport m a t p l o t l i b . pyplot as p l t# Import NEURON f o r s imulat ingimport neuron
OUR FIRST SOMA
# Access the h ( hoc ) to c r e a t e a S e c t io nsoma = neuron . h . Se c t i o n (name=”soma ”)soma . nseg = 1soma . diam = 10soma . L = 10
YOUR FIRST RUN
I Run the script with F5
I You have created your first soma!I Use ipython to inspect your soma by typing dir(soma) in
the console
YOUR FIRST RUN
I Run the script with F5I You have created your first soma!
I Use ipython to inspect your soma by typing dir(soma) inthe console
YOUR FIRST RUN
I Run the script with F5I You have created your first soma!I Use ipython to inspect your soma by typing dir(soma) in
the console
SOME ATTRIBUTS AND METHODS OF YOUR FIRST
SECTION
AttributsL The segment diameter
Ra The axial resistancenseg The number of segments
Methodconnect Connect the section to another one use ? to know
more.insert Insert a mechanism in all the segments of the
section.
SOME ATTRIBUTS AND METHODS OF YOUR FIRST
SECTION
AttributsL The segment diameter
Ra The axial resistancenseg The number of segments
Methodconnect Connect the section to another one use ? to know
more.insert Insert a mechanism in all the segments of the
section.
ADD HODGKIN HUXLEY MECHANISMS
For that simply add the lines:
soma . i n s e r t (” hh ”)meca = soma ( 0 . 5 ) . hh
Inspect meca of the middle section with dir(meca).
SOME ATTRIBUTS OF MECHANISMS
gnabar hh Maximum sodium channel conductance S/cm2̂gkbar hh Maximum potassium channel conductance S/cm2̂
gl hh Leakage conductance S/cm2̂ena, ek, el hh Reversal potential for the sodium channel,ik
potassium and leakage channel mVm hh, n hh, h hh Sodium activation and Potassium
inactivation and activation state
RECORD VARIABLES
Specify the values of the section to be recorded:
# Record Time from NEURON ( neuron . h . r e f t )r e c t = neuron . h . Vector ( )r e c t . record ( neuron . h . r e f t )# Record Voltage from the c e n t e r of the somar e c v = neuron . h . Vector ( )r e c v . record ( soma ( 0 . 5 ) . r e f v )
INSERT AN ELECTRODE
# Create an e l e c t r o d e i n j e c t i n g current in the somastim = neuron . h . IClamp ( soma ( 0 . 5 ) )
# Set the e l e c t r o d e p r o p e r t i e sstim . delay = 100stim . dur = 100stim . amp = 0 . 1
SOME ATTRIBUTS OF THE ELECTRODE
amp Amplitude of the injected currentdelay Time of activation in ms
dur Duration of the stimulation
RUN A SIMULATION
# I n i t i a l i s e the value of the vol tageneuron . h . f i n i t i a l i z e (−65)# Set the time of the s imulat iont s t o p = 300#Run the s imulat ionneuron . run ( t s t o p )
PLOT THE RESULT
#Record time and vol tage as numpy arraystime = r e c t . as numpy ( )vol tage = r e c v . as numpy ( )# P l o tp l t . p l o t ( time , voltage , c o l o r = ’b ’ )p l t . x l a b e l (” Time [ms] ” )p l t . y l a b e l (” Voltage [mV] ” )p l t . a x i s ( xmin=0 , xmax=max( time ) , \
ymin=min ( vol tage )−5 , ymax=max( vol tage )+ 5 )p l t . show ( )
YOUR JOB I
I After writing the part creating the soma / insertingmecanism / recording variables / inserting an electrode /plotting the result. You can run your script.
I Change the amplitude of the stimulation and observe theoutcome
YOUR JOB I
I After writing the part creating the soma / insertingmecanism / recording variables / inserting an electrode /plotting the result. You can run your script.
I Change the amplitude of the stimulation and observe theoutcome
ADDING DENDRITES
# Create ndendri tesndend = 2dends = range ( ndend )f o r i in dends :
dend = neuron . h . Se c t i o n ( )dend . nseg = 5dend . L = 300dend . diam = 0 . 5dend . Ra = 125dend . i n s e r t (” pas ”)dend . connect ( soma , 0 )dends [ i ] = dend
REFACTOR THE CODE
I Never rewrite something two times
I Enable to identify bottleneck (see %timeit in ipython). InNEURON this is often the run() obviously
REFACTOR THE CODE
I Never rewrite something two timesI Enable to identify bottleneck (see %timeit in ipython). In
NEURON this is often the run() obviously
AN EXAMPLE OF FUNCTION: SET RECORDINGS
def rec ( seg ) :””” Record vol tage of a segment seg .f o r example soma ( 0 . 5 ) ” ” ”r e c v = neuron . h . Vector ( )r e c v . record ( seg . r e f v )re turn r e c v
YOUR JOB II
I Refactor in two functions: run to run a simulation, and plotto plot a voltage trace.
I Plot the voltage from soma(0.5) and from one of thedendrites at 0.9 with two different colors
I Hint: Use the functions rec two times and the function plottwo times
I Increase the number of dendrites and explain yourobservation.
YOUR JOB II
I Refactor in two functions: run to run a simulation, and plotto plot a voltage trace.
I Plot the voltage from soma(0.5) and from one of thedendrites at 0.9 with two different colors
I Hint: Use the functions rec two times and the function plottwo times
I Increase the number of dendrites and explain yourobservation.
YOUR JOB II
I Refactor in two functions: run to run a simulation, and plotto plot a voltage trace.
I Plot the voltage from soma(0.5) and from one of thedendrites at 0.9 with two different colors
I Hint: Use the functions rec two times and the function plottwo times
I Increase the number of dendrites and explain yourobservation.
YOUR JOB II
I Refactor in two functions: run to run a simulation, and plotto plot a voltage trace.
I Plot the voltage from soma(0.5) and from one of thedendrites at 0.9 with two different colors
I Hint: Use the functions rec two times and the function plottwo times
I Increase the number of dendrites and explain yourobservation.
THE FEATURE BINDING PROBLEM
I Caze et al 2013 “Passive dendrites enable single neurons tocompute linearly non-separable functions”
I Use NEURON to show that neurons are capable of linearlynon-separable computations.
THE FEATURE BINDING PROBLEM
[x1, x2, x3, x4] y[1, 1.0, 0] 0[1, 0, 1, 0] 1[0, 1, 0, 1] 1[0, 0, 1, 1] 0
THE FEATURE BINDING PROBLEM IS LINEARLY
NON-SEPARABLE
Line Weights ConditionL1 w1 + w2 + 0 + 0 < ΘL2 w1 + 0 + w3 + 0 ≥ ΘL3 0 + w2 + 0 + w4 ≥ ΘL4 0 + 0 + w3 + w4 < Θ
Contradiction apparent when you add L1 + L4 and L2 + L3→no set of weights can compute this function
A FUNCTION TO ADD SYNAPSES TO A SEGMENT
def add syn ( seg , time ) :”””Add a synapse a t a given l o c a t i o n ”””stim = neuron . h . AlphaSynapse ( seg )stim . onset = timestim . gmax = 0 . 2re turn stim
YOUR JOB III
I Show that a neuron with two passive dendrites (bipolar)can implement the feature binding problem
I Hint 1: synapses should be located in the middle ofdendritic sections to make the neuron spike
I Hint 2: add only synapses that should be activeI Hint 3: use the symmetry of the problem to study only two
cases instead of four.
YOUR JOB III
I Show that a neuron with two passive dendrites (bipolar)can implement the feature binding problem
I Hint 1: synapses should be located in the middle ofdendritic sections to make the neuron spike
I Hint 2: add only synapses that should be activeI Hint 3: use the symmetry of the problem to study only two
cases instead of four.
YOUR JOB III
I Show that a neuron with two passive dendrites (bipolar)can implement the feature binding problem
I Hint 1: synapses should be located in the middle ofdendritic sections to make the neuron spike
I Hint 2: add only synapses that should be active
I Hint 3: use the symmetry of the problem to study only twocases instead of four.
YOUR JOB III
I Show that a neuron with two passive dendrites (bipolar)can implement the feature binding problem
I Hint 1: synapses should be located in the middle ofdendritic sections to make the neuron spike
I Hint 2: add only synapses that should be activeI Hint 3: use the symmetry of the problem to study only two
cases instead of four.
TO GO FURTHER
I NEURON a programming tutorial:http://www.anc.ed.ac.uk/school/neuron/
I You should be able to reproduce the Part A and B usingNEURON + python without help
I The part C introduce with 3D models, a bit more involvedbut here also NEURON + python helps
I Part D is standalone as a .mod file can be used both inNEURON + Python and NEURON
I Part E is obsolete because Python enables more complexdata processing/recording
TO GO FURTHER
I NEURON a programming tutorial:http://www.anc.ed.ac.uk/school/neuron/
I You should be able to reproduce the Part A and B usingNEURON + python without help
I The part C introduce with 3D models, a bit more involvedbut here also NEURON + python helps
I Part D is standalone as a .mod file can be used both inNEURON + Python and NEURON
I Part E is obsolete because Python enables more complexdata processing/recording
TO GO FURTHER
I NEURON a programming tutorial:http://www.anc.ed.ac.uk/school/neuron/
I You should be able to reproduce the Part A and B usingNEURON + python without help
I The part C introduce with 3D models, a bit more involvedbut here also NEURON + python helps
I Part D is standalone as a .mod file can be used both inNEURON + Python and NEURON
I Part E is obsolete because Python enables more complexdata processing/recording
TO GO FURTHER
I NEURON a programming tutorial:http://www.anc.ed.ac.uk/school/neuron/
I You should be able to reproduce the Part A and B usingNEURON + python without help
I The part C introduce with 3D models, a bit more involvedbut here also NEURON + python helps
I Part D is standalone as a .mod file can be used both inNEURON + Python and NEURON
I Part E is obsolete because Python enables more complexdata processing/recording
TO GO FURTHER
I NEURON a programming tutorial:http://www.anc.ed.ac.uk/school/neuron/
I You should be able to reproduce the Part A and B usingNEURON + python without help
I The part C introduce with 3D models, a bit more involvedbut here also NEURON + python helps
I Part D is standalone as a .mod file can be used both inNEURON + Python and NEURON
I Part E is obsolete because Python enables more complexdata processing/recording