Skip to content

Commit 14d8219

Browse files
authored
Merge pull request #184 from stan-dev/convert-odes
Updated links to model code/data for convert ODEs case study
2 parents 327a3da + 3588380 commit 14d8219

File tree

2 files changed

+61
-23
lines changed

2 files changed

+61
-23
lines changed

knitr/convert-odes/convert_odes.Rmd

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
---
22
title: "Upgrading to the new ODE interface"
33
author: "Ben Bales & Sebastian Weber"
4-
date: "19 July 2020"
4+
date: "26 July 2020"
55
output: html_document
66
---
77

88
# Introduction
99

1010
Cmdstan 2.24 introduces a new ODE interface intended to make it easier to
11-
specify the ODE RHS by avoiding packing and unpacking schemes required with
11+
specify the ODE system function by avoiding packing and unpacking schemes required with
1212
the old interface.
1313

1414
Stan solves for $y(t, \theta)$ at a sequence of times $t_1, t_2, \cdots, t_N$
@@ -276,18 +276,28 @@ output is an array of vectors (`vector[]`).
276276

277277
```{stan, output.var = "", eval = FALSE}
278278
transformed parameters {
279-
vector<lower=0>[4] y[N_t] = ode_rk45(simple_SIR, y0, t0, t, beta, kappa, gamma, xi, delta);
279+
vector<lower=0>[4] y[N_t] = ode_rk45(simple_SIR, y0, t0, t,
280+
beta, kappa, gamma, xi, delta);
281+
}
282+
```
283+
284+
The `ode_rk45_tol` function can be used to specify tolerances manually:
285+
286+
```{stan, output.var = "", eval = FALSE}
287+
transformed parameters {
288+
vector<lower=0>[4] y[N_t] = ode_rk45_tol(simple_SIR, y0, t0, t,
289+
1e-6, 1e-6, 1000,
290+
beta, kappa, gamma, xi, delta);
280291
}
281292
```
282293

283294
### Full Model
284295

