-
Notifications
You must be signed in to change notification settings - Fork 9
/
validate_compare_models.py
executable file
·141 lines (115 loc) · 4.57 KB
/
validate_compare_models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/bin/python
#-----------------------------------------------------------------------------
# File Name : calibrate.py
# Purpose: Calibrates the parameters of the sigmoid function by fitting the parameters gamma and beta to the transfer function of the IF neuron
#
# Author: Emre Neftci
#
# Creation Date : 24-04-2013
# Last Modified : Thu 22 Jan 2015 12:37:59 PM PST
#
# Copyright : (c) UCSD, Emre Neftci, Srinjoy Das, Bruno Pedroni, Kenneth Kreutz-Delgado, Gert Cauwenberghs
# Licence : GPLv2
#-----------------------------------------------------------------------------
import meta_parameters
meta_parameters.parameters_script = 'parameters_kldivergence'
from common import *
N = 20
t_sim = 5000*ms
def wrap_run_srm(bias):
defaultclock.reinit()
#----------------------------------------- RBM parameters
#------------------------------------------ Neuron Groups
eqs = Equations(eqs_str_lif_rd,
Cm = cm,
I_inj = i_inj + bias,
g = g_leak,
tau_rec = tau_rec)
#beta arbitrary choice
neuron_group = NeuronGroup((N),
model=eqs,
threshold = SimpleFunThreshold( exp_prob_beta_gamma(defaultclock.dt, beta, g_leak, gamma), state = 'v'),
refractory = t_ref)
#set injection currents
#---------------------- Connections and Synapses
#Inject Noise for neural sampling
#--------------------------- Monitors
M = SpikeMonitor(neuron_group)
net = Network([neuron_group, M])
print "running"
net.run(t_sim)
mmon_slice = time_slice(M, t_start=.5*second, t_stop=t_sim)
return float(len(mmon_slice.spikes)) / N / (t_sim-.5*second)
def wrap_run_if(bias):
defaultclock.reinit()
#----------------------------------------- RBM parameters
#------------------------------------------ Neuron Groups
eqs_if = Equations(eqs_str_lif_wnrd, #neuron equations are described in neusa.experimentLib
Cm = cm,
I_inj = i_inj + bias,
g = g_leak,
sigma = wnsigma,
tau_rec = tau_rec)
#beta arbitrary choice
neuron_group = NeuronGroup(\
N,
model = eqs_if,
threshold = 'v>theta*volt',
refractory = t_ref,
reset = 0*volt
)
#set injection currents
#---------------------- Connections and Synapses
#Inject Noise for neural sampling
#--------------------------- Monitors
M = SpikeMonitor(neuron_group)
net = Network([neuron_group, M])
print "running"
net.run(t_sim)
mmon_slice = time_slice(M, t_start=.5*second, t_stop=t_sim)
return float(len(mmon_slice.spikes)) / N / (t_sim-.5*second)
def wrap_run_clif(bias):
defaultclock.reinit()
#----------------------------------------- RBM parameters
#------------------------------------------ Neuron Groups
eqs = Equations(eqs_str_clif_wnrd, #neuron equations are described in neusa.experimentLib
Cm = cm,
I_inj = ci_inj + bias*beta/cbeta,
g = cg_leak,
sigma = wnsigma,
tau_rec = tau_rec)
neuron_group = NeuronGroup(\
N,
model = eqs,
threshold = 'v>ctheta*volt',
refractory = t_ref,
reset = 0*volt
)
#set injection currents
#---------------------- Connections and Synapses
#Inject Noise for neural sampling
#--------------------------- Monitors
M = SpikeMonitor(neuron_group)
@network_operation
def rigid_boundary():
neuron_group.v[neuron_group.v<0] = 0
net = Network([neuron_group, M, rigid_boundary])
print "running"
net.run(t_sim)
mmon_slice = time_slice(M, t_start=.5*second, t_stop=t_sim)
return float(len(mmon_slice.spikes)) / N / (t_sim-.5*second)
if __name__ == '__main__':
#Number of points of the transfer curve
N_run = 36
import multiprocessing
pool = multiprocessing.Pool(8)
input_rates = np.linspace(-4000e-12,4000e-12, N_run)
rates_out_clif = np.array(pool.map(wrap_run_clif, input_rates))
rates_out_srm = np.array(pool.map(wrap_run_srm, input_rates))
rates_out_if = np.array(pool.map(wrap_run_if, input_rates))
plot(input_rates,rates_out_srm, label = 'srm')
plot(input_rates,rates_out_if, label = 'if')
plot(input_rates,rates_out_clif, label = 'clif')
plot(input_rates, (1./t_ref)/(1+np.exp(-beta*input_rates)), linewidth=2, color='k', label='$\\left(\\tau+\\gamma^{-1}\\exp(-\\beta)\\right)^{-1}$')
legend()
#reconstruct pdf