Skip to content

Fix centered standardized moments for odd orders - #179

Merged
jmh530 merged 1 commit into
libmir:masterfrom
jmh530:codex/fix-centered-odd-moments
Oct 18, 2026
Merged

jmh530 merged 1 commit into
libmir:masterfrom
jmh530:codex/fix-centered-odd-moments

Conversation

@jmh530

@jmh530 jmh530 commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

The centered standardized-moment algorithm uses integer division in N / 2, omitting one factor of the population standard deviation for odd orders. For [0, 0, 1], the third standardized moment consequently returns 1/3 instead of 1/sqrt(2).

This change divides by the missing standard-deviation factor in both the range and variadic overloads. Even-order calculations, the first- and second-order special cases, and the default scaled algorithm remain unchanged. It also corrects the centered formula documentation and documents the algorithm parameters.

Regression tests cover third, fourth, and fifth moments using independently derived expectations, float and double inputs, both overloads, and positive rescaling.

Validation:

  • Full DMD test suite: 67 modules passed.
  • Focused LDC 1.43 checks: small and large scales, negative skew, and zero variance passed.
  • DMD documentation check passed.
  • Final branch review and whitespace check passed.

The centered algorithm retains its existing susceptibility to overflow and underflow when computing unscaled central moments and variance powers. This change fixes normalization without redesigning numerical stability.

AI-Assisted-By: Codex (GPT-6 Astra Medium)

The centered algorithm used integer division in N / 2, omitting one
factor of the population standard deviation for odd orders. For
[0, 0, 1], this returned a third standardized moment of 1/3 instead
of 1/sqrt(2).

Divide by the missing standard-deviation factor in both overloads
while preserving even-order calculations. Correct the centered
formula documentation and describe the algorithm parameters.

Cover third, fourth, and fifth moments with independent expected
values across float and double inputs, range and variadic calls,
and positive rescaling.

AI-Assisted-By: Codex (GPT-6 Astra Medium)
@codecov

codecov Bot commented Oct 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@jmh530
jmh530 merged commit f7d455f into libmir:master Oct 18, 2026
26 checks passed
@jmh530
jmh530 deleted the codex/fix-centered-odd-moments branch October 18, 2026 23:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant