Skip to content

test: property-based correctness sweep over every Prior subclass - #1499

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/prior-property-tests
Aug 18, 2026
Merged

test: property-based correctness sweep over every Prior subclass#1499
Jammy2211 merged 1 commit into
mainfrom
feature/prior-property-tests

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Closes #1497. Phase 3 of the priors/messages census (hub #1331): the general property sweep that locks the nine shipped fixes in as class-wide invariants rather than pointwise regressions.

What this adds

test_autofit/mapper/prior/test_prior_properties.py — 134 parametrised tests, five properties over every concrete Prior family (Uniform, LogUniform, Gaussian, LogGaussian, TruncatedGaussian; two parameterisations each):

autofit/messages/transform.py — the LinearShiftTransform class docstring (the remaining half of the census's C6/bug/priors/11; the composition-order half shipped in #1334): shift/scale are physical-space parameters and the stored parent Jacobian is deliberately 1/scale because transform() runs physical → base.

New finding, filed separately

While implementing P2: TransformedMessage.logpdf/pdf omit the transform Jacobian — the generic path returns the base-space density at physical coordinates (UniformPrior(0,1).message.pdf integrates to 0.282 = 1/(2√π), not 1.0), while factor() is correct. Filed as #1498 with full reproduction; the tests here assert the physical density via factor() for transformed messages and cite #1498 at the site, so they can be tightened once it is adjudicated.

Validation

  • New module: 134/134 pass.
  • test_autofit/mapper/prior/ + test_autofit/messages/ + test_autofit/graphical/functionality/test_messages.py: 477 passed; the 5 failures present are identical on clean main in this environment (jax API drift in test_jax_trace.py/test_beta, unrelated — the new module is NumPy-only per the house rule).
  • All five properties were numerically validated against main before being committed as assertions.

🤖 Generated with Claude Code

https://claude.ai/code/session_016KANrjyrdj7pLXC7sKbhJo


Generated by Claude Code

Adds test_autofit/mapper/prior/test_prior_properties.py — 134 parametrised
tests locking five properties over every concrete Prior family:

- P1 value_for is the inverse CDF (cdf round-trip to 1e-6)
- P2 the normalised prior density integrates to 1, three ways: the
  log_prior_from_value + log_normalisation() contract (#1331 Option A),
  the message physical-density path, and the generic exponential-family
  pdf for direct messages — now including TruncatedNormalMessage, the
  exclusion that let the #1331-04 log-partition bug survive
- P3 log_prior gradient matches the density gradient by central finite
  differences (the #1266 sign-convention canary)
- P4 with_limits constructs for every family with documented semantics
  (hard limits hit exactly; Gaussian families centre between limits)
- P5 from_mode(m, V) reproduces mean and variance at V != 1
  discriminating points for Normal and Gamma (#1331-D3 invariant)

TransformedMessage physical densities are asserted via factor() because
the generic logpdf path omits the transform Jacobian — filed as #1498.

Also adds the LinearShiftTransform class docstring (bug/priors/11 s2):
shift/scale are physical-space parameters; the stored parent Jacobian is
deliberately 1/scale because transform() runs physical -> base.
@Jammy2211
Jammy2211 merged commit 21288bb into main Aug 18, 2026
3 checks passed
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.

test: property-based correctness sweep over every Prior subclass

2 participants