Module cost

Module cost 

Source
Expand description

Cost function calculation for BestDose optimization

Implements the hybrid cost function that balances patient-specific performance (variance) with population-level robustness (bias). Also enforces dose range constraints through penalty-based bounds checking.

§Cost Function

Cost = {
  (1-λ) × Variance + λ × Bias²,  if doses within bounds
  1e12 + violation² × 1e6,        if any dose violates bounds
}

§Variance Term (Patient-Specific)

Expected squared prediction error using posterior weights:

Variance = Σᵢ posterior_weight[i] × Σⱼ (target[j] - pred[i,j])²
  • Weighted by patient-specific posterior probabilities
  • Minimizes expected error for this specific patient
  • Emphasizes parameter values compatible with patient history

§Bias Term (Population-Level)

Squared deviation from population mean prediction using prior weights:

Bias² = Σⱼ (target[j] - population_mean[j])²
where population_mean[j] = Σᵢ prior_weight[i] × pred[i,j]
  • Weighted by population prior probabilities
  • Minimizes deviation from population-typical behavior
  • Provides robustness when patient history is limited

§Bias Weight Parameter (λ)

  • λ = 0.0: Pure personalization (minimize variance only)
  • λ = 0.5: Balanced hybrid approach
  • λ = 1.0: Pure population (minimize bias only)

§Implementation Notes

The cost function handles both concentration and AUC targets:

  • Concentration: Simulates model at observation times directly
  • AUC: Generates dense time grid and calculates cumulative AUC via trapezoidal rule

See calculate_cost for the main implementation.

Functions§

calculate_cost
Calculate cost function for a candidate dose regimen