Core Types
The main types exported by ferx_core. All types are available via use ferx_core::*.
CompiledModel
A parsed and compiled model ready for estimation. Created by parse_model_file() or parse_full_model_file().
pub struct CompiledModel {
pub name: String,
pub pk_model: PkModel,
pub error_model: ErrorModel,
pub pk_param_fn: PkParamFn, // (theta, eta, covariates) -> PkParams
pub n_theta: usize,
pub n_eta: usize,
pub n_epsilon: usize,
pub theta_names: Vec<String>,
pub eta_names: Vec<String>,
pub default_params: ModelParameters,
pub tv_fn: Option<...>, // Typical values function for analytical PK
pub pk_indices: Vec<usize>, // Maps eta index -> PK parameter index
pub ode_spec: Option<OdeSpec>, // ODE specification (if ODE model)
}Key fields: - pk_param_fn: Closure that maps (theta, eta, covariates) to PK parameters. Generated by the parser from [individual_parameters]. - default_params: Initial parameter values from [parameters] block. - ode_spec: Present only for ODE models; None for analytical models.
Population and Subject
pub struct Population {
pub subjects: Vec<Subject>,
pub covariate_names: Vec<String>,
pub dv_column: String,
}
pub struct Subject {
pub id: String,
pub doses: Vec<DoseEvent>,
pub obs_times: Vec<f64>,
pub observations: Vec<f64>,
pub obs_cmts: Vec<usize>,
pub covariates: HashMap<String, f64>, // Subject-static fallback (first values)
pub dose_covariates: Vec<HashMap<String, f64>>, // Per-dose LOCF snapshot (empty if no TV cov)
pub obs_covariates: Vec<HashMap<String, f64>>, // Per-obs LOCF snapshot (empty if no TV cov)
pub cens: Vec<i8>, // 0 quantified, 1 below LLOQ, -1 above ULOQ
pub occasions: Vec<u32>,
pub dose_occasions: Vec<u32>,
}dose_covariates and obs_covariates are populated only when at least one covariate varies within the subject — the no-TV-cov fast paths use covariates directly. Helpers subject.has_tv_covariates(), subject.dose_cov(k), and subject.obs_cov(j) abstract over this.
ModelParameters
pub struct ModelParameters {
pub theta: Vec<f64>,
pub theta_names: Vec<String>,
pub theta_lower: Vec<f64>,
pub theta_upper: Vec<f64>,
pub omega: OmegaMatrix,
pub sigma: SigmaVector,
}OmegaMatrix
Between-subject variability matrix with pre-computed Cholesky factor.
pub struct OmegaMatrix {
pub matrix: DMatrix<f64>, // Full omega matrix
pub chol: DMatrix<f64>, // Lower Cholesky factor L (Omega = L*L')
pub eta_names: Vec<String>,
pub diagonal: bool, // True if omega is diagonal
}Constructors: - OmegaMatrix::from_matrix(m, names, diagonal) – From a full matrix (computes Cholesky, regularizes if needed) - OmegaMatrix::from_diagonal(variances, names) – From diagonal variances
FitOptions
pub struct FitOptions {
pub method: EstimationMethod, // Foce, FoceI, or Saem
pub outer_maxiter: usize, // Default: 500
pub outer_gtol: f64, // Default: 1e-6
pub inner_maxiter: usize, // Default: 200
pub inner_tol: f64, // Default: 1e-5
pub cov_inner_tol: Option<f64>, // Covariance-step EBE tol (None = auto)
pub run_covariance_step: bool, // Default: true
pub interaction: bool, // FOCEI flag
pub verbose: bool, // Default: true
pub optimizer: Optimizer, // Default: Bobyqa
pub lbfgs_memory: usize, // Default: 5
pub global_search: bool, // Default: false
pub global_maxeval: usize, // Default: 0 (auto)
// SAEM-specific
pub saem_n_exploration: usize, // Default: 150
pub saem_n_convergence: usize, // Default: 250
pub saem_n_mh_steps: usize, // Default: 3
pub saem_adapt_interval: usize, // Default: 50
pub saem_seed: Option<u64>, // Default: None
}Use FitOptions::default() for standard FOCEI settings.
FitResult
pub struct FitResult {
pub method: EstimationMethod,
pub converged: bool,
pub ofv: f64,
pub aic: f64,
pub bic: f64,
pub theta: Vec<f64>,
pub theta_names: Vec<String>,
pub omega: DMatrix<f64>,
pub sigma: Vec<f64>,
pub covariance_matrix: Option<DMatrix<f64>>,
pub se_theta: Option<Vec<f64>>,
pub se_omega: Option<Vec<f64>>,
pub se_sigma: Option<Vec<f64>>,
pub subjects: Vec<SubjectResult>,
pub n_obs: usize,
pub n_subjects: usize,
pub n_parameters: usize,
pub n_iterations: usize,
pub interaction: bool,
pub warnings: Vec<String>,
}SubjectResult
Per-subject diagnostics from the fit.
pub struct SubjectResult {
pub id: String,
pub eta: DVector<f64>,
pub ipred: Vec<f64>, // Individual predictions
pub pred: Vec<f64>, // Population predictions
pub iwres: Vec<f64>, // Individual weighted residuals
pub cwres: Vec<f64>, // Conditional weighted residuals
pub ofv_contribution: f64,
}Enums
pub enum EstimationMethod { Foce, FoceI, Saem }
pub enum PkModel { OneCptIv, OneCptOral,
TwoCptIv, TwoCptOral,
ThreeCptIv, ThreeCptOral }
pub enum ErrorModel { Additive, Proportional, Combined }
pub enum Optimizer { Bfgs, Lbfgs, Slsqp, NloptLbfgs, Mma }The IV variants cover both bolus and infusion administration — the route is chosen per dose from the data’s RATE column (RATE=0 ⇒ bolus, RATE>0 ⇒ infusion), so one model handles either or a mix within a single subject.
DoseEvent
pub struct DoseEvent {
pub time: f64,
pub amt: f64,
pub cmt: usize,
pub rate: f64,
pub duration: f64,
pub ss: bool,
pub ii: f64,
}