-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOrnsteinUhlenbeck.ino
65 lines (57 loc) · 2.99 KB
/
OrnsteinUhlenbeck.ino
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
/*
Copyright 2017. Niraj S. Desai, Richard Gray, and Daniel Johnston.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
// Synaptic background conductances according to the point conductance model (Destexhe et al., Neurosci., 2001).
// Excitatory and inhibitory conductance trains are generated by Ornstein-Uhlenbeck processes.
const int gaussianPoolSize = 100;
float gaussianNumbers[gaussianPoolSize] = {0.0};
// When the program is uploaded to the microcontroller, this function is called in order to create
// a pool of Gaussian random numbers for subsequent use by the OU processes
void GenerateGaussianNumbers() {
float x1,x2,w;
int nIter = round(gaussianPoolSize/2);
for (int x=0; x<nIter; x++) {
w = 20.0;
// Marsaglia polar method (a.k.a. Box-Mueller-Marsaglia) to obtain Gaussian random numbers
while (w >= 1.0) {
x1 = 2.0 * random(1001)/1000.0 - 1.0;
x2 = 2.0 * random(1001)/1000.0 - 1.0;
w = x1*x1 + x2*x2;
}
w = sqrtf((-2.0*logf(w))/w);
gaussianNumbers[2*x] = x1*w;
gaussianNumbers[2*x+1] = x2*w;
}
}
// This function calculates the current from the OU processes at every time step
// To integrate the OU processes, we use the approximation msecs << tauExc,tauInh
float OrnsteinUhlenbeck(float v) {
const float tauExc = 2.5; // msec, time constant of excitatory process
const float tauInh = 8.0; // msec, time constant of inhibitory process
static float gOU1 = 0.0; // nS, excitatory OU conductance
static float gOU2 = 0.0; // nS, inhibitory OU conductance
float y1 = gaussianNumbers[random(gaussianPoolSize)];
float y2 = gaussianNumbers[random(gaussianPoolSize)];
// gOU1 is excitatory and gOU2 is inhibitory
gOU1 = gOU1 + msecs*(-(gOU1-conducts[3])/tauExc) + sqrtf(conducts[4]*msecs)*y1;
gOU2 = gOU2 + msecs*(-(gOU2-conducts[5])/tauInh) + sqrtf(conducts[6]*msecs)*y2;
if (gOU1<0.0) gOU1=0.0;
if (gOU2<0.0) gOU2=0.0;
float current = -gOU1*v - gOU2*(v+80); // Reversal potentials (0 mV excitatory, -80 mV inhibitory)
return current;
}