Function log_likelihood_matrix
pub fn log_likelihood_matrix(
equation: &impl Equation,
subjects: &Data,
support_points: &ArrayBase<OwnedRepr<f64>, Dim<[usize; 2]>>,
error_models: &AssayErrorModels,
progress: bool,
) -> Result<ArrayBase<OwnedRepr<f64>, Dim<[usize; 2]>>, PharmsolError>Expand description
Calculate the log-likelihood matrix for all subjects and support points.
This function computes log-likelihoods directly in log-space, which is numerically more stable than computing likelihoods and then taking logarithms. This is especially important when dealing with many observations or extreme parameter values that could cause the regular likelihood to underflow to zero.
support_points must already be a dense matrix in model order. If the
incoming columns are in an external named order, validate that order once
with [crate::ParameterOrder] and reorder before calling this function.
§Parameters
equation: The equation to use for simulationsubjects: The subject datasupport_points: The support points to evaluate (rows = support points, cols = parameters)error_models: The error models to use (observation-based sigma)progress: Whether to display a progress bar during computation
§Returns
A 2D array of log-likelihoods with shape (n_subjects, n_support_points)
§Example
ⓘ
use ndarray::array;
use pharmsol::{ParameterOrder, prelude::simulator::log_likelihood_matrix};
let order = ParameterOrder::with_model(&equation, ["ka", "ke"])?;
let support_points_in_source_order = array![[0.1, 0.3], [0.2, 0.4]];
let support_points = order.matrix(support_points_in_source_order)?;
let log_liks = log_likelihood_matrix(
&equation,
&data,
&support_points,
&error_models,
false
)?;