The model is p(x) = exp(−E(x))/Z with the quartic energy E(x) = θ1x + θ2x² + θ3x³ + θ4x⁴, fitted to 400 draws from a two-component mixture (the dotted curve is the truth). Maximum likelihood needs Z; score matching, denoising score matching and noise contrastive estimation (NCE) do not. Pick an estimator, then change the noise level σ of denoising score matching or the width of the NCE noise distribution and watch the fit.
The model lives on the window [−6, 6]. Maximum likelihood uses Newton steps with the model expectation computed by quadrature; score matching and denoising score matching are exact linear solves, because the score −θ·φ′(x) is linear in θ; NCE is a logistic regression with an offset c = −log Z that is learned together with θ. KL is the divergence from the true mixture to the fitted density.
code/ch24_energy_based_models.py (Figure 24.x4, fit_mle_poly, fit_sm_poly, fit_nce_poly).