Skip to content

[Sad Catapella N2][Scientific correctness] Tail second moments and pooled standard deviation can overflow despite finite true spread #33

Closed

Description

@guijacquemet

Baseline and classification

Normalization Batch 2, commit f784c95e3049483f87466150ffc5764375fa631d. Confirmed numerical overflow path, with isolated NumPy squared-value probe. Full library runtime not tested.

Evidence

Minimal counterexamples

  • Two finite pixels [-1e200, +1e200] have population standard deviation 1e200 (finite), but their squared deviations overflow float64, causing PooledHistogram.std to return infinity or a nonfinite result.
  • With a robust histogram whose extreme finite 1e200 values enter the tail, _TailSums.add stores sum_of_squares=inf, so pooled tail-based variance cannot be reconstructed reliably from saved schema-v4 moments, even though true std can be finite. An isolated NumPy probe confirmed (np.array([1e200])**2) == inf.

Impact

Valid floating-point measurements or upstream transformed arrays can yield an invalid z-score/weighted z-score despite mathematically finite dispersion; for tail-derived moments the persisted representation may already have lost information. This is a representation/algorithm issue, not just an output formatter.

Fix and tests

For direct/ordinary bins, use a scaled/centered variance computation that avoids overflow and catastrophic cancellation. For robust tails, introduce a stable mergeable moment representation (e.g., centered mean/variance with scale and count, or suitable normalized moments) and a versioned data/contract migration if necessary; do not silently reinterpret existing schema-v4 inf second moments. Test ±1e200, constant 1e200, 1e200±1e185, weighted conditions, mixed blocks, 32/64-bit floats and CSV round-trip, with high-precision reference and explicit diagnostic for truly unsupported magnitudes. Preserve ordinary-range numeric parity where required. Benchmark stable implementation before any Numba use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions