PairSimilarity

Contents

PairSimilarity#

class scarlet2.PairSimilarity(weight: float, eps: float = 1e-12)[source]#

Bases: Module

Configuration for the pair-similarity regularizer used by fit().

Penalizes the morphology-cosine x SED-cosine similarity summed over source pairs. Targets the parasitic-flux failure mode: when source A absorbs flux in the shape of a neighbour B, the morphology cosine rises, and the penalty pushes that B-shaped component back down. The SED-cosine factor scales the penalty by the degree of spectral degeneracy between the pair.

Parameters:
  • weight (float) – Relative coefficient of the regularizer: the target ratio of the penalty to the initial NLL. fit() evaluates the NLL and the unweighted penalty once at initialization and rescales internally so that R = weight * |NLL_init| at the start of optimization. 0.0 is a no-op (bit-identical to the unregularized loss). Empirically a value around 0.01 (penalty ~1% of the NLL) works well.

  • eps (float, optional) – Small constant added to cosine denominators for numerical stability.

Notes

Implemented as an eqx.Module with all-static fields so it threads through eqx.filter_jit without being treated as a differentiable leaf and without forcing recompilation across identical configs.