Metrics¶
Held-out scores for model selection. Robusta.score() returns a ZMoments; read .kl for
the paper's cross-validation score. The functions below compute the same quantities
directly from arrays.
ZMoments¶
robusta_hmf.ZMoments
dataclass
¶
Sufficient statistics for the moment-based held-out scores.
Attributes:
| Name | Type | Description |
|---|---|---|
n |
int
|
Number of residuals summed over, |
sum_z, sum_z2 |
float
|
|
sum_chi2 |
float
|
|
n_excluded_rows, n_excluded_cols |
int
|
Rows and columns the scored state excludes (see
|
n_excluded_entries |
int
|
Entries with non-zero weight that fall in an excluded row or column. |
mean_z
property
¶
Mean of the robustly-weighted residuals. Target: 0.
var_z
property
¶
Variance of the robustly-weighted residuals. Target: 1.
std_z
property
¶
Standard deviation of the robustly-weighted residuals. Target: 1.
chi2_red
property
¶
Reduced chi-squared, mean(W * r**2). Target: 1.
rmse
property
¶
Weighted RMSE, sqrt(chi2_red). Lower is better.
kl
property
¶
KL divergence of the z distribution from N(0, 1). Target: 0.
The paper's model-selection score (Eq. 20). See
kl_from_moments(). Lower is better.
as_dict()
¶
The scores as a plain dict, for tabulating over a (K, Q) grid.
Functions¶
robusta_hmf.kl_from_moments(mean_z, std_z)
¶
KL divergence from N(mean_z, std_z^2) to N(0, 1). Target: 0.
The paper's model-selection score (Eq. 20), under a Gaussian approximation to the empirical distribution of the standardised residuals:
.. math:: \mathrm{KL} = -\log\sigma_z + (\sigma_z^2 + \mu_z^2) / 2 - 1/2
which is zero only for :math:\mu_z = 0, \sigma_z = 1 and positive
otherwise. Lower is better.
robusta_hmf.z_scores(Y, W, A, G, likelihood)
¶
Robustly-weighted standardised residuals.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Y
|
(Array, shape(N, M))
|
Data matrix. |
required |
W
|
(Array, shape(N, M))
|
Data weights (inverse variance). |
required |
A
|
(Array, shape(N, K))
|
Coefficients. |
required |
G
|
(Array, shape(M, K))
|
Basis vectors. |
required |
likelihood
|
Likelihood
|
Supplies the IRLS downweighting. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
z |
(Array, shape(N, M))
|
|
robusta_hmf.z_moments(Y, W, A, G, likelihood)
¶
Held-out moments for (A, G) on (Y, W), forming the full residual.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
Y
|
(Array, shape(N, M))
|
Data and weights. |
required |
W
|
(Array, shape(N, M))
|
Data and weights. |
required |
A
|
(Array, shape(N, K))
|
Coefficients, e.g. from |
required |
G
|
(Array, shape(M, K))
|
Basis vectors. |
required |
likelihood
|
Likelihood
|
Supplies the IRLS downweighting. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
moments |
ZMoments
|
|
See Also
robusta_hmf.sharded.ShardedFrame.z_moments : chunked, out-of-core route.