Repository navigation
Description
Found while implementing the #1497 property sweep (priors/messages census follow-up; hubs #1330/#1331). Same failure shape as #1331-04: a generic-interface density path is silently wrong while the direct paths are right.
The finding
TransformedMessage inherits MessageInterface.logpdf (natural-parameter path). Its overrides forward natural_parameters, calc_log_base_measure and to_canonical_form to the base message — to_canonical_form is @transform-decorated, so the physical input is mapped to base coordinates — but no log_det change-of-variables term is ever added. The result: logpdf(x) at a physical x returns the base-space density at the mapped point, not the physical density. Meanwhile TransformedMessage.factor(x) does it correctly (base.logpdf(transform(x)) + log_det).
Reproduction on main @ 7d4d931 (numbers exact):
import numpy as np
from scipy.integrate import quad
import autofit as af
m = af.UniformPrior(0.0, 1.0).message # TransformedMessage(UniformNormalMessage, LinearShift)
m.logpdf(np.asarray(0.7)) # -1.05644 — physical density is 1.0, expect 0.0
m.factor(np.asarray(0.7)) # 0.0 — correct
quad(lambda x: float(m.pdf(np.asarray(x))), 0.0, 1.0) # 0.282095 = 1/(2*sqrt(pi)), not 1.0
quad(lambda x: float(np.exp(m.factor(np.asarray(x)))), 0.0, 1.0) # 1.000000For LogUniformPrior(0.01, 100) the generic-path pdf integrates to 15.83. Every TransformedMessage-wrapped prior (Uniform, LogUniform, LogGaussian) is affected; plain NormalMessage / TruncatedNormalMessage priors are not.
Doc contradiction
The composed_transform.py module docstring (added in #1334) states: "Evaluating logpdf(x) at a physical x runs the same three steps in reverse (physical → base) via _transform, accumulating the log-Jacobian log_det of each transform for the change of variables." The code does not accumulate it. Either the docstring describes the intended contract (then logpdf needs the log_det term) or logpdf is deliberately base-space for EP message arithmetic (then the docstring and pdf() are wrong/misleading).
What needs adjudication before a fix
- Which callers consume
TransformedMessage.logpdf/pdfvsfactor? The EP factor-graph path usesfactor/exp_factor(correct). If any EP projection /log_normpath evaluateslogpdfon transformed messages at physical coordinates, it inherits this error. logpdf_gradientreturns the baselog_likelihoodwith a Jacobian-corrected gradient — a third convention (gradient physical, value base-space) worth settling in the same pass.- Note
value_for,cdf,log_prior_from_valueandfactorare all verified correct — user-facing sampling and MCMC/MLE log-priors are unaffected. The exposure is anything treatingtransformed_message.pdf()as a physical density.
The #1497 property tests assert the physical-density path via factor for transformed messages and cite this issue at the site; when this is resolved they can be tightened to assert logpdf directly.
Sequencing suggestion: adjudicate alongside the parked single-source-density design (census C1/C4, prompts 12/13) — this is a fourth density-convention divergence of exactly the kind that design exists to eliminate.
Activity
Jammy2211 commentedon Aug 19, 2026
Caller analysis (adjudication point 1) — 2026-08-19, main @
21288bbFull inventory of
logpdf/pdf/logpdf_gradient/factorcall sites across the productionautofit/tree, numerically verified (UniformPrior(0,2):logpdf(1.3) = −0.993174vsfactor(1.3) = −0.693147 = log 0.5;∫exp(logpdf)over the support= 0.564190 = 2/(2√π),∫exp(factor) = 1.000000).Callers expecting a physical density (exposed to the bug)
Prior.logpdf— the public prior API.UniformPrior.logpdf(uniform.py:124) callsmessage.logpdfexplicitly, and its boundary-epsilon nudge operates in physical coordinates, so the method unambiguously intends physical semantics; every other prior reachesmessage.logpdfviaPrior.__getattr__. Uniform / LogUniform / LogGaussian users are silently handed base-space values.MessageInterface.pdf(interface.py:45) — zero production callers; public-API surface only.logpdf— sampling and MCMC/MLE go throughvalue_for/log_prior_from_value/factor, all verified correct. Exposure is API-level, not search-level.EP-internal callers — all base-space, and mutually consistent
MeanField.logpdf/logpdf_gradient(mean_field.py:294,300), reached fromFactorApproximation.__call__/func_gradient(mean_field.py:631-633,647) by the Laplace optimiser;MeanFieldis itself aFactorwrapping_logpdf, soprojection(mode)in thefrom_mode_covariancelog_normcalibration (mean_field.py:404) andAbstractMessage.__call__/factor_jacobian(abstract.py:392,398) route the same way.This loop is coherent, not buggy: a likelihood factor is a density over data (measure-free in x), so
fval(x) + Σ log q_base(T(x))is exactly the base-space tilted log density atz = T(x). The Laplace mode it finds is the base-space tilted mode, andfrom_mode(transform_jac+jac.quad) projects mode and covariance into base space consistently. The missinglog_detis the EP loop's working convention — and base-space Laplace is arguably the better-conditioned choice (unbounded support).The one genuine cross-convention seam —
PriorFactorPriorFactor(declarative/factor/prior.py:23,62) wrapsprior.factor— the physical density — as both its factor callable and itslog_likelihood_function. Its tilted objective under the numerical optimiser is therefore— one x-dependent
log_det(x)more than the coherent base-space tilted density (and one short of the coherent physical one). Because the #1337 seam strips the exact-update hooks (see thegraphical/README.mdroster row), declarative PriorFactors really do take this numerical path: prior-factor EP updates optimise a hybrid objective whose mode is neither the base-space nor the physical tilted mode.Correction to adjudication point 2
logpdf_gradientis not a third convention. Its analytic gradient equals the central-difference derivative oflogpdfexactly (−0.520142 both, at the probe point) — the jacobian multiplication is just the chain rule for the base-space compositionbase.logpdf(T(x)). So (logpdf,logpdf_gradient,numerical_logpdf_gradient_hessian) form one self-consistent base-space family andfactoris the physical one: two conventions, not three.New finding
Running the reproducer surfaced #1501:
TransformedMessage.factor_gradientunpacks four values from_transform_det_jac, which returns three — crashes on first call, zero production callers.Proposed resolution (adjudication point 3 — for ratification, nothing actioned)
A two-sided contract repair rather than a one-line
logpdfpatch:logpdfthe message contract (fixing thecomposed_transform.pymodule-docstring claim thatlogpdfaccumulates the Jacobian) and makePriorFactorconsume the base-space density (message.logpdf) instead ofprior.factor, making the EP loop fully base-space coherent. This changes prior-factor updates (removes the spuriouslog_det) but preserves the deliberate-looking base-space Laplace everywhere else. Belongs with the design: unify the Prior/Message hierarchy around a single-source density #1500 design (Q2/Q3 there).Prior.logpdfandpdfpromise a physical density and should route throughfactor(or be renamed/documented). Small, standalone, user-facing correctness fix.The other coherent option — adding
log_dettologpdfitself so everything is physical — touches every EP path at once and shifts EP Laplace modes to physical-space MAPs; that is a design change that should only be taken inside the #1500 single-source-density decision.External verification requested
This analysis is AI-generated. Before acting on it we'd value a check from someone with a probabilistic-programming background on two claims in particular: (a) that the likelihood-factor tilted objective as implemented equals the base-space tilted density (the change-of-variables argument above), and (b) that
PriorFactor's use of the physical density really does leave its tilted objective onelog_det(x)off either coherent convention.Generated by Claude Code