rxnfit.fit_metrics module
Goodness-of-fit metrics shared by solvers and fitters.
Computes RSS, TSS, R², RMSE, and MAE. Residuals and totals omit NaN pairs so
RSS, SAE, and n_datapoints always refer to the same valid (time, species)
samples.
- rxnfit.fit_metrics.expdata_df_to_datasets(expdata_df, function_names)
Convert a single experimental DataFrame to datasets format.
- Parameters:
expdata_df (pandas.DataFrame) – Time in first column, species concentrations in remaining columns. Column names must include all function_names.
function_names (list[str]) – Chemical species names (e.g. ODE order).
- Returns:
- One-element list of dicts with keys ‘t_list’, ‘C_exp_list’
(aligned to function_names order; valid points only, NaN removed).
- Return type:
list
- Raises:
ValueError – If a species in function_names is not in the DataFrame.
- rxnfit.fit_metrics.fit_metrics(datasets, rss, sae, n_datapoints)
Compute fit metrics from datasets and residual sums.
TSS uses per-species means over the same valid points as RSS/SAE. Callers should pass keyword arguments for
saeandn_datapoints:fit_metrics(datasets, rss, sae=sae, n_datapoints=n)
- Parameters:
datasets (list[dict]) – List of dicts with ‘t_list’, ‘C_exp_list’ (each list of arrays in species order; valid points only).
rss (float) – Residual sum of squares (already computed).
sae (float) – Sum of absolute residuals (already computed).
n_datapoints (int) – Number of valid residual points (same set as RSS/SAE).
- Returns:
- Keys ‘rss’, ‘tss’, ‘r2’, ‘rmse’, ‘mae’, ‘n_datapoints’.
If TSS <= 0, ‘r2’ is NaN. If
n_datapoints<= 0, ‘rmse’ and ‘mae’ are NaN. Callers should warn when tss < TSS_MIN_THRESHOLD.
- Return type:
dict