diff --git a/examples/rosuva/config.toml b/examples/rosuva/config.toml deleted file mode 100644 index 92ceecb69..000000000 --- a/examples/rosuva/config.toml +++ /dev/null @@ -1,34 +0,0 @@ -[paths] -data = "examples/data/rosuva_slim.csv" -log_out = "log/rosuva_slim.log" -#prior_dist = "theta_rosuva_slim.csv" - -[config] -cycles = 100 -engine = "NPAG" -init_points = 10000 -seed = 347 -tui = true -pmetrics_outputs = true -cache = true - -[random] -Ka=[0.0,10.0] -K15=[0.0,15.0] -K16=[0.0,12.0] -K23=[0.0,12.0] -K32=[0.0,12.0] -K24=[0.0,10.0] -K42=[0.0,20.0] -K20=[0.0,4.0] -tlag1=[0.0,0.8] -tlag2=[0.0,10.0] -tlag3=[0.0,10.0] -FA1=[0.01, 1.0] -V=[0.0,350.0] -LAM=[0.0, 20.0] - -[error] -value = 5.0 -class = "proportional" -poly = [0.0005495041, 0.0342807720, 0.0001165904, 0.0] diff --git a/examples/rosuva/main-old.rs b/examples/rosuva/main-old.rs deleted file mode 100644 index 5539105f8..000000000 --- a/examples/rosuva/main-old.rs +++ /dev/null @@ -1,233 +0,0 @@ -#![allow(dead_code)] -#![allow(unused_variables)] -#![allow(non_snake_case)] -use std::collections::HashMap; - -use eyre::Result; -use npcore::prelude::{ - datafile::{CovLine, Infusion, Scenario}, - predict::{Engine, Predict}, - start, -}; -use ode_solvers::*; -const ATOL: f64 = 1e-4; -const RTOL: f64 = 1e-4; - -#[derive(Debug, Clone)] -struct Model<'a> { - FA1: f64, - Ka: f64, - K15: f64, - K16: f64, - K20: f64, - K23: f64, - K24: f64, - K32: f64, - K42: f64, - LAM: f64, - tlag1: f64, - tlag2: f64, - tlag3: f64, - V: f64, - _scenario: &'a Scenario, - infusions: Vec, - cov: Option<&'a HashMap>, -} - -type State = Vector6; -type Time = f64; - -impl ode_solvers::System for Model<'_> { - fn system(&self, t: Time, x: &State, dy: &mut State) { - let Ka = self.Ka; - let K15 = self.K15; - let K16 = self.K16; - let K23 = self.K23; - let K32 = self.K32; - let K24 = self.K24; - let K42 = self.K42; - let K20 = self.K20; - let LAM = self.LAM; // Change this accordingly - let tlag1 = self.tlag1; - let tlag2 = self.tlag2; - let tlag3 = self.tlag3; - let FA1 = self.FA1; - let V = self.V; - let K12 = Ka * (0.5 * (1.0 + (LAM * (t - tlag1)).atan() * (2.0 / std::f64::consts::PI))); - let K52 = Ka * (0.5 * (1.0 + (LAM * (t - tlag2)).atan() * (2.0 / std::f64::consts::PI))); - let K62 = Ka * (0.5 * (1.0 + (LAM * (t - tlag3)).atan() * (2.0 / std::f64::consts::PI))); - - let mut rateiv = [0.0]; - for infusion in &self.infusions { - if t >= infusion.time && t <= (infusion.dur + infusion.time) { - rateiv[infusion.compartment] += infusion.amount / infusion.dur; - } - } - - ///////////////////// USER DEFINED /////////////// - - dy[0] = -K12 * x[0] - K15 * x[0] - K16 * x[0]; - dy[1] = K12 * x[0] + K52 * x[4] + K62 * x[5] - K23 * x[1] + K32 * x[2] - K24 * x[1] - + K42 * x[3] - - K20 * x[1]; - dy[2] = K23 * x[1] - K32 * x[2]; - dy[3] = K24 * x[1] - K42 * x[3]; - dy[4] = K15 * x[0] - K52 * x[4]; - dy[5] = K16 * x[0] - K62 * x[5]; - - //////////////// END USER DEFINED //////////////// - } -} -#[derive(Debug, Clone)] -struct Ode {} - -impl Predict for Ode { - fn predict(&self, params: Vec, scenario: &Scenario) -> Vec { - let mut system = Model { - FA1: params[0], - Ka: params[1], - K15: params[2], - K16: params[3], - K20: params[4], - K23: params[5], - K24: params[6], - K32: params[7], - K42: params[8], - LAM: params[9], - tlag1: params[10], - tlag2: params[11], - tlag3: params[12], - V: params[13], - _scenario: scenario, - infusions: vec![], - cov: None, - }; - let lag = 0.0; - let mut yout = vec![]; - let mut x = State::new(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); - let mut index: usize = 0; - for block in &scenario.blocks { - //if no code is needed here, remove the blocks from the codebase - //It seems that blocks is an abstractions we're going to end up not using - system.cov = Some(&block.covs); - for event in &block.events { - let lag_time = event.time + lag; - if event.evid == 1 { - if event.dur.unwrap_or(0.0) > 0.0 { - //infusion - system.infusions.push(Infusion { - time: lag_time, - dur: event.dur.unwrap(), - amount: event.dose.unwrap(), - compartment: event.input.unwrap() - 1, - }); - // x = simulate_next_state(x, &system, scenario, event, index); - if let Some(next_time) = scenario.times.get(index + 1) { - if *next_time > event.time { - let mut stepper = Dopri5::new( - system.clone(), - event.time, - *next_time, - 1e-3, - x, - RTOL, - ATOL, - ); - - let _res = stepper.integrate(); - let y = stepper.y_out(); - x = *y.last().unwrap(); - } else if *next_time < event.time { - log::error!("Panic: Next event's time is in the past!"); - panic!("Panic: Next event's time is in the past!"); - } - } - } else { - //dose - if lag > 0.0 { - // let mut stepper = - // Rk4::new(system.clone(), event.time, x, lag_time, 0.1); - if let Some(next_time) = scenario.times.get(index + 1) { - if *next_time < lag_time { - log::error!("Panic: lag time overpasses next observation, not implemented. Stopping."); - panic!("Panic: lag time overpasses next observation, not implemented. Stopping."); - } - let mut stepper = Dopri5::new( - system.clone(), - event.time, - lag_time, - 1e-3, - x, - RTOL, - ATOL, - ); - - let _int = stepper.integrate(); - let y = stepper.y_out(); - x = *y.last().unwrap(); - } - } - - x[event.input.unwrap() - 1] += event.dose.unwrap(); - if let Some(next_time) = scenario.times.get(index + 1) { - if *next_time > lag_time { - let mut stepper = Dopri5::new( - system.clone(), - lag_time, - *next_time, - 1e-3, - x, - RTOL, - ATOL, - ); - - let _res = stepper.integrate(); - let y = stepper.y_out(); - x = *y.last().unwrap(); - } else if *next_time > event.time { - log::error!("Panic: Next event's time is in the past!"); - panic!("Panic: Next event's time is in the past!"); - } - } - } - } else if event.evid == 0 { - //obs - let vd = params[12]; - yout.push(x[1] / vd); - if let Some(next_time) = scenario.times.get(index + 1) { - // let mut stepper = Rk4::new(system.clone(), lag_time, x, *next_time, 0.1); - if *next_time > event.time { - let mut stepper = Dopri5::new( - system.clone(), - event.time, - *next_time, - 0.01, - x, - 1e-4, - 1e-4, - ); - - let _res = stepper.integrate(); - let y = stepper.y_out(); - x = *y.last().unwrap(); - } else if *next_time < event.time { - log::error!("Panic: Next event's time is in the past!"); - panic!("Panic: Next event's time is in the past!"); - } - } - } - index += 1; - } - } - yout - } -} - -fn main() -> Result<()> { - start( - Engine::new(Ode {}), - "examples/rosuva/config.toml".to_string(), - )?; - - Ok(()) -}