Latent-variable EBM: LatentEBM (joint E(x,z), block-Gibbs sampled) - #55
Merged
Conversation
A latent-variable EBM coupling a prior over a latent z (default standard normal) with a decoder energy E(x|z) into a joint E(x,z)=E_prior(z)+E(x|z). The data marginal is intractable, so sample_joint runs block Gibbs — alternating an MCMC update of z under its posterior E(z|x) with an update of x under E(x|z); posterior_energy/conditional_energy expose those blocks as plain EnergyFns. nn.Module decoder/prior components are registered so they train and freeze. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Block Gibbs recovers the exact marginal N(0, WWᵀ+σ²I); posterior_energy(x) sampled directly matches the conjugate Gaussian posterior z|x (cov and mean). Plus joint/custom-prior/module-registration and sample() shape/z_init cases. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Example: a fixed nonlinear decoder bends a Gaussian latent into a curved 2D manifold; block-Gibbs sampling of the joint matches the ancestral marginal (MMD ~0). Bumps version to 0.16.0 (0.15.0 published), README composition row + examples list updated. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
LatentEBM— the roadmap's final item (E7): a latent-variable energy-based model.What
z(default standard normal) with a decoder energyE(x | z)into a jointE(x, z) = E_prior(z) + E(x | z),p(x, z) ∝ exp(-E).p(x) ∝ ∫ exp(-E(x,z)) dzis intractable — as with all latent EBMs you sample the joint.sample_jointruns block Gibbs: alternate an MCMC update ofzunder its posteriorE(z | x)with an update ofxunderE(x | z).posterior_energy(x)andconditional_energy(z)expose those blocks as plainEnergyFns usable with any sampler.nn.Moduledecoder/prior components are registered, so their parameters train and freeze during sampling like everything else.Validation (closed-form / distributional)
z ~ N(0,I),x|z ~ N(Wz, σ²I)): block Gibbs recovers the exact marginalN(0, WWᵀ + σ²I), andposterior_energy(x)sampled directly matches the conjugate Gaussian posteriorz|x(covariance and mean).latent_ebm.py: a fixed nonlinear decoder bends a Gaussian latent into a curved 2-D manifold; the block-Gibbs marginal matches the ancestral marginal at MMD ≈ 0 (vs 0.14 for a Gaussian).Notes
🤖 Generated with Claude Code