Skip to content

Add reliability diagnostics to GVar#8

Merged
timholy merged 2 commits into
mainfrom
reliability-diagnostics
Jul 14, 2026
Merged

Add reliability diagnostics to GVar#8
timholy merged 2 commits into
mainfrom
reliability-diagnostics

Conversation

@timholy

@timholy timholy commented Jul 14, 2026

Copy link
Copy Markdown
Member

A GVar's moments are exact only when each operation is at most quadratic over the spread of its input and the input really is Gaussian. Neither holds in general. GVar now carries two fields that accumulate through arithmetic and say how far the result has drifted from a Gaussian:

κ3 the third cumulant, exposed standardized as skewness err an estimate of the absolute error in center, exposed as
moment_error, tracking the leading Taylor term each operation
neglects

distrust combines them into one dimensionless number: the displacement of the quantiles in units of rad. It is zero for an exact Gaussian and grows without bound as the description degrades. The two components are complementary. exp of a Gaussian is exactly lognormal, so its moment_error is zero while its skewness is large; a quadratic has neither.

Two fixes fall out of the same derivation:

Var[f(x)] = f'^2 σ^2 + f''^2 σ^4/2 + f' f''' σ^4 + O(σ^6). The third term was omitted although it is the same order as the second, and it is positive for inv, log, sqrt and x^p, so σ was systematically understated: log(3 ± 0.5) was low by 3.1%, now 0.5%.

ThickNumbers builds the result of hull, intersect, typemin and typemax with the two-argument call TN(lo, hi), but GVar(center, σ) is a different parametrization; those four now have GVar methods. The generic versions produced a hull spanning [-2.5, 6.5] for operands spanning [2, 4] and [2.5, 4.5], and an intersection wider than either operand.

Integer powers use exact Gaussian raw moments, which terminate for a polynomial, rather than an asymptotic correction to the variance. Mean, variance and third cumulant are then all exact, and SpecialFunctions is no longer needed. Exponents above 20 overflow the moment sum and throw.

Assisted-by: Claude Opus 4.8 noreply@anthropic.com

timholy added 2 commits July 14, 2026 16:32
A GVar's moments are exact only when each operation is at most quadratic
over the spread of its input and the input really is Gaussian. Neither
holds in general. GVar now carries two fields that accumulate through
arithmetic and say how far the result has drifted from a Gaussian:

  κ3   the third cumulant, exposed standardized as `skewness`
  err  an estimate of the absolute error in `center`, exposed as
       `moment_error`, tracking the leading Taylor term each operation
       neglects

`distrust` combines them into one dimensionless number: the displacement
of the quantiles in units of `rad`. It is zero for an exact Gaussian and
grows without bound as the description degrades. The two components are
complementary. `exp` of a Gaussian is exactly lognormal, so its
`moment_error` is zero while its skewness is large; a quadratic has
neither.

Two fixes fall out of the same derivation:

Var[f(x)] = f'^2 σ^2 + f''^2 σ^4/2 + f' f''' σ^4 + O(σ^6). The third term
was omitted although it is the same order as the second, and it is
positive for `inv`, `log`, `sqrt` and `x^p`, so σ was systematically
understated: `log(3 ± 0.5)` was low by 3.1%, now 0.5%.

ThickNumbers builds the result of `hull`, `intersect`, `typemin` and
`typemax` with the two-argument call `TN(lo, hi)`, but `GVar(center, σ)`
is a different parametrization; those four now have GVar methods. The
generic versions produced a hull spanning [-2.5, 6.5] for operands
spanning [2, 4] and [2.5, 4.5], and an intersection wider than either
operand.

Integer powers use exact Gaussian raw moments, which terminate for a
polynomial, rather than an asymptotic correction to the variance. Mean,
variance and third cumulant are then all exact, and SpecialFunctions is
no longer needed. Exponents above 20 overflow the moment sum and throw.

Assisted-by: Claude Opus 4.8 <noreply@anthropic.com>
ThickNumbers 1.1.2 builds generic results with `lohi` and `midrad` rather
than with a two-argument `TN(lo, hi)` call, so `GVar`'s midpoint/σ
parametrization no longer needs its own `typemin` and `typemax`.

`hull` and `intersect` stay, for a different reason: a result built from
the span alone carries the diagnostics of a fresh box, so the generic
versions would report `distrust` of zero for the hull of two values that
are not to be trusted at all.

Assisted-by: Claude Opus 4.8 <noreply@anthropic.com>
@timholy timholy force-pushed the reliability-diagnostics branch from 0cab54d to ce246b6 Compare July 14, 2026 21:34
@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.22936% with 27 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.66%. Comparing base (eb09203) to head (ce246b6).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/GaussianRandomVariables.jl 75.22% 27 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main       #8       +/-   ##
===========================================
+ Coverage   38.70%   66.66%   +27.95%     
===========================================
  Files           1        1               
  Lines         124      168       +44     
===========================================
+ Hits           48      112       +64     
+ Misses         76       56       -20     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@timholy timholy merged commit dff1575 into main Jul 14, 2026
4 checks passed
@timholy timholy deleted the reliability-diagnostics branch July 14, 2026 21:38
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