1 | ;; |
---|
2 | ;; Simple Model of Spiking Neurons, Izhikevich E |
---|
3 | ;; |
---|
4 | ;; IEEE Transactions on Neural Networks (2003) 14:1569- 1572 |
---|
5 | ;; |
---|
6 | ;; |
---|
7 | |
---|
8 | (use signal-diagram signal-diagram-dynamics mathh srfi-1 ) |
---|
9 | |
---|
10 | (define (Izhikevich03:construct t V U k1 k2 k3 theta a b c d spike tspike Isyn ) |
---|
11 | |
---|
12 | `((f . ,(let* ((subthreshold-eq (ODE (variable h) t |
---|
13 | (V (+ (* k1 V V) (* k2 V) k3 (neg U) Isyn)) |
---|
14 | (U (* a (- (* b V) U))))) |
---|
15 | |
---|
16 | (threshold-detect (ASSIGN (spike (> V theta)))) |
---|
17 | |
---|
18 | (tspike-set (ASSIGN (tspike (if spike t tspike)))) |
---|
19 | |
---|
20 | (subthreshold-regime (SEQUENCE subthreshold-eq (SEQUENCE threshold-detect tspike-set))) |
---|
21 | |
---|
22 | (refractory-eq (ASSIGN (t (+ t h) ) |
---|
23 | (spike false) |
---|
24 | (tspike tspike) |
---|
25 | (V c) |
---|
26 | (U (+ U d)))) |
---|
27 | ) |
---|
28 | |
---|
29 | (TRANSIENT subthreshold-regime refractory-eq 'spike) |
---|
30 | |
---|
31 | )) |
---|
32 | |
---|
33 | (initial . |
---|
34 | ((h 1e-2) |
---|
35 | (t ,t) |
---|
36 | (V ,V) |
---|
37 | (U ,U) |
---|
38 | (k1 ,k1) |
---|
39 | (k2 ,k2) |
---|
40 | (k3 ,k3) |
---|
41 | (theta ,theta) |
---|
42 | (a ,a) |
---|
43 | (b ,b) |
---|
44 | (c ,c) |
---|
45 | (d ,d) |
---|
46 | (spike ,spike) |
---|
47 | (tspike ,tspike) |
---|
48 | (Isyn ,Isyn) |
---|
49 | )) |
---|
50 | )) |
---|
51 | |
---|
52 | |
---|
53 | (define (dataflow model) |
---|
54 | (let* ((f (alist-ref 'f model)) |
---|
55 | (initial (alist-ref 'initial model)) |
---|
56 | (input (map car initial))) |
---|
57 | (print "input = " input) |
---|
58 | (print "dataflow f: " (dataflow (construct f) input)) |
---|
59 | )) |
---|
60 | |
---|
61 | |
---|
62 | (define (codegen name model #!key (language 'scheme) (random #f) (pre #t) (post #t) (solver 'rkdp)) |
---|
63 | (let* ((f (alist-ref 'f model)) |
---|
64 | (initial (alist-ref 'initial model))) |
---|
65 | (case language |
---|
66 | ((octave Octave) (codegen/Octave name (construct f) initial: initial pre: pre solver: solver)) |
---|
67 | ((scheme Scheme) (codegen/scheme name (construct f) initial: initial pre: pre solver: solver)) |
---|
68 | ((ML) (codegen/ML name (construct f) initial: initial random: random pre: pre post: post solver: solver))) |
---|
69 | )) |
---|
70 | |
---|
71 | |
---|
72 | ;; Parameters common to all spiking regimes |
---|
73 | (define k1 0.04) |
---|
74 | (define k2 5.0) |
---|
75 | (define k3 140.0) |
---|
76 | (define theta 30.0) |
---|
77 | (define Isyn 10.0) |
---|
78 | |
---|
79 | ;; State initial values |
---|
80 | (define t 0.0) |
---|
81 | (define V -65.0) |
---|
82 | |
---|
83 | |
---|
84 | ;; Regular spiking (RS) parameters |
---|
85 | (define RS |
---|
86 | (let ((a 0.02) |
---|
87 | (b 0.2) |
---|
88 | (c -65.0) |
---|
89 | (d 8.0)) |
---|
90 | (Izhikevich03:construct |
---|
91 | ;; t V U k1 k2 k3 theta a b c d spike tspike Isyn |
---|
92 | t V (* b V) k1 k2 k3 theta a b c d #f t Isyn))) |
---|
93 | |
---|
94 | |
---|
95 | ;; Intrinsically bursting (IB) parameters |
---|
96 | (define IB |
---|
97 | (let ((a 0.02) |
---|
98 | (b 0.2) |
---|
99 | (c -55.0) |
---|
100 | (d 4.0)) |
---|
101 | (Izhikevich03:construct |
---|
102 | ;; t V U k1 k2 k3 theta a b c d spike tspike Isyn |
---|
103 | t V (* b V) k1 k2 k3 theta a b c d #f t Isyn))) |
---|
104 | |
---|
105 | |
---|
106 | ;; Chattering (CH) parameters |
---|
107 | (define CH |
---|
108 | (let ((a 0.02) |
---|
109 | (b 0.2) |
---|
110 | (c -50.0) |
---|
111 | (d 2.0)) |
---|
112 | (Izhikevich03:construct |
---|
113 | ;; t V U k1 k2 k3 theta a b c d spike tspike Isyn |
---|
114 | t V (* b V) k1 k2 k3 theta a b c d #f t Isyn))) |
---|
115 | |
---|
116 | |
---|
117 | ;; Fast-spiking (FS) parameters |
---|
118 | (define FS |
---|
119 | (let ((a 0.1) |
---|
120 | (b 0.2) |
---|
121 | (c -65.0) |
---|
122 | (d 2.0)) |
---|
123 | (Izhikevich03:construct |
---|
124 | ;; t V U k1 k2 k3 theta a b c d spike tspike Isyn |
---|
125 | t V (* b V) k1 k2 k3 theta a b c d #f t Isyn))) |
---|
126 | |
---|
127 | |
---|
128 | |
---|
129 | ;; Thalamo-cortical (TC) parameters |
---|
130 | (define TC |
---|
131 | (let ((a 0.02) |
---|
132 | (b 0.25) |
---|
133 | (c -65.0) |
---|
134 | (d 0.05)) |
---|
135 | (Izhikevich03:construct |
---|
136 | ;; t V U k1 k2 k3 theta a b c d spike tspike Isyn |
---|
137 | t V (* b V) k1 k2 k3 theta a b c d #f t Isyn))) |
---|
138 | |
---|
139 | |
---|
140 | ;; Resonator (RZ) parameters |
---|
141 | (define RZ |
---|
142 | (let ((a 0.1) |
---|
143 | (b 0.26) |
---|
144 | (c -65.0) |
---|
145 | (d 2.0)) |
---|
146 | (Izhikevich03:construct |
---|
147 | ;; t V U k1 k2 k3 theta a b c d spike tspike Isyn |
---|
148 | t V (* b V) k1 k2 k3 theta a b c d #f t Isyn))) |
---|
149 | |
---|
150 | |
---|
151 | |
---|
152 | ;; Low-threshold spiking (LTS) parameters |
---|
153 | (define LTS |
---|
154 | (let ((a 0.02) |
---|
155 | (b 0.25) |
---|
156 | (c -65.0) |
---|
157 | (d 2.0)) |
---|
158 | (Izhikevich03:construct |
---|
159 | ;; t V U k1 k2 k3 theta a b c d spike tspike Isyn |
---|
160 | t V (* b V) k1 k2 k3 theta a b c d #f t Isyn))) |
---|
161 | |
---|
162 | |
---|
163 | (define models `((RS . ,RS) (IB . ,IB) (CH . ,CH) (FS . ,FS) (RZ . ,RZ) (LTS . ,LTS) )) |
---|
164 | |
---|
165 | |
---|
166 | (with-output-to-file "Izhikevich03_solver.sml" |
---|
167 | (lambda () |
---|
168 | (let recur ((models models) (pre #t)) |
---|
169 | (if (pair? models) |
---|
170 | (let* ((name.model (car models)) |
---|
171 | (name (car name.model)) |
---|
172 | (model (cdr name.model))) |
---|
173 | (codegen name model language: 'ML solver: 'rkdp random: #f pre: pre post: (null? (cdr models))) |
---|
174 | (recur (cdr models) #f) |
---|
175 | ))) |
---|
176 | )) |
---|
177 | |
---|
178 | (with-output-to-file "Izhikevich03_solver.m" |
---|
179 | (lambda () |
---|
180 | (let recur ((models models) (pre #t)) |
---|
181 | (if (pair? models) |
---|
182 | (let* ((name.model (car models)) |
---|
183 | (name (car name.model)) |
---|
184 | (model (cdr name.model))) |
---|
185 | (codegen name model language: 'octave pre: pre solver: 'lsode) |
---|
186 | (recur (cdr models) #f) |
---|
187 | ))) |
---|
188 | )) |
---|
189 | |
---|
190 | (with-output-to-file "Izhikevich03_solver.scm" |
---|
191 | (lambda () |
---|
192 | (let recur ((models models) (pre #t)) |
---|
193 | (if (pair? models) |
---|
194 | (let* ((name.model (car models)) |
---|
195 | (name (car name.model)) |
---|
196 | (model (cdr name.model))) |
---|
197 | (codegen name model language: 'scheme pre: pre) |
---|
198 | (recur (cdr models) #f) |
---|
199 | ))) |
---|
200 | )) |
---|
201 | |
---|
202 | |
---|
203 | |
---|