pub struct BestDoseProblem { /* private fields */ }Expand description
The BestDose optimization problem
Contains all data needed for the three-stage BestDose algorithm.
Create via BestDoseProblem::new(), then call .optimize()
to run the full algorithm.
§Three-Stage Algorithm
-
Posterior Density Calculation (automatic in
new())- NPAGFULL11: Bayesian filtering of prior support points
- NPAGFULL: Local refinement of each filtered point
-
Dual Optimization (automatic in
optimize())- Optimization with posterior weights (patient-specific)
- Optimization with uniform weights (population-based)
- Selection of better result
-
Final Predictions (automatic in
optimize())- Concentration or AUC predictions with optimal doses
§Fields
§Input Data
target: Future dosing template with target observationstarget_type:Target::Concentrationor [Target::AUC]
§Population Prior
population_weights: Filtered population probability weights (used for bias term)
§Patient-Specific Posterior
theta: Refined posterior support points (from NPAGFULL11 + NPAGFULL)posterior: Posterior probability weights
§Model Components
eq: Pharmacokinetic/pharmacodynamic ODE modelsettings: NPAG configuration settings (used for prediction grid)
§Optimization Parameters
doserange: Min/max dose constraintsbias_weight(λ): Personalization parameter (0=personalized, 1=population)
§Example
ⓘ
use pmcore::bestdose::{BestDoseProblem, Target, DoseRange};
let problem = BestDoseProblem::new(
&population_theta,
&population_weights,
Some(past), // Patient history
target, // Dosing template with targets
eq,
error_models,
DoseRange::new(0.0, 1000.0),
0.5, // Balanced personalization
settings,
500, // NPAGFULL cycles
Target::Concentration,
)?;
let result = problem.optimize()?;Implementations§
Source§impl BestDoseProblem
impl BestDoseProblem
Sourcepub fn new(
population_theta: &Theta,
population_weights: &Weights,
past_data: Option<Subject>,
target: Subject,
time_offset: Option<f64>,
eq: ODE,
doserange: DoseRange,
bias_weight: f64,
settings: Settings,
target_type: Target,
) -> Result<Self>
pub fn new( population_theta: &Theta, population_weights: &Weights, past_data: Option<Subject>, target: Subject, time_offset: Option<f64>, eq: ODE, doserange: DoseRange, bias_weight: f64, settings: Settings, target_type: Target, ) -> Result<Self>
Create a new BestDose problem with automatic posterior calculation
This is the main entry point for the BestDose algorithm.
§Algorithm Structure (Matches Flowchart)
┌─────────────────────────────────────────┐
│ STAGE 1: Posterior Density Calculation │
│ │
│ Prior Density (N points) │
│ ↓ │
│ Has past data with observations? │
│ ↓ Yes ↓ No │
│ Step 1.1: Use prior │
│ NPAGFULL11 directly │
│ (Filter) │
│ ↓ │
│ Step 1.2: │
│ NPAGFULL │
│ (Refine) │
│ ↓ │
│ Posterior Density │
└─────────────────────────────────────────┘§Parameters
population_theta- Population support points from NPAGpopulation_weights- Population probabilitiespast_data- Patient history (None = use prior directly)target- Future dosing template with targetstime_offset- Optional time offset for concatenation (None = standard mode, Some(t) = Fortran mode)eq- Pharmacokinetic/pharmacodynamic modelerror_models- Error model specificationsdoserange- Allowable dose constraintsbias_weight- λ ∈ [0,1]: 0=personalized, 1=populationsettings- NPAG settings for posterior refinementmax_cycles- NPAGFULL cycles (0=skip refinement, 500=default)target_type- Concentration or AUC targets
§Returns
BestDoseProblem ready for optimize()
Sourcepub fn optimize(self) -> Result<BestDoseResult>
pub fn optimize(self) -> Result<BestDoseResult>
Run the complete BestDose optimization algorithm
§Algorithm Flow (Matches Diagram!)
┌─────────────────────────────────────────┐
│ STAGE 1: Posterior Calculation │
│ [COMPLETED in new()] │
└────────────┬────────────────────────────┘
↓
┌─────────────────────────────────────────┐
│ STAGE 2: Dual Optimization │
│ │
│ Optimization 1: Posterior Weights │
│ (Patient-specific) │
│ ↓ │
│ Result 1: (doses₁, cost₁) │
│ │
│ Optimization 2: Uniform Weights │
│ (Population-based) │
│ ↓ │
│ Result 2: (doses₂, cost₂) │
│ │
│ Select: min(cost₁, cost₂) │
└────────────┬────────────────────────────┘
↓
┌─────────────────────────────────────────┐
│ STAGE 3: Final Predictions │
│ │
│ Calculate predictions with │
│ optimal doses and winning weights │
└─────────────────────────────────────────┘§Returns
BestDoseResult containing:
dose: Optimal dose amount(s)objf: Final cost function valuepreds: Concentration-time predictionsauc_predictions: AUC values (if target_type is AUC)optimization_method: “posterior” or “uniform”
Sourcepub fn with_bias_weight(self, weight: f64) -> Self
pub fn with_bias_weight(self, weight: f64) -> Self
Set the bias weight (lambda parameter)
- λ = 0.0 (default): Full personalization (minimize patient-specific variance)
- λ = 0.5: Balanced between individual and population
- λ = 1.0: Population-based (minimize deviation from population mean)
Trait Implementations§
Source§impl Clone for BestDoseProblem
impl Clone for BestDoseProblem
Source§fn clone(&self) -> BestDoseProblem
fn clone(&self) -> BestDoseProblem
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl CostFunction for BestDoseProblem
Implement CostFunction trait for BestDoseProblem
impl CostFunction for BestDoseProblem
Implement CostFunction trait for BestDoseProblem
This allows the Nelder-Mead optimizer to evaluate candidate doses.
§fn bulk_cost<P>(&self, params: &[P]) -> Result<Vec<Self::Output>, Error>where
P: Borrow<Self::Param> + SyncAlias,
Self::Output: SendAlias,
Self: SyncAlias,
fn bulk_cost<P>(&self, params: &[P]) -> Result<Vec<Self::Output>, Error>where
P: Borrow<Self::Param> + SyncAlias,
Self::Output: SendAlias,
Self: SyncAlias,
Compute
cost in bulk. If the rayon feature is enabled, multiple calls to cost will be run in parallel using rayon, otherwise they will execute sequentially. If the rayon feature is enabled, parallelization can still be turned off by overwriting parallelize to return false. This can be useful in cases where it is preferable to parallelize only certain parts. Note that even if parallelize is set to false, the parameter vectors and the problem are still required to be Send and Sync. Those bounds are linked to the rayon feature. This method can be overwritten.§fn parallelize(&self) -> bool
fn parallelize(&self) -> bool
Indicates whether to parallelize calls to
cost when using bulk_cost. By default returns true, but can be set manually to false if needed. This allows users to turn off parallelization for certain traits implemented on their problem. Note that parallelization requires the rayon feature to be enabled, otherwise calls to cost will be executed sequentially independent of how parallelize is set.Auto Trait Implementations§
impl Freeze for BestDoseProblem
impl RefUnwindSafe for BestDoseProblem
impl Send for BestDoseProblem
impl Sync for BestDoseProblem
impl Unpin for BestDoseProblem
impl UnwindSafe for BestDoseProblem
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> Twhere
Self: Distribution<T>,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.