Macro sde
sde!() { /* proc-macro */ }Expand description
Define an SDE (stochastic differential equation) model.
Builds a particle‑based stochastic model with a drift term, a diffusion
term, and a configurable number of particles. The macro generates an SDE
value with full metadata.
§Fields
| Field | Required | Description |
|---|---|---|
name | yes | Model name |
params | yes | Parameter identifiers |
covariates | no | Covariate identifiers |
states | yes | State identifiers |
outputs | yes | Output identifiers |
particles | yes | Number of particles for the simulation |
routes | no | Route declarations |
drift | yes | Closure |x, p, t, dx, cov| { … } for the deterministic drift |
diffusion | yes | Closure |p, sigma| { … } setting per‑state diffusion coefficients |
lag | no | Lag‑time closure |
fa | no | Bioavailability closure |
init | no | Initial‑state closure |
out | yes | Output mapping closure |
§Example
ⓘ
let model = sde! {
name: "one_cmt_sde",
params: [ke, sigma_ke, v],
states: [central],
outputs: [cp],
particles: 16,
routes: [infusion(iv) -> central],
drift: |x, _p, _t, dx, _cov| {
dx[central] = -ke * x[central];
},
diffusion: |_p, sigma| {
sigma[central] = sigma_ke;
},
out: |x, _p, _t, _cov, y| {
y[cp] = x[central] / v;
},
};