This repository has been archived by the owner on Mar 19, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Compile CVODES functions with each Stan model
In 2017, model compilation takes ~40-50 seconds. Compiling CVODES functions with each model adds about 7 seconds. Closes #209.
- Loading branch information
ariddell
committed
Jan 16, 2018
1 parent
5365e91
commit 1cc9432
Showing
2 changed files
with
102 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import unittest | ||
|
||
import pystan | ||
|
||
|
||
class TestCVODES(unittest.TestCase): | ||
|
||
def test_cvodes_program(self): | ||
# from integrate_ode_bdf.stan | ||
model_code = """ | ||
functions { | ||
real[] sho(real t, | ||
real[] y, | ||
real[] theta, | ||
real[] x, | ||
int[] x_int) { | ||
real dydt[2]; | ||
dydt[1] = y[2]; | ||
dydt[2] = -y[1] - theta[1] * y[2]; | ||
return dydt; | ||
} | ||
} | ||
data { | ||
int<lower=1> T; | ||
real y0_d[2]; | ||
real t0; | ||
real ts[T]; | ||
real theta_d[1]; | ||
real x[0]; | ||
int x_int[0]; | ||
} | ||
parameters { | ||
real y0_p[2]; | ||
real theta_p[1]; | ||
} | ||
model { | ||
real y_hat[T,2]; | ||
y_hat = integrate_ode_bdf(sho, y0_d, t0, ts, theta_d, x, x_int); | ||
y_hat = integrate_ode_bdf(sho, y0_d, t0, ts, theta_p, x, x_int); | ||
y_hat = integrate_ode_bdf(sho, y0_p, t0, ts, theta_d, x, x_int); | ||
y_hat = integrate_ode_bdf(sho, y0_p, t0, ts, theta_p, x, x_int); | ||
y_hat = integrate_ode_bdf(sho, y0_d, t0, ts, theta_d, x, x_int, 1e-10, 1e-10, 1e8); | ||
y_hat = integrate_ode_bdf(sho, y0_d, t0, ts, theta_p, x, x_int, 1e-10, 1e-10, 1e8); | ||
y_hat = integrate_ode_bdf(sho, y0_p, t0, ts, theta_d, x, x_int, 1e-10, 1e-10, 1e8); | ||
y_hat = integrate_ode_bdf(sho, y0_p, t0, ts, theta_p, x, x_int, 1e-10, 1e-10, 1e8); | ||
} | ||
generated quantities { | ||
real y_hat[T,2]; | ||
y_hat = integrate_ode_bdf(sho, y0_d, t0, ts, theta_d, x, x_int); | ||
y_hat = integrate_ode_bdf(sho, y0_d, t0, ts, theta_p, x, x_int); | ||
y_hat = integrate_ode_bdf(sho, y0_p, t0, ts, theta_d, x, x_int); | ||
y_hat = integrate_ode_bdf(sho, y0_p, t0, ts, theta_p, x, x_int); | ||
y_hat = integrate_ode_bdf(sho, y0_d, t0, ts, theta_d, x, x_int, 1e-10, 1e-10, 1e8); | ||
y_hat = integrate_ode_bdf(sho, y0_d, t0, ts, theta_p, x, x_int, 1e-10, 1e-10, 1e8); | ||
y_hat = integrate_ode_bdf(sho, y0_p, t0, ts, theta_d, x, x_int, 1e-10, 1e-10, 1e8); | ||
y_hat = integrate_ode_bdf(sho, y0_p, t0, ts, theta_p, x, x_int, 1e-10, 1e-10, 1e8); | ||
} | ||
""" | ||
model = pystan.StanModel(model_code=model_code, verbose=True) | ||
self.assertIsNotNone(model) |