BestDoseProblem

Struct BestDoseProblem 

Source
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

  1. Posterior Density Calculation (automatic in new())

    • NPAGFULL11: Bayesian filtering of prior support points
    • NPAGFULL: Local refinement of each filtered point
  2. Dual Optimization (automatic in optimize())

    • Optimization with posterior weights (patient-specific)
    • Optimization with uniform weights (population-based)
    • Selection of better result
  3. Final Predictions (automatic in optimize())

    • Concentration or AUC predictions with optimal doses

§Fields

§Input Data

  • target: Future dosing template with target observations
  • target_type: Target::Concentration or [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 model
  • settings: NPAG configuration settings (used for prediction grid)

§Optimization Parameters

  • doserange: Min/max dose constraints
  • bias_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

Source

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 NPAG
  • population_weights - Population probabilities
  • past_data - Patient history (None = use prior directly)
  • target - Future dosing template with targets
  • time_offset - Optional time offset for concatenation (None = standard mode, Some(t) = Fortran mode)
  • eq - Pharmacokinetic/pharmacodynamic model
  • error_models - Error model specifications
  • doserange - Allowable dose constraints
  • bias_weight - λ ∈ [0,1]: 0=personalized, 1=population
  • settings - NPAG settings for posterior refinement
  • max_cycles - NPAGFULL cycles (0=skip refinement, 500=default)
  • target_type - Concentration or AUC targets
§Returns

BestDoseProblem ready for optimize()

Source

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 value
  • preds: Concentration-time predictions
  • auc_predictions: AUC values (if target_type is AUC)
  • optimization_method: “posterior” or “uniform”
Source

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

Source§

fn clone(&self) -> BestDoseProblem

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl CostFunction for BestDoseProblem

Implement CostFunction trait for BestDoseProblem

This allows the Nelder-Mead optimizer to evaluate candidate doses.

Source§

type Param = Vec<f64>

Type of the parameter vector
Source§

type Output = f64

Type of the return value of the cost function
Source§

fn cost(&self, param: &Self::Param) -> Result<Self::Output>

Compute cost function
§

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

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.
Source§

impl Debug for BestDoseProblem

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> ByRef<T> for T

§

fn by_ref(&self) -> &T

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> DistributionExt for T
where T: ?Sized,

§

fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> T
where Self: Distribution<T>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

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

Checks if self is actually part of its subset T (and can be converted to it).
§

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

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> SendAlias for T

§

impl<T> SyncAlias for T