Last active
November 2, 2016 19:37
-
-
Save ozturkib/10047d58ae0c0c796f8b4ea4c66bd2df to your computer and use it in GitHub Desktop.
Leaky Integrate And Fire model with volt units, it is not behaving as it should behave.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Created on 2 Nov 2016 | |
@author: io517@york.ac.uk | |
@link : http://www.ozturkibrahim.com/ | |
Give a stimulus and see the trajectory of membrane voltage | |
''' | |
from brian2 import * | |
import brian2tools | |
if __name__ == '__main__': | |
OutLyrGroup_NeuronNum = 1 # Number of Neurons | |
##LIF Neuron dynamics | |
lif_taum = 10 * ms # membrane time constant (R_m * C_m) | |
lif_Vth = -55 * mV # threshold potential | |
lif_Vresting = -60 * mV | |
lif_Vreset = -65 * mV # spike reset, reset potential | |
t_simulation = 200 * ms #Simulation Time as ms | |
t_step = 0.1 #Time step in simulation as ms | |
t_steps_total = t_simulation / t_step | |
#Configuration about the LIF neuron --> | |
lif_eqs = ''' | |
dv/dt = (v0-v)/taum : volt (unless refractory) | |
v0 = appliedLower + diffIntoLower *int(t > diffTime) : volt | |
appliedLower : volt | |
diffIntoLower : volt | |
diffTime : second | |
taum : second | |
''' | |
lif_threshold_statement = 'v > %.2f * volt' % (lif_Vth) | |
lif_reset_statement = 'v = %.2f * volt' % (lif_Vreset) | |
lif_refractory_time = 0*ms | |
lif_initial_volt_statement = '%.2f * volt + 0.5 * volt * (%.2f - %.2f)' % (lif_Vreset, lif_Vth, lif_Vreset) | |
lif_integ_method = 'euler' | |
OutLyrGroup = NeuronGroup(OutLyrGroup_NeuronNum, lif_eqs,\ | |
threshold = lif_threshold_statement, \ | |
reset = lif_reset_statement, \ | |
refractory = lif_refractory_time, \ | |
method = lif_integ_method, \ | |
#order = 3, \ | |
name = "OutLyrGroup*") | |
OutLyrGroup.v = 0* volt#lif_initial_volt_statement | |
OutLyrGroup.taum = lif_taum | |
OutLyrGroup.appliedLower = lif_Vth - 3*mV | |
OutLyrGroup.diffIntoLower = 6*mV | |
OutLyrGroup.diffTime = 100*ms | |
SpMon_OutLyrGroup = SpikeMonitor(OutLyrGroup, name="SpMon_OutLyrGroup*") | |
StMon_OutLyrGroup = StateMonitor(OutLyrGroup, ['v', 'v0'], record=True) | |
run(t_simulation) | |
figure(1) | |
plot(StMon_OutLyrGroup.t/ms, StMon_OutLyrGroup.v[0]/mV) | |
plot(StMon_OutLyrGroup.t/ms, StMon_OutLyrGroup.v0[0]/mV) | |
xlabel('Time (ms)', fontsize=24) | |
ylabel('v (mV)',fontsize=24) | |
ylim(-70,-50) | |
show() | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Created on 2 Nov 2016 | |
@author: io517@york.ac.uk | |
@link : http://www.ozturkibrahim.com/ | |
Give a stimulus and see the trajectory of membrane voltage | |
''' | |
from brian2 import * | |
import brian2tools | |
if __name__ == '__main__': | |
OutLyrGroup_NeuronNum = 1 # Number of Neurons | |
##LIF Neuron dynamics | |
lif_taum = 10 * ms # membrane time constant (R_m * C_m) | |
lif_Vth = -55 # threshold potential | |
lif_Vresting = -60 | |
lif_Vreset = -65 # spike reset, reset potential | |
t_simulation = 200 * ms #Simulation Time as ms | |
t_step = 0.1 #Time step in simulation as ms | |
t_steps_total = t_simulation / t_step | |
#Configuration about the LIF neuron --> | |
lif_eqs = ''' | |
dv/dt = (v0-v)/taum : 1 (unless refractory) | |
v0 = appliedLower + diffIntoLower *int(t > diffTime) : 1 | |
appliedLower : 1 | |
diffIntoLower : 1 | |
diffTime : second | |
taum : second | |
''' | |
lif_threshold_statement = 'v > %.2f ' % (lif_Vth) | |
lif_reset_statement = 'v = %.2f ' % (lif_Vreset) | |
lif_refractory_time = 0*ms | |
lif_initial_volt_statement = '%.2f + 0.5 * (%.2f - %.2f)' % (lif_Vreset, lif_Vth, lif_Vreset) | |
lif_integ_method = 'euler' | |
OutLyrGroup = NeuronGroup(OutLyrGroup_NeuronNum, lif_eqs,\ | |
threshold = lif_threshold_statement, \ | |
reset = lif_reset_statement, \ | |
refractory = lif_refractory_time, \ | |
method = lif_integ_method, \ | |
#order = 3, \ | |
name = "OutLyrGroup*") | |
OutLyrGroup.v = 0 #lif_initial_volt_statement | |
OutLyrGroup.taum = lif_taum | |
OutLyrGroup.appliedLower = lif_Vth - 3 | |
OutLyrGroup.diffIntoLower = 6 | |
OutLyrGroup.diffTime = 100*ms | |
SpMon_OutLyrGroup = SpikeMonitor(OutLyrGroup, name="SpMon_OutLyrGroup*") | |
StMon_OutLyrGroup = StateMonitor(OutLyrGroup, ['v', 'v0'], record=True) | |
run(t_simulation) | |
figure(1) | |
plot(StMon_OutLyrGroup.t/ms, StMon_OutLyrGroup.v[0]) | |
plot(StMon_OutLyrGroup.t/ms, StMon_OutLyrGroup.v0[0]) | |
xlabel('Time (ms)', fontsize=24) | |
ylabel('v (mV)',fontsize=24) | |
ylim(-70,-50) | |
show() | |
Author
ozturkib
commented
Nov 2, 2016
Both codes are exactly the same except units. Second code is working as it should. However, the first one with units (mV - volt) should also work but it is behaving strangely. Dont understand what is the problem in the first file.
Solution is suggested by Dan Goodman >>
The problem is '%.2f * volt' % V_th gives result '0.06 * volt' as the output because 55 mV in volts is 0.055 and you only give 2 decimal places so it gets rounded to 0.06.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment