Skip to content

Metrics and Diagnostics

TFOpt uses an optimization loss, post-fit metrics, feasibility and KKT diagnostics, and a curve-similarity measure to evaluate TF-regulation fits.


Optimization losses (loss_type)

With residuals $r_{jt} = R_{jt} - \hat R_{jt}$ (observed minus transformed prediction) over the $N$ entries of all targets $j$ and RNA time points $t$, and β the vector of all β (tfopt/local/objfn/minfn.py; the mean and the constants are those of the original implementation):

loss_type Objective
0 (MSE) $\frac{1}{N} \sum_{j,t} r_{jt}^2$
1 (MAE) $\frac{1}{N} \sum_{j,t} \lvert r_{jt}\rvert$
2 (soft L1) $\frac{1}{N} \sum_{j,t} 2\big(\sqrt{1 + r_{jt}^2} - 1\big)$
3 (Cauchy) $\frac{1}{N} \sum_{j,t} \log\big(1 + r_{jt}^2\big)$
4 (arctan) $\frac{1}{N} \sum_{j,t} \arctan\big(r_{jt}^2\big)$
5 (elastic net, default) $\frac{1}{N} \sum_{j,t} r_{jt}^2 + 10^{-6}\lVert\beta\rVert_1 + 10^{-6}\lVert\beta\rVert_2^2$
6 (Tikhonov) $\frac{1}{N} \sum_{j,t} r_{jt}^2 + 10^{-6}\lVert\beta\rVert_2^2$

Losses 1 and 5 are nonsmooth (see Configuration). Any other loss_type is rejected.


Fit metrics

The Optimization Results sheet of tfopt_results.xlsx and diagnostics.json report the solver status, iterations, the objective, and SSE, MSE, RMSE, MAE, MAPE and R² of the prediction against the observed series (tfopt.fitanalysis.metrics.fit_metrics, unweighted, over all targets and time points). SSE is the unnormalized sum of squared residuals, MSE its mean and RMSE the square root of the MSE. MAPE excludes observed values with absolute value ≤ 1e-8 and is NaN if none remain. The objective is never labelled SSE: diagnostics.json keeps the data loss, the regularization, the constraint penalty (zero for the exact-constraint methods) and the total objective as separate fields.


Fit Analysis

tfopt.fitanalysis draws post-fit figures from the results workbook after a run (see Plotting).


Feasibility and stationarity

tfopt.optimality.KKT.diagnostics measures the largest violation of the sum-to-one groups and the bounds, and the infinity norm of the projected gradient $x - P(x - \nabla f(x))$ on the actual bounded affine groups. It is a first-order stationarity measure, not a proof of global optimality and not a second-order certificate.


KKT diagnostics

tfopt.optimality.kkt_diagnostics (the same names, report and tolerances as KinOpt 0.11) checks a fit against the KKT conditions of $\min f(x)$ subject to $Ax = b$ (Σα = 1 per target over its real edges, Σβ = 1 per TF) and $l \le x \le u$. The multipliers λ (equalities) and $\mu_l, \mu_u \ge 0$ (active bounds) are estimated by least squares on the stationarity equation $\nabla f + A^\top\lambda - \mu_l + \mu_u = 0$. TFOpt's equality groups are disjoint, so this splits into one exact one-dimensional problem per group. The report gives four residuals, each with a tolerance and a pass/fail verdict:

Condition Tolerance
stationarity, relative to max(1, ‖∇f‖∞) 1e-5
primal feasibility 1e-10
dual feasibility 1e-10
complementary slackness 1e-8

They are written for every start (kkt_* columns of multistart_summary.csv), for the selected fit (diagnostics.json), and in the workbook (sheets "KKT Diagnostics" and "KKT Multipliers"). A start is accepted only if its KKT verdict passes. If no start is accepted, a warning says so and the start is selected by the earlier rule (feasible first, then successful, then the lowest objective). Do not report a fit as converged or feasible without these measurements.

Prediction Check

An mRNA level cannot be negative. Every run computes, for each target, the summed prediction $\sum_k \alpha_{ik}\,\mathrm{activity}_k(t)$ before the prediction transform and flags the targets where it is negative at any RNA time point: the workbook sheet "Prediction Check" (mRNA, min_prediction, negative_points, negative), the Optimization Results row "Targets with a negative prediction", run_config.json (negative_predictions: targets and time points), diagnostics.json (negative_prediction_targets), the bundle table prediction_check and a warning in the log. With the default transform clip, Estimated shows those points as 0; a flagged target should be inspected. (KinOpt 0.11.0 has the same check, per phosphosite.)


Curve Similarity

tfopt similarity <results_dir> (library: tfopt.analysis.curve_similarity) writes the discrete Fréchet distance between the observed and estimated series of every target, aligned by mRNA identifier, with ranks and a summary. It is an iterative discrete Euclidean implementation on (time, value) paths. By default time is normalized to the unit interval, which keeps irregular sampling while reducing the weight of minute units; --raw-time uses minutes. Incomplete rows are flagged with no distance or rank; missing data is never imputed. The score depends on amplitude and time scale and does not replace the objective or the fit metrics. The run bundle carries the same numbers in the table curve_similarity.