GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — pharmsol/examples/dsl_analytical_covariates.rs at main · LAPKB/pharmsol

Expand file tree

/

dsl_analytical_covariates.rs

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
99 lines (85 loc) · 2.78 KB
/

dsl_analytical_covariates.rs

Copy path

File metadata and controls

99 lines (85 loc) · 2.78 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//! Demonstrates JIT compilation of an analytical model from DSL source text,
//! compared against the equivalent `analytical!` macro.
//!
//! A one-compartment oral model with weight-based covariate scaling is defined
//! both as a DSL string (compiled at runtime) and as a declarative macro.
//! Predictions from both paths are printed side by side to verify parity.
//!
//! Run with:
//! cargo run --example dsl_analytical_covariates --features dsl
#[cfg(feature = "dsl")]
fn main() -> Result<(), Box<dyn std::error::Error>> {
use std::io;
use pharmsol::{prelude::*, Parameters};
let model_source = r#"
name = one_cmt_covariates
kind = analytical
params = ka, ke0, v
covariates = wt@linear
derived = ke
states = gut, central
outputs = cp
bolus(oral) -> gut
ke = ke0 * pow(wt / 70.0, 0.75)
structure = one_compartment_with_absorption
out(cp) = central / v ~ continuous()
"#;
let jit_model = pharmsol::dsl::compile_module_source_to_runtime(
model_source,
Some("one_cmt_covariates"),
|_kind, _message| {},
)?;
let analytical = analytical! {
name: "one_cmt_covariates",
params: [ke0, ka, v],
derived: [ke],
covariates: [wt],
states: [gut, central],
outputs: [cp],
routes: [
bolus(oral) -> gut,
],
structure: one_compartment_with_absorption,
derive: |_t| {
ke = ke0 * (wt / 70.0).powf(0.75);
},
out: |x, _t, y| {
y[cp] = x[central] / v;
},
};
let subject = Subject::builder("covariates")
.bolus(0.0, 100.0, "oral")
.missing_observation(0.5, "cp")
.missing_observation(1.0, "cp")
.missing_observation(2.0, "cp")
.missing_observation(4.0, "cp")
.covariate("wt", 0.0, 75.0)
.build();
let values = [("ka", 1.2), ("ke0", 0.08), ("v", 20.0)];
let jit_parameters = Parameters::with_model(&jit_model, values)?;
let analytical_parameters = Parameters::with_model(&analytical, values)?;
let jit_predictions = jit_model
.predict(&subject, &jit_parameters)?
.into_subject()
.ok_or_else(|| io::Error::other("expected subject predictions"))?;
let analytical_predictions = analytical.predict(&subject, &analytical_parameters)?;
println!("t dsl analytical!");
for (jit, analytical) in jit_predictions
.predictions()
.iter()
.zip(analytical_predictions.predictions())
{
println!(
"{:<4.1} {:>12.6} {:>16.6}",
jit.time(),
jit.prediction(),
analytical.prediction()
);
}
Ok(())
}
#[cfg(not(feature = "dsl"))]
fn main() {
eprintln!("Run with: cargo run --example dsl_analytical_covariates --features dsl");
std::process::exit(1);
}
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.