Score the deep-feature class-conditional Mahalanobis LRT discriminator
Source:R/singlesample-deepmaha-scorer.R
score_lrt_deepmaha.RdScores each row of X independently with the frozen model from
fit_lrt_deepmaha, in PURE R (no python). Each query is mapped to
the per-sample robust CLR over the frozen feature universe (absent universe
features carry the neutral rCLR value 0), embedded by the exported MLP
forward, and scored by the class-conditional Mahalanobis log-likelihood ratio
(case minus control) with the frozen tied covariance. Larger = more case-like.
Queries with fewer than model$hp$min_features universe features present (a
column-overlap floor), or empty positive support over the frozen universe on the
(pre-rCLR) aligned abundances (!any(X_use[i, ] > 0)), return the neutral
score 0. A FLAT all-equal-positive composition maps to the rCLR origin but
is a VALID specimen and is scored normally. The score of a row depends only on
that row and the frozen model and is exactly invariant to per-specimen positive
scaling.
Arguments
- model
A
lrt_deepmaha_modelobject fromfit_lrt_deepmaha.- X
Numeric matrix (samples \(\times\) features) of non-negative abundances with named feature columns.
- meta
Optional per-sample metadata. Accepted for interface uniformity and ignored by this method.
References
Lee K, Lee K, Lee H, Shin J. (2018) A Simple Unified Framework for Detecting Out-of-Distribution Samples and Adversarial Attacks. NeurIPS 31. arXiv:1807.03888.
Examples
if (FALSE) { # \dontrun{
model <- fit_lrt_deepmaha(X, y)
score_lrt_deepmaha(model, X[1, , drop = FALSE])
} # }