Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion examples/bestdose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,25 @@ fn main() -> Result<()> {

// Print results
for (bias_weight, optimal) in &results {
let opt_doses = optimal
.optimal_subject
.iter()
.flat_map(|occ| {
occ.events()
.iter()
.filter_map(|event| match event {
Event::Bolus(bolus) => Some(bolus.amount()),
Event::Infusion(infusion) => Some(infusion.amount()),
_ => None,
})
.collect::<Vec<_>>()
})
.collect::<Vec<f64>>();

println!(
"Bias weight: {:.2}\t\t Optimal dose: {:?}\t\tCost: {:.6}\t\tln Cost: {:.4}\t\tMethod: {}",
bias_weight,
optimal.dose,
opt_doses,
optimal.objf,
optimal.objf.ln(),
optimal.optimization_method
Expand Down
17 changes: 16 additions & 1 deletion examples/bestdose_auc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,23 @@ fn main() -> Result<()> {
println!("Optimizing dose...\n");
let optimal = problem.optimize()?;

let opt_doses = optimal
.optimal_subject
.iter()
.flat_map(|occ| {
occ.events()
.iter()
.filter_map(|event| match event {
Event::Bolus(bolus) => Some(bolus.amount()),
Event::Infusion(infusion) => Some(infusion.amount()),
_ => None,
})
.collect::<Vec<_>>()
})
.collect::<Vec<f64>>();

println!("=== RESULTS ===");
println!("Optimal dose: {:.1} mg", optimal.dose[0]);
println!("Optimal dose: {:.1} mg", opt_doses[0]);
println!("Cost function: {:.6}", optimal.objf);

if let Some(auc_preds) = &optimal.auc_predictions {
Expand Down
4 changes: 2 additions & 2 deletions src/bestdose/cost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ use pharmsol::Equation;
///
/// # Dose Masking
///
/// When `problem.current_time` is set (past/future separation), only doses where
/// When `problem.time_offset` is set (past/future separation), only doses where
/// `dose_optimization_mask[i] == true` are updated with values from `candidate_doses`.
/// Past doses (mask == false) remain at their historical values.
///
Expand Down Expand Up @@ -239,7 +239,7 @@ pub fn calculate_cost(problem: &BestDoseProblem, candidate_doses: &[f64]) -> Res
.matrix()
.row_iter()
.zip(problem.posterior.iter()) // Posterior from NPAGFULL11 (patient-specific)
.zip(problem.prior_weights.iter())
.zip(problem.population_weights.iter())
// Prior (population)
{
let spp = row.iter().copied().collect::<Vec<f64>>();
Expand Down
Loading
Loading