Skip to content

fix(laplace): refresh deterministic-variable covariance on the fd-Hessian path - #1573

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/ep-laplace-deterministic-hessian
Sep 7, 2026
Merged

Jammy2211 merged 1 commit into
mainfrom
feature/ep-laplace-deterministic-hessian

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

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_approx wrote only the free-variable Hessian. det_hessian kept the cavity precision prepare_state built, because refine_state / newton.quasi_deterministic_update moved to the quasi branch in #1562. The deterministic variables were therefore projected at their cavity covariance, with success=True.

path Var(x) Var(z) for z = 2x (initial q(z) = N(0, 10))
hessian="fd" before 0.1996 100.0
hessian="fd" after 0.1996 0.8000
hessian="quasi" 0.1996 0.8000
truth 0.2 0.8

The campaign referee (analytic_gaussian_collapse.py) has no factor_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's deterministic_values with respect to the free parameters (on the same steps as the mode Hessian, now shared via fd_steps) to get J, and write diag(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), and MeanField.from_mode reads only the marginals. An output the free parameters do not move keeps its cavity curvature.

API Changes

None. fd_steps is a pure extraction of the existing step rule from make_mode_hessian.

Tests

  • New test__deterministic_variance_follows_the_free_variable[fd|quasi] in test_autofit/graphical/functionality/test_laplace_hessian.py: Var(x) ≈ 0.2, Var(z) ≈ 0.8 (rel 1e-2); fails on fd without the fix, passes on quasi before and after.
  • test_autofit/graphical: 267 passed. test_autofit/messages: 93 passed.
  • Workspace: autofit_workspace_test/scripts/graphical/ep_deterministic.py PASS; analytic_gaussian_collapse.py COLLAPSE 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_PROJECTION with updated=True on late sweeps, before and after this change; that flag is #1571.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Gu4YysuvpQ4k6zkQjiwabd

…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
@Jammy2211 Jammy2211 added the pending-release PR queued for the next release build label Sep 7, 2026
@Jammy2211
Jammy2211 merged commit 470a89c into main Sep 7, 2026
4 checks passed
@Jammy2211
Jammy2211 deleted the feature/ep-laplace-deterministic-hessian branch September 7, 2026 21:32
@Jammy2211 Jammy2211 removed the pending-release PR queued for the next release build label Sep 26, 2026
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.

fix(laplace): refresh deterministic-variable covariance on the fd-Hessian path

1 participant