mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-08 12:32:43 +00:00
Reformulate composeRegression from the determinant form (n*Sxx - Sx^2) to the mean-centered corrected-sum identities (Sxx = Sxx - Sx^2/n, ...). Algebraically identical to the prior form and to Postgres REGR_* / STDDEV_POP, but it subtracts the x mean at matched scale and avoids the catastrophic cancellation the determinant form suffers on the ~1e10 epoch-day x-axis. Also read the exact stored sum_value accumulator for the Sy term instead of reconstructing it as mean*count, dropping the AVG-to-multiply float residual; fall back to mean*count when the column is null. Composition-only: no migration, no schema change. The WEIGHT live-parity case stays bit-identical at the 1e-9 relative bound. The near-flat DST parity seed improves by ~30x but still exceeds 1e-9, so it remains quarantined with an updated note pointing at a window-local x-rescale as the real fix.