In [1]:
import numpy as np
import matplotlib.pyplot as plt

In [23]:
#leaky integrate and fire with random inputs 

#Corriente
Imax = 1.2 #nA
#time constant
tau = 20. #ms
#input resistance
R = 10. #MOhms
#capacidad
C = tau/R
v_thres = 10 #mV
#integration time step
dt = 0.1 #ms
#simulation time
t_max = 2000.
t_v = np.arange(0,t_max - dt ,dt)        
nt_v = len(t_v)

#compute constants to save time
dttau = dt / tau
one_dttau = 1 - dttau #forward Euler
m1_dttau = 1 / (1 + dttau) #backward Euler


#number of simulations
#n_sims = 500
n_sims = 1 #debugging

#input current
#constant current for debugging purposes
Nt = len(t_v)
i_v_i = np.zeros_like(t_v) #nA
i_v_i[(Nt*1/4):(Nt*3/4)] = Imax #nA
#i_v_i(1:(Nt*3/4)) = Imax; %nA

for j in xrange(0,n_sims):
    

   
    i_v_tot=i_v_i  #corriente total de entrada
      
    v_v = np.zeros_like(t_v)  #vector de voltaje
    s_v = np.zeros_like(t_v)  #vector que indica si hubo spike


    #simulate LIF response to input
    for i in xrange(1,nt_v):
        
        #forward Euler
        #v_v(i) = (1-dt/tau)*v_v[i-1] + dt*i_v_tot[i-1]/C

        #backward Euler
        v_v[i] = m1_dttau*(v_v[i-1] +dt*i_v_tot[i]/C)

        if (v_v[i] >= v_thres):  #Si sobrepasa umbral resetea y guarda spike en s_v
            v_v[i] = 0.
            s_v[i] = 1.
    
    

v_v_f = v_v + s_v * 60 #mv

In [24]:
plt.plot(t_v,v_v_f)
plt.plot(t_v,i_v_i,'r')
plt.show()

In [27]:
a = np.arange(0,10)
a


Out[27]:
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])

In [55]:
b = np.array([2,2,2,2,2,2,2,2,2,2])
b.shape


Out[55]:
(10,)

In [56]:
a * b


Out[56]:
array([ 0,  2,  4,  6,  8, 10, 12, 14, 16, 18])

In [57]:
np.dot(a,b)


Out[57]:
90

In [58]:
A = np.array([[1,2],[3,4]])
A


Out[58]:
array([[1, 2],
       [3, 4]])

In [59]:
A.shape


Out[59]:
(2, 2)

In [60]:
B = np.array([[1,2],[3,4]])

In [61]:
B * A


Out[61]:
array([[ 1,  4],
       [ 9, 16]])

In [62]:
np.dot(A,B)


Out[62]:
array([[ 7, 10],
       [15, 22]])

In [ ]: