-
Notifications
You must be signed in to change notification settings - Fork 2
/
epileptor_sde_euler_cen.stan
81 lines (60 loc) · 1.54 KB
/
epileptor_sde_euler_cen.stan
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
data {
int nt;
real dt;
real eta_true;
real x_init;
real z_init;
real xlim[2];
real zlim[2];
real I1;
real tau0;
vector[nt] xs;
}
transformed data {
}
parameters {
vector<lower=xlim[1], upper=xlim[2]>[nt] x;
vector<lower=zlim[1], upper=zlim[2]>[nt] z;
real eta;
real <lower=0.0> amplitude;
real offset;
real<lower=0.0> eps;
real<lower=0.0> sig;
}
model {
vector[nt] xhat;
vector[nt] zhat;
x[1] ~ normal(x_init, 1.);
z[1] ~ normal(z_init, 1.);
//eta ~ normal(eta_true, 1.);
amplitude ~ normal(1.,1.);
offset ~ normal(0., 1.);
eps ~ normal(0., 1.);
sig ~ normal(0., 1.);
for (t in 1:(nt-1)) {
real dx = 1.0 - x[t]*x[t]*x[t] - 2.0*x[t]*x[t] - z[t] + I1;
real dz = (1.0/tau0)*(4*(x[t] - eta) - z[t] );
x[t+1] ~ normal(x[t] + dt*dx, sqrt(dt)*sig);
z[t+1] ~ normal(z[t] + dt*dz, sqrt(dt)*sig);
}
xhat=amplitude*x+offset;
zhat=amplitude*z+offset;
//xs ~ normal(xhat, eps);
target+=normal_lpdf(xs| xhat, eps);
}
generated quantities {
vector[nt] xhat_q;
vector[nt] zhat_q;
vector[nt] x_ppc;
vector[nt] z_ppc;
vector[nt] log_lik;
xhat_q=amplitude*x+offset;
zhat_q=amplitude*z+offset;
for (i in 1:nt){
x_ppc[i] = normal_rng(xhat_q[i], eps);
z_ppc[i] = normal_rng(zhat_q[i], eps);
}
for (i in 1:nt){
log_lik[i] = normal_lpdf(xs[i]| xhat_q[i], eps);
}
}