Loss Functions in v0.6.1¶
ZeroProofML v0.6.1 combines multiple losses to stabilise training near singularities and to distinguish projective orientations.
Implicit Loss¶
Cross-product form that avoids direct division:
[ E = (P \cdot Y_d - Q \cdot Y_n)^2, \quad L = \operatorname{mean}\left( \frac{E}{Q^2 Y_d^2 + P^2 Y_n^2 + \gamma} \right) ]
Handles poles by keeping gradients defined even when Q → 0.
The default detach_scale=False keeps the scale factor attached in the
backward pass, preserving the ideal homogeneous loss's near-zero radial
gradient away from the γ floor. Pass detach_scale=True to recover the
legacy detached-scale heuristic, which treats the denominator as constant and
therefore creates an inward radial shrink force for nonzero residuals.
Margin Loss¶
The canonical 0.7 path encourages the normalized denominator score to stay
away from zero during training:
[ L_{\text{margin}} = \operatorname{mean}(\max(0, \tau_{train} - |\hat Q|)^2) ]
SCMTrainingLoss passes both (P,Q) through the authoritative gauge. Direct
margin_loss(Q, ...) remains the v0.6 raw-coordinate compatibility form;
canonical callers pass numerator=P and, for a tuple, coordinate_axis.
Optionally masked to finite paths. margin_loss(..., reduction="population")
keeps the default population risk by averaging the masked penalties over the
whole batch. reduction="conditional" averages over finite targets only and
returns zero when the finite-target mask is empty.
With a finite-target event (F), population reduction controls: [ \Pr(F\cap B) \leq \frac{L_{\text{margin,pop}}}{(\tau_{\text{train}}-\tau_{\text{infer}})^2} ]
Conditional finite-label reporting instead uses the finite-label probability: [ \Pr(B\mid F) \leq \frac{L_{\text{margin,pop}}} {\Pr(F)(\tau_{\text{train}}-\tau_{\text{infer}})^2}. ]
Sign Consistency Loss (Singular Orientation)¶
Projective cosine similarity to align (P, Q) with target orientation tuples
(Y_n, Y_d) on singular/censored labels or another explicitly signed task
domain. It is not a generic finite-regression loss; finite projective targets
that are equivalent up to a global sign should normally be handled by
implicit_loss rather than an orientation penalty.
When mask_singular is omitted, sign_consistency_loss and SCMTrainingLoss
apply the sign term only to targets with abs(Y_d) <= epsilon_sing. Pass
mask_singular explicitly to supervise finite orientations or another signed
task domain.
Since v0.6.1, masked-out sign and margin samples are replaced with finite
placeholders before reduction, so masked NaN payloads cannot contaminate the
loss or gradients for selected samples. Loss scalar parameters are validated:
gamma, tau_train, epsilon_sing, and loss weights must be finite and
non-negative; coverage targets must be in [0, 1]; separation thresholds must
be finite, non-negative, and ordered as tau_bot <= tau_finite.
Coverage & Rejection¶
- Coverage metric: fraction of outputs that are finite (non-⊥).
- Hard rejection penalty:
rejection_loss(is_bottom, ...)penalises measured coverage below a target threshold from an already-thresholded mask. This hard-mask path is detached and should be treated as metric-style accounting, not as a differentiable gate-training signal. - Soft coverage surrogate:
soft_coverage_loss(P, Q, tau, temperature, target)first applies the authoritative canonical projective gauge and approximates finite-output probability from its denominator score. Scale-equivalent(P, Q)tuples therefore receive the same coverage loss, while representation and numerical faults receive zero finite probability: [ p_{\text{finite}}(P,Q)=\sigma\left(\frac{|\widehat Q|-\tau}{T}\right). ] The defaultmode="under"penalises under-coverage as [ \max(0,c_{\text{target}}-\mathbb E[p_{\text{finite}}])^2. ] Representation and numerical faults are sanitized before differentiable norm arithmetic, so their zero finite probability also has a finite zero gradient.
Combined Training Objective¶
SCMTrainingLoss mixes the components:
[ L = L_{fit} + \lambda_{margin} L_{margin} + \lambda_{sign} L_{sign} + \lambda_{rej} L_{rej} ]
Default hyperparameters: γ=1e-9, τ_{train}=1e-4, ε_{sing}=1e-3, λ_{margin}=0.1, λ_{sign}=1.0.