splisosm.logger#

Training logger utilities for GLM/GLMM optimization.

Classes#

PatienceLogger

Logger for tracking training patience and convergence.

Module Contents#

class splisosm.logger.PatienceLogger(batch_size, patience, min_delta=1e-05, tol_relative=False, diagnose=False, store_param_history=False)#

Logger for tracking training patience and convergence.

For training MultinomGLM and MultinomGLMM.

Loss history is always recorded (one scalar per gene per epoch). Per-epoch parameter snapshots are only stored when store_param_history=True.

Parameters:
  • batch_size (int) – Number of samples in the batch.

  • patience (int) – Number of epochs to wait after the last significant improvement.

  • min_delta (float) – Minimum change in the loss to qualify as an improvement. Interpreted as an absolute change when tol_relative=False (default) or as a fraction of the current best loss when tol_relative=True.

  • tol_relative (bool) – If True, min_delta is treated as a relative threshold: an epoch counts as a “big improvement” only when (best - current) / max(|best|, 1) >= min_delta. Relative mode is more robust when the loss scale varies widely across genes or datasets. Default False preserves the original absolute behaviour.

  • diagnose (bool) – Deprecated alias for store_param_history. Will be removed in a future version.

  • store_param_history (bool) – Whether to store per-epoch parameter snapshots during training. This can consume significant memory (O(epochs × n_genes × params)). Loss history is always stored regardless of this flag.

get_params_iter()#

Return stored parameter history if store_param_history=True.

Returns:

Dictionary {"loss": list[Tensor], "params": list[dict]} where each entry corresponds to one epoch, if store_param_history=True; otherwise None.

Return type:

dict or None

log(loss, params)#

Log loss for a given epoch and update best parameters if improved.

Parameters:
  • loss (Tensor) – Loss for the current epoch, shape (batch_size,).

  • params (dict[str, Tensor]) – Current model parameters, keyed by parameter name.

Return type:

None

batch_size#
best_epoch#
best_loss#
best_params = None#
convergence#
epoch = 0#
epochs_without_improvement#
property loss_history: Tensor#

Loss history as a 2-D tensor of shape (n_epochs, batch_size).

Each row is the per-gene negative log-likelihood at that epoch. Always available after at least one call to log().

Return type:

Tensor

min_delta = 1e-05#
patience#
store_param_history = False#
tol_relative = False#