Skip to main content

sde

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

FieldRequiredDescription
nameyesModel name
paramsyesParameter identifiers
covariatesnoCovariate identifiers
statesyesState identifiers
outputsyesOutput identifiers
particlesyesNumber of particles for the simulation
routesnoRoute declarations
driftyesClosure |x, p, t, dx, cov| { … } for the deterministic drift
diffusionyesClosure |p, sigma| { … } setting per‑state diffusion coefficients
lagnoLag‑time closure
fanoBioavailability closure
initnoInitial‑state closure
outyesOutput 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;
    },
};