Permalink
Newer
Older
100644 175 lines (155 sloc) 7.28 KB
Apr 24, 2014 @miscco Cleanup. Made comments line save
1 /*
Mar 21, 2016 @miscco Corrected typo in the reference
2 * Copyright (c) 2015 University of Lübeck
Nov 9, 2015 @miscco Updated the code with correct license.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
Feb 1, 2016 @miscco Switched to the random_stream header for RNGs and updated the naming …
11 * The aboVp copyright notice and this permission notice shall be included in
Nov 9, 2015 @miscco Updated the code with correct license.
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Feb 1, 2016 @miscco Switched to the random_stream header for RNGs and updated the naming …
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVpNT SHALL THE
Nov 9, 2015 @miscco Updated the code with correct license.
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 *
22 * AUTHORS: Michael Schellenberger Costa: mschellenbergercosta@gmail.com
23 *
Mar 21, 2016 @miscco Corrected typo in the reference
24 * Based on: Characterization of K-Complexes and Slow Wave Activity in a Neural Mass Model
25 * A Weigenand, M Schellenberger Costa, H-VV Ngo, JC Claussen, T Martinetz
26 * PLoS Computational Biology. 2014;10:e1003923
27 *
28 * A thalamocortical neural mass model of the EEG during NREM sleep and its response
Nov 9, 2015 @miscco Updated the code with correct license.
29 * to auditory stimulation.
30 * M Schellenberger Costa, A Weigenand, H-VV Ngo, L Marshall, J Born, T Martinetz,
31 * JC Claussen.
Sep 13, 2016 @miscco Major cleanup and moderinization
32 * PLoS Computational Biology http://dx.doi.org/10.1371/journal.pcbi.1005022
Nov 9, 2015 @miscco Updated the code with correct license.
33 */
Apr 24, 2014 @miscco Cleanup. Made comments line save
34
Sep 13, 2016 @miscco Major cleanup and moderinization
35 /******************************************************************************/
36 /* Functions of the cortical module */
37 /******************************************************************************/
Mar 1, 2014 @miscco New implementation of the thalamo-cortical model
38 #include "Cortical_Column.h"
Mar 10, 2014 @miscco First modular implementation of the thalamo-cortical model.
39
Sep 13, 2016 @miscco Major cleanup and moderinization
40 /******************************************************************************/
41 /* Initialization of RNG */
42 /******************************************************************************/
Mar 10, 2014 @miscco First modular implementation of the thalamo-cortical model.
43 void Cortical_Column::set_RNG(void) {
Sep 13, 2016 @miscco Major cleanup and moderinization
44 extern const double dt;
45 unsigned numRandomVariables = 2;
46
47 MTRands.reserve(2*numRandomVariables);
48 Rand_vars.reserve(2*numRandomVariables);
49 for (unsigned i=0; i < numRandomVariables; ++i){
50 /* Add the RNG for I_{l}*/
Sep 26, 2016 @miscco Fixed a minor casting bug in random stream implementation and renamed…
51 MTRands.push_back(randomStreamNormal(0.0, dphi*dt));
Sep 13, 2016 @miscco Major cleanup and moderinization
52
53 /* Add the RNG for I_{l,0} */
Sep 26, 2016 @miscco Fixed a minor casting bug in random stream implementation and renamed…
54 MTRands.push_back(randomStreamNormal(0.0, dt));
Sep 13, 2016 @miscco Major cleanup and moderinization
55
56 /* Get the random number for the first iteration */
57 Rand_vars.push_back(MTRands[2*i]());
58 Rand_vars.push_back(MTRands[2*i+1]());
59 }
Mar 10, 2014 @miscco First modular implementation of the thalamo-cortical model.
60 }
61
Sep 13, 2016 @miscco Major cleanup and moderinization
62 /******************************************************************************/
63 /* RK noise scaling */
64 /******************************************************************************/
65 double Cortical_Column::noise_xRK(int N, int M) const{
66 return gamma_e * gamma_e * (Rand_vars[2*M] + Rand_vars[2*M+1]/std::sqrt(3))*B[N];
67 }
68
69 double Cortical_Column::noise_aRK(int M) const{
70 return gamma_e * gamma_e * (Rand_vars[2*M] - Rand_vars[2*M+1]*std::sqrt(3))/4;
71 }
Mar 10, 2014 @miscco First modular implementation of the thalamo-cortical model.
72
Sep 13, 2016 @miscco Major cleanup and moderinization
73 /******************************************************************************/
74 /* Firing Rate functions */
75 /******************************************************************************/
Apr 24, 2014 @miscco Cleanup. Made comments line save
76 /* Pyramidal firing rate */
Feb 1, 2016 @miscco Switched to the random_stream header for RNGs and updated the naming …
77 double Cortical_Column::get_Qp (int N) const{
Sep 13, 2016 @miscco Major cleanup and moderinization
78 return Qp_max / (1 + exp(-C1 * (Vp[N] - theta_p) / sigma_p));
Mar 1, 2014 @miscco New implementation of the thalamo-cortical model
79 }
80
Apr 24, 2014 @miscco Cleanup. Made comments line save
81 /* Inhibitory firing rate */
Mar 1, 2014 @miscco New implementation of the thalamo-cortical model
82 double Cortical_Column::get_Qi (int N) const{
Sep 13, 2016 @miscco Major cleanup and moderinization
83 return Qi_max / (1 + exp(-C1 * (Vi[N] - theta_i) / sigma_i));
Mar 1, 2014 @miscco New implementation of the thalamo-cortical model
84 }
85
Sep 13, 2016 @miscco Major cleanup and moderinization
86 /******************************************************************************/
87 /* Synaptic currents */
88 /******************************************************************************/
Apr 24, 2014 @miscco Cleanup. Made comments line save
89 /* Excitatory input to pyramidal population */
Sep 13, 2016 @miscco Major cleanup and moderinization
90 double Cortical_Column::I_ep (int N) const{
91 return g_AMPA * s_ep[N] * (Vp[N] - E_AMPA);
Mar 1, 2014 @miscco New implementation of the thalamo-cortical model
92 }
93
Apr 24, 2014 @miscco Cleanup. Made comments line save
94 /* Inhibitory input to pyramidal population */
Sep 13, 2016 @miscco Major cleanup and moderinization
95 double Cortical_Column::I_gp (int N) const{
96 return g_GABA * s_gp[N] * (Vp[N] - E_GABA);
Mar 1, 2014 @miscco New implementation of the thalamo-cortical model
97 }
Apr 24, 2014 @miscco Cleanup. Made comments line save
98 /* Excitatory input to inhibitory population */
Sep 13, 2016 @miscco Major cleanup and moderinization
99 double Cortical_Column::I_ei (int N) const{
100 return g_AMPA * s_ei[N] * (Vi[N] - E_AMPA);
Mar 1, 2014 @miscco New implementation of the thalamo-cortical model
101 }
102
Apr 24, 2014 @miscco Cleanup. Made comments line save
103 /* Inhibitory input to inhibitory population */
Sep 13, 2016 @miscco Major cleanup and moderinization
104 double Cortical_Column::I_gi (int N) const{
105 return g_GABA * s_gi[N] * (Vi[N] - E_GABA);
Mar 1, 2014 @miscco New implementation of the thalamo-cortical model
106 }
107
Sep 13, 2016 @miscco Major cleanup and moderinization
108 /******************************************************************************/
109 /* Intrinsic currents */
110 /******************************************************************************/
Apr 24, 2014 @miscco Cleanup. Made comments line save
111 /* Leak current of pyramidal population */
Sep 13, 2016 @miscco Major cleanup and moderinization
112 double Cortical_Column::I_L_p (int N) const{
113 return g_L * (Vp[N] - E_L_p);
Mar 1, 2014 @miscco New implementation of the thalamo-cortical model
114 }
115
Apr 24, 2014 @miscco Cleanup. Made comments line save
116 /* Leak current of inhibitory population */
Sep 13, 2016 @miscco Major cleanup and moderinization
117 double Cortical_Column::I_L_i (int N) const{
118 return g_L * (Vi[N] - E_L_i);
Mar 1, 2014 @miscco New implementation of the thalamo-cortical model
119 }
120
Apr 24, 2014 @miscco Cleanup. Made comments line save
121 /* Sodium dependent potassium current */
Sep 13, 2016 @miscco Major cleanup and moderinization
122 double Cortical_Column::I_KNa (int N) const{
123 double w_KNa = 0.37/(1+pow(38.7/Na[N], 3.5));
124 return g_KNa * w_KNa * (Vp[N] - E_K);
Mar 1, 2014 @miscco New implementation of the thalamo-cortical model
125 }
126
Sep 13, 2016 @miscco Major cleanup and moderinization
127 /******************************************************************************/
128 /* Potassium pump */
129 /******************************************************************************/
130 double Cortical_Column::Na_pump (int N) const{
131 return R_pump*(Na[N]*Na[N]*Na[N]/(Na[N]*Na[N]*Na[N]+3375) -
132 Na_eq*Na_eq*Na_eq/(Na_eq*Na_eq*Na_eq+3375));
Mar 1, 2014 @miscco New implementation of the thalamo-cortical model
133 }
134
Sep 13, 2016 @miscco Major cleanup and moderinization
135 /******************************************************************************/
136 /* SRK iteration */
137 /******************************************************************************/
Mar 10, 2014 @miscco First modular implementation of the thalamo-cortical model.
138 void Cortical_Column::set_RK (int N) {
Sep 13, 2016 @miscco Major cleanup and moderinization
139 extern const double dt;
140 Vp [N+1] = Vp [0] + A[N] * dt*(-(I_L_p(N) + I_ep(N) + I_gp(N))/tau_p - I_KNa(N));
141 Vi [N+1] = Vi [0] + A[N] * dt*(-(I_L_i(N) + I_ei(N) + I_gi(N))/tau_i);
142 Na [N+1] = Na [0] + A[N] * dt*(alpha_Na * get_Qp(N) - Na_pump(N))/tau_Na;
143 s_ep[N+1] = s_ep[0] + A[N] * dt*(x_ep[N]);
144 s_ei[N+1] = s_ei[0] + A[N] * dt*(x_ei[N]);
145 s_gp[N+1] = s_gp[0] + A[N] * dt*(x_gp[N]);
146 s_gi[N+1] = s_gi[0] + A[N] * dt*(x_gi[N]);
147 y [N+1] = y [0] + A[N] * dt*(x [N]);
148 x_ep[N+1] = x_ep[0] + A[N] * dt*(gamma_e*gamma_e * (N_pp * get_Qp(N) + N_pt * Thalamus->y[N] - s_ep[N]) - 2 * gamma_e * x_ep[N]) + noise_xRK(N, 0);
149 x_ei[N+1] = x_ei[0] + A[N] * dt*(gamma_e*gamma_e * (N_ip * get_Qp(N) + N_it * Thalamus->y[N] - s_ei[N]) - 2 * gamma_e * x_ei[N]) + noise_xRK(N, 1) ;
150 x_gp[N+1] = x_gp[0] + A[N] * dt*(gamma_g*gamma_g * (N_pi * get_Qi(N) - s_gp[N]) - 2 * gamma_g * x_gp[N]);
151 x_gi[N+1] = x_gi[0] + A[N] * dt*(gamma_g*gamma_g * (N_ii * get_Qi(N) - s_gi[N]) - 2 * gamma_g * x_gi[N]);
152 x [N+1] = x [0] + A[N] * dt*(nu * nu * ( get_Qp(N) - y [N]) - 2 * nu * x [N]);
Mar 1, 2014 @miscco New implementation of the thalamo-cortical model
153 }
154
155 void Cortical_Column::add_RK(void) {
Sep 13, 2016 @miscco Major cleanup and moderinization
156 add_RK(Vp);
157 add_RK(Vi);
158 add_RK(Na);
159 add_RK(s_ep);
160 add_RK(s_ei);
161 add_RK(s_gp);
162 add_RK(s_gi);
163 add_RK(y);
164 add_RK_noise(x_ep, 0);
165 add_RK_noise(x_ei, 1);
166 add_RK(x_gp);
167 add_RK(x_gi);
168 add_RK(x);
169
170 /* Generate noise for the next iteration */
171 for (unsigned i=0; i<Rand_vars.size(); ++i) {
172 Rand_vars[i] = MTRands[i]() + input;
173 }
Mar 1, 2014 @miscco New implementation of the thalamo-cortical model
174 }