Repository navigation
fix(laplace): refresh deterministic-variable covariance on the fd-Hessian path - #1573
Merged
Merged
Conversation
…sian path (#1570) The fd branch of LaplaceOptimiser.optimise_approx wrote only the free-variable Hessian; det_hessian kept the cavity precision prepare_state built, because refine_state / quasi_deterministic_update moved to the quasi branch in #1562. For z = 2x with initial q(z) = N(0, 10) EP returned Var(z) = 100 with success=True (quasi path: 0.8, truth 0.8). Push the free-variable covariance through the factor's Jacobian (central differences of deterministic_values) and write the diagonal of J Σ Jᵀ as the deterministic precision; diagonal only, because J Σ Jᵀ is rank-deficient when n_det > n_free and MeanField.from_mode consumes marginals. Codex review of the phase-2 fixes, finding 1 (P1). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Gu4YysuvpQ4k6zkQjiwabd
This was referenced Sep 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1570. Finding 1 (P1) of the Codex review of the phase-2 EP fixes (#1562 introduced the fd path; umbrella #1405).
Problem
The fd branch of
LaplaceOptimiser.optimise_approxwrote only the free-variable Hessian.det_hessiankept the cavity precisionprepare_statebuilt, becauserefine_state/newton.quasi_deterministic_updatemoved to the quasi branch in #1562. The deterministic variables were therefore projected at their cavity covariance, withsuccess=True.hessian="fd"beforehessian="fd"afterhessian="quasi"The campaign referee (
analytic_gaussian_collapse.py) has nofactor_out, and no unit test asserted a deterministic variable's variance, so this was invisible to every gate.Fix
LaplaceOptimiser.make_deterministic_hessian: central-difference the factor'sdeterministic_valueswith respect to the free parameters (on the same steps as the mode Hessian, now shared viafd_steps) to get J, and writediag(J Σ Jᵀ)⁻¹as the deterministic precision, Σ =hessian.inv(). Diagonal only:J Σ Jᵀis rank-deficient whenever there are more deterministic outputs than free parameters (a regression factor with 50 outputs and 3 parameters), andMeanField.from_modereads only the marginals. An output the free parameters do not move keeps its cavity curvature.API Changes
None.
fd_stepsis a pure extraction of the existing step rule frommake_mode_hessian.Tests
test__deterministic_variance_follows_the_free_variable[fd|quasi]intest_autofit/graphical/functionality/test_laplace_hessian.py: Var(x) ≈ 0.2, Var(z) ≈ 0.8 (rel 1e-2); fails onfdwithout the fix, passes onquasibefore and after.test_autofit/graphical: 267 passed.test_autofit/messages: 93 passed.autofit_workspace_test/scripts/graphical/ep_deterministic.pyPASS;analytic_gaussian_collapse.pyCOLLAPSE CONFIG: PASS (5/5 seeds), RECOVER 5/5, seed 0 σ 9.24 ± 3.61 vs exact 6.57 (unchanged from the phase-2 record).Note: the deterministic factor's own projection reports
BAD_PROJECTIONwithupdated=Trueon late sweeps, before and after this change; that flag is #1571.🤖 Generated with Claude Code
https://claude.ai/code/session_01Gu4YysuvpQ4k6zkQjiwabd