# Focal-loss numerical reference

Run `python examples/focalloss.py` or append `--json`; no packages required.
Regions: `loss`, `gradient`, `population`. Source: [Focal Loss v2](https://arxiv.org/pdf/1708.02002v2),
Equations 3–5 and §3.3. The source-crop manifest pins the PDF and image hashes.

Targets are 0/1. Alpha is the positive-class weight; negatives receive 1-alpha.
Set alpha=None for the unweighted form. Gamma=0 with alpha present gives
**alpha-weighted BCE**, not unweighted BCE. The analytic logit derivative includes
the derivative of (1-p_t)^gamma. Stable softplus and expm1 avoid clipping-induced
gradient errors. Self-checks compare derivatives to central finite differences.

Population counts/probabilities are supplied teaching values, not recorded anchor
statistics. Summed absolute classification gradients are an illustrative proxy,
not parameter-gradient norms or measured optimization dynamics. The initial bias
helper maps a supplied prior (default 0.01) to a logit. There is no FPN, anchor
matcher, box regression, pretrained checkpoint, COCO evaluation or timing here.