285-
The full model with the new interface can be found
286-
[here](https://github.com/stan-dev/stat_comp_benchmarks/blob/feature/variadic-odes/benchmarks/sir/sir.stan);
287-
the full model with the old interface can be found
288-
[here](https://github.com/stan-dev/stat_comp_benchmarks/blob/master/benchmarks/sir/sir.stan),
289-
and the data can be found
290-
[here](https://github.com/stan-dev/stat_comp_benchmarks/blob/master/benchmarks/sir/sir.data.R).
296+
The full model with the new interface is
297+
[here](https://github.com/stan-dev/stat_comp_benchmarks/blob/master/benchmarks/sir/sir.stan) and the data is [here](https://github.com/stan-dev/stat_comp_benchmarks/blob/master/benchmarks/sir/sir.data.R).
298+
299+
The full model with the old interface is
300+
[here](https://github.com/stan-dev/stat_comp_benchmarks/blob/64b6597cd17de77e91dcfb1a9977758407017d20/benchmarks/sir/sir.stan), and the data is [here](https://github.com/stan-dev/stat_comp_benchmarks/blob/64b6597cd17de77e91dcfb1a9977758407017d20/benchmarks/sir/sir.data.R).
291301

292302
## PKPD Model
293303

@@ -373,14 +383,26 @@ In the new interface the arguments are simply passed at the end of the
373383

374384
```{stan, output.var = "", eval = FALSE}
375385
transformed parameters {
376-
vector[1] C[N_t] = ode_bdf(one_comp_mm_elim_abs, C0, t0, times, k_a, K_m, V_m, D, V);
386+
vector[1] mu_C[N_t] = ode_bdf(one_comp_mm_elim_abs, C0, t0, times,
387+
k_a, K_m, V_m, D, V);
388+
}
389+
```
390+
391+
The `ode_bdf_tol` function can be used to specify tolerances manually:
392+
393+
```{stan, output.var = "", eval = FALSE}
394+
transformed parameters {
395+
vector[1] mu_C[N_t] = ode_bdf_tol(one_comp_mm_elim_abs, C0, t0, times,
396+
1e-8, 1e-8, 1000,
397+
k_a, K_m, V_m, D, V);
377398
}
378399
```
400+
379401
### Full Model
380402

381-
The full model with the new interface can be found
382-
[here](https://github.com/stan-dev/stat_comp_benchmarks/blob/feature/variadic-odes/benchmarks/one_comp_mm_elim_abs/one_comp_mm_elim_abs.stan);
383-
the full model with the old interface can be found
384-
[here](https://github.com/stan-dev/stat_comp_benchmarks/blob/master/benchmarks/pkpd/one_comp_mm_elim_abs.stan),
385-
and the data can be found
386-
[here](https://github.com/stan-dev/stat_comp_benchmarks/blob/master/benchmarks/pkpd/one_comp_mm_elim_abs.data.R).
403+
The full model with the new interface is
404+
[here](https://github.com/stan-dev/stat_comp_benchmarks/blob/master/benchmarks/one_comp_mm_elim_abs/one_comp_mm_elim_abs.stan) and the data is [here](https://github.com/stan-dev/stat_comp_benchmarks/blob/master/benchmarks/one_comp_mm_elim_abs/one_comp_mm_elim_abs.data.R).
405+
406+
The full model with the old interface is
407+
[here](https://github.com/stan-dev/stat_comp_benchmarks/blob/64b6597cd17de77e91dcfb1a9977758407017d20/benchmarks/pkpd/one_comp_mm_elim_abs.stan) and the data is [here](https://github.com/stan-dev/stat_comp_benchmarks/blob/64b6597cd17de77e91dcfb1a9977758407017d20/benchmarks/pkpd/one_comp_mm_elim_abs.data.R).
408+

knitr/convert-odes/convert_odes.html

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<meta name="author" content="Ben Bales &amp; Sebastian Weber" />
1313

14-
<meta name="date" content="2020-07-19" />
14+
<meta name="date" content="2020-07-26" />
1515

1616
<title>Upgrading to the new ODE interface</title>
1717

@@ -365,14 +365,14 @@
365365

366366
<h1 class="title toc-ignore">Upgrading to the new ODE interface</h1>
367367
<h4 class="author">Ben Bales &amp; Sebastian Weber</h4>
368-
<h4 class="date">19 July 2020</h4>
368+
<h4 class="date">26 July 2020</h4>
369369

370370
</div>
371371

372372

373373
<div id="introduction" class="section level1">
374374
<h1>Introduction</h1>
375-
<p>Cmdstan 2.24 introduces a new ODE interface intended to make it easier to specify the ODE RHS by avoiding packing and unpacking schemes required with the old interface.</p>
375+
<p>Cmdstan 2.24 introduces a new ODE interface intended to make it easier to specify the ODE system function by avoiding packing and unpacking schemes required with the old interface.</p>
376376
<p>Stan solves for <span class="math inline">\(y(t, \theta)\)</span> at a sequence of times <span class="math inline">\(t_1, t_2, \cdots, t_N\)</span> in the ODE initial value problem defined by:</p>
377377
<p><span class="math display">\[
378378
y(t, \theta)' = f(t, y, \theta)\\
@@ -506,12 +506,20 @@ <h3>Calling the ODE Solver</h3>
506506
}</code></pre>
507507
<p>In the new ODE interface each of the arguments is appended on to the ODE solver function call. The RK45 ODE solver with default tolerances is called <code>ode_rk45</code>. Because the states are handled as <code>vector</code> variables, the solver output is an array of vectors (<code>vector[]</code>).</p>
508508
<pre class="stan"><code>transformed parameters {
509-
vector&lt;lower=0&gt;[4] y[N_t] = ode_rk45(simple_SIR, y0, t0, t, beta, kappa, gamma, xi, delta);
509+
vector&lt;lower=0&gt;[4] y[N_t] = ode_rk45(simple_SIR, y0, t0, t,
510+
beta, kappa, gamma, xi, delta);
511+
}</code></pre>
512+
<p>The <code>ode_rk45_tol</code> function can be used to specify tolerances manually:</p>
513+
<pre class="stan"><code>transformed parameters {
514+
vector&lt;lower=0&gt;[4] y[N_t] = ode_rk45_tol(simple_SIR, y0, t0, t,
515+
1e-6, 1e-6, 1000,
516+
beta, kappa, gamma, xi, delta);
510517
}</code></pre>
511518
</div>
512519
<div id="full-model" class="section level3">
513520
<h3>Full Model</h3>
514-
<p>The full model with the new interface can be found <a href="https://github.com/stan-dev/stat_comp_benchmarks/blob/feature/variadic-odes/benchmarks/sir/sir.stan">here</a>; the full model with the old interface can be found <a href="https://github.com/stan-dev/stat_comp_benchmarks/blob/master/benchmarks/sir/sir.stan">here</a>, and the data can be found <a href="https://github.com/stan-dev/stat_comp_benchmarks/blob/master/benchmarks/sir/sir.data.R">here</a>.</p>
521+
<p>The full model with the new interface is <a href="https://github.com/stan-dev/stat_comp_benchmarks/blob/master/benchmarks/sir/sir.stan">here</a> and the data is <a href="https://github.com/stan-dev/stat_comp_benchmarks/blob/master/benchmarks/sir/sir.data.R">here</a>.</p>
522+
<p>The full model with the old interface is <a href="https://github.com/stan-dev/stat_comp_benchmarks/blob/64b6597cd17de77e91dcfb1a9977758407017d20/benchmarks/sir/sir.stan">here</a>, and the data is <a href="https://github.com/stan-dev/stat_comp_benchmarks/blob/64b6597cd17de77e91dcfb1a9977758407017d20/benchmarks/sir/sir.data.R">here</a>.</p>
515523
</div>
516524
</div>
517525
<div id="pkpd-model" class="section level2">
@@ -582,12 +590,20 @@ <h3>Calling the ODE Solver</h3>
582590
}</code></pre>
583591
<p>In the new interface the arguments are simply passed at the end of the <code>ode_bdf</code> call (and the <code>transformed data</code> block removed):</p>
584592
<pre class="stan"><code>transformed parameters {
585-
vector[1] C[N_t] = ode_bdf(one_comp_mm_elim_abs, C0, t0, times, k_a, K_m, V_m, D, V);
593+
vector[1] mu_C[N_t] = ode_bdf(one_comp_mm_elim_abs, C0, t0, times,
594+
k_a, K_m, V_m, D, V);
595+
}</code></pre>
596+
<p>The <code>ode_bdf_tol</code> function can be used to specify tolerances manually:</p>
597+
<pre class="stan"><code>transformed parameters {
598+
vector[1] mu_C[N_t] = ode_bdf_tol(one_comp_mm_elim_abs, C0, t0, times,
599+
1e-8, 1e-8, 1000,
600+
k_a, K_m, V_m, D, V);
586601
}</code></pre>
587602
</div>
588603
<div id="full-model-1" class="section level3">
589604
<h3>Full Model</h3>
590-
<p>The full model with the new interface can be found <a href="https://github.com/stan-dev/stat_comp_benchmarks/blob/feature/variadic-odes/benchmarks/one_comp_mm_elim_abs/one_comp_mm_elim_abs.stan">here</a>; the full model with the old interface can be found <a href="https://github.com/stan-dev/stat_comp_benchmarks/blob/master/benchmarks/pkpd/one_comp_mm_elim_abs.stan">here</a>, and the data can be found <a href="https://github.com/stan-dev/stat_comp_benchmarks/blob/master/benchmarks/pkpd/one_comp_mm_elim_abs.data.R">here</a>.</p>
605+
<p>The full model with the new interface is <a href="https://github.com/stan-dev/stat_comp_benchmarks/blob/master/benchmarks/one_comp_mm_elim_abs/one_comp_mm_elim_abs.stan">here</a> and the data is <a href="https://github.com/stan-dev/stat_comp_benchmarks/blob/master/benchmarks/one_comp_mm_elim_abs/one_comp_mm_elim_abs.data.R">here</a>.</p>
606+
<p>The full model with the old interface is <a href="https://github.com/stan-dev/stat_comp_benchmarks/blob/64b6597cd17de77e91dcfb1a9977758407017d20/benchmarks/pkpd/one_comp_mm_elim_abs.stan">here</a> and the data is <a href="https://github.com/stan-dev/stat_comp_benchmarks/blob/64b6597cd17de77e91dcfb1a9977758407017d20/benchmarks/pkpd/one_comp_mm_elim_abs.data.R">here</a>.</p>
591607
</div>
592608
</div>
593609
</div>

0 commit comments

Comments
 (0)