Skip to content

Diagnostics, warnings and errors

model.fit_info records how the last fit() ran. Warnings all derive from RobustaWarning, so warnings.simplefilter("error", RobustaWarning) turns every one of them into an error.

FitInfo

robusta_hmf.FitInfo dataclass

How a call to Robusta.fit() ran.

Attributes:

Name Type Description
converged bool

Whether the convergence test passed.

stop_reason {converged, max_iter}

Why the loop ended.

n_iter int

Number of iterations run.

final_loss float

Loss at the last iteration (NaN if no iteration ran).

loss_rises tuple of int

Iterations at which the loss rose by more than the optimiser allows.

exclusions tuple of ExclusionEvent

Every exclusion, in the order it happened.

ExclusionEvent

robusta_hmf.ExclusionEvent dataclass

Rows or columns removed from a fit because the data could not determine them.

Exclusion happens before the first iteration, from the weights.

Attributes:

Name Type Description
axis {row, col}

Whether indices are rows (of Y and A) or columns (of Y, rows of G).

indices tuple of int

The excluded indices, sorted.

cause {empty, low_coverage, cascade}

"empty": no non-zero weights. "low_coverage": fewer non-zero weights than the rank. "cascade": fell below the rank after other rows or columns were excluded.

Warnings

robusta_hmf.RobustaWarning

Bases: UserWarning

Base class for warnings issued by robusta-hmf.

Filter on it to act on all of them at once, e.g. warnings.simplefilter("error", RobustaWarning) turns every robusta-hmf warning into an exception.

robusta_hmf.DataWarning

Bases: RobustaWarning

The input data were modified before use.

Issued by fit(), infer() and score() (or prepare() on a frame) when entries of Y or W are NaN or infinite: those entries are treated as missing (Y = W = 0), and the message says how many there were. Pass nan_error=True to raise ValueError instead.

robusta_hmf.UnderdeterminedWarning

Bases: RobustaWarning

Some rows or columns have fewer usable weights than the rank.

Their factors are not determined by the data: a row of A (or of G) has rank unknowns and needs at least that many non-zero weights. Without als_ridge these rows and columns are excluded from the fit and returned as NaN (see FitInfo.exclusions); with als_ridge they are kept, determined only by the ridge, and the warning names them.

robusta_hmf.ConvergenceWarning

Bases: RobustaWarning

The fit did not converge, or its loss rose when it should not.

Issued when a fit or inference reaches max_iter before the convergence test passes, and (for ALS without a ridge) when the loss rises by more than floating-point round-off allows, which in exact arithmetic it never does. A rise usually means a badly conditioned least-squares solve: try float64, a smaller rank, or check W.

Errors

robusta_hmf.PrecisionError

Bases: RuntimeError

A fit asked for float64 but JAX's float64 support is disabled.

JAX computes in float32 unless jax.config.update("jax_enable_x64", True) is called before any JAX array is created. Rather than silently running a float64 model in float32, fit(), infer() and score() raise this. Enable x64, or pass dtype="float32" to Robusta to choose float32 explicitly.