Skip to content

Recognize affine functions of independent Gaussians as MvNormal logp#8342

Draft
ricardoV94 wants to merge 1 commit into
pymc-devs:mainfrom
ricardoV94:mvnormal_logp_inference
Draft

Recognize affine functions of independent Gaussians as MvNormal logp#8342
ricardoV94 wants to merge 1 commit into
pymc-devs:mainfrom
ricardoV94:mvnormal_logp_inference

Conversation

@ricardoV94

Copy link
Copy Markdown
Member

Teach pymc.logprob to derive the logp of a value variable that is an
affine function of one or more independent Gaussian leaves (e.g. the
low-rank guide loc + W @ ek + d * ed) by propagating moments and
substituting a dense MvNormal, instead of inverting the transform.

This unlocks fundamentally non-invertible cases the existing machinery
declines: wide/low-rank matvecs (find_measurable_matmul bails on
non-square matrices) and sums of >=2 independent Gaussians (the elemwise
transforms require <=1 measurable operand). Covers low-rank ADVI guides,
sums of independent normals, and linear-Gaussian marginalization
(regression coefficients, etc.).

The accumulated covariance is kept dense; exploiting low-rank structure
for an O(D K^2) logp would need a Woodbury rewrite in PyTensor, which
does not exist yet, so the emitted MvNormal does a dense O(D^3) cholesky.

Claude-Session: https://claude.ai/code/session_0183HnSTpYk7UrvAJ7D3kBtj

Teach pymc.logprob to derive the logp of a value variable that is an
affine function of one or more independent Gaussian leaves (e.g. the
low-rank guide loc + W @ ek + d * ed) by propagating moments and
substituting a dense MvNormal, instead of inverting the transform.

This unlocks fundamentally non-invertible cases the existing machinery
declines: wide/low-rank matvecs (find_measurable_matmul bails on
non-square matrices) and sums of >=2 independent Gaussians (the elemwise
transforms require <=1 measurable operand). Covers low-rank ADVI guides,
sums of independent normals, and linear-Gaussian marginalization
(regression coefficients, etc.).

The accumulated covariance is kept dense; exploiting low-rank structure
for an O(D K^2) logp would need a Woodbury rewrite in PyTensor, which
does not exist yet, so the emitted MvNormal does a dense O(D^3) cholesky.

Claude-Session: https://claude.ai/code/session_0183HnSTpYk7UrvAJ7D3kBtj
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 pymc | 🛠️ Build #33330413 | 📁 Comparing b22c382 against latest (558bb5e)

  🔍 Preview build  

1 file changed
± glossary.html

@codecov

codecov Bot commented Jun 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.48387% with 27 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.71%. Comparing base (fffac80) to head (b22c382).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
pymc/logprob/gaussian.py 85.40% 27 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #8342      +/-   ##
==========================================
- Coverage   86.73%   86.71%   -0.03%     
==========================================
  Files         126      127       +1     
  Lines       20595    20781     +186     
==========================================
+ Hits        17863    18020     +157     
- Misses       2732     2761      +29     
Files with missing lines Coverage Δ
pymc/logprob/__init__.py 100.00% <100.00%> (ø)
pymc/logprob/gaussian.py 85.40% <85.40%> (ø)

... and 2 files with indirect coverage changes

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

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