You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Sad Catapella N2][Scientific correctness] Tail second moments and pooled standard deviation can overflow despite finite true spread #33
WeightedHistogram.std, lines 281–288 shares these paths. z_score uses the returned standard deviation; its parameter constructor refuses nonfinite scale, despite a finite true standard deviation.
Tail moment test uses int32 values (~2^31), not large finite float64 magnitudes.
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.
Activity