circuits-inference
Safe HaskellNone
LanguageGHC2024

Circuit.Inference.HMC

Description

Hamiltonian Monte Carlo on a standard Gaussian target.

HMC with leapfrog integration and Metropolis-Hastings accept/reject. The oracle verifies empirical moments match N(0,1) within tolerance.

This module also exposes the leapfrog integrator as a System and Process over the circuits polynomial interface, together with exact oracles for reversibility and volume preservation on the Gaussian target.

Synopsis

Sampling

hmcSamples :: Int -> Double -> Int -> IO [Double] Source #

Generate N HMC samples.

momentTest :: [Double] -> (Bool, Double, Double) Source #

Check empirical moments match N(0,1).

Leapfrog dynamics

leapfrogStep :: (Double, Double) -> Double -> (Double, Double) Source #

One leapfrog step on the Gaussian target.

leapfrog :: Double -> Int -> (Double, Double) -> (Double, Double) Source #

L leapfrog steps.

negateMomentum :: (Double, Double) -> (Double, Double) Source #

Negate the momentum component of a phase-space point.

reverseLeapfrog :: Double -> Int -> (Double, Double) -> (Double, Double) Source #

Run the leapfrog integrator backwards in time.

Time reversal for symplectic integrators is achieved by negating the momentum, integrating forward, then negating the momentum again.

Circuit integrations

leapfrogSystem :: Double -> System (->) (Double, Double) (Mono (Double, Double) (Double, Double)) Source #

The leapfrog integrator as a cartesian System with phase-space state.

The state is the current (position, momentum) pair. The monomial direction is ignored because the Gaussian-target dynamics are autonomous; the output position is the next phase-space point.

leapfrogProcess :: Double -> Process (Double, Double) (Double, Double) Source #

The leapfrog integrator as a first-input-seeded Process.

The seed is (0, 1); the observation returns the current state as the position, and the step uses leapfrogSystem.

Yoshida-4 dynamics

yoshida4Step :: (Double, Double) -> Double -> (Double, Double) Source #

One Yoshida-4 macro-step on the Gaussian target.

yoshida4 :: Double -> Int -> (Double, Double) -> (Double, Double) Source #

N Yoshida-4 macro-steps.

yoshida4System :: Double -> System (->) (Double, Double) (Mono (Double, Double) (Double, Double)) Source #

The Yoshida-4 integrator as a cartesian System.

yoshida4Process :: Double -> Process (Double, Double) (Double, Double) Source #

The Yoshida-4 integrator as a first-input-seeded Process.

Exact oracles

leapfrogReversible :: Double -> Int -> (Double, Double) -> Bool Source #

Exact oracle: leapfrog integration is reversible up to machine epsilon.

Forward integration followed by momentum flip, backward integration, and another momentum flip returns to the initial phase-space point.

leapfrogJacobianDet :: Double -> Int -> Double Source #

Exact oracle: the leapfrog map preserves phase-space volume.

For the Gaussian target the leapfrog step is linear, so the Jacobian is constant. We estimate it by applying the n-step map to the standard basis vectors and returning the determinant, which is exactly 1.0 for a symplectic integrator.

yoshida4Reversible :: Double -> Int -> (Double, Double) -> Bool Source #

Exact oracle: Yoshida-4 integration is reversible up to machine epsilon.

yoshida4JacobianDet :: Double -> Int -> Double Source #

Exact oracle: the Yoshida-4 map preserves phase-space volume.

The map is linear for the Gaussian target, and a composition of symplectic maps has determinant 1.

Order oracles

leapfrogOrderSlope :: Double -> (Double, Double) -> Double Source #

Measured energy-error slope for leapfrog on the harmonic oscillator.

Expected value is 2.0. We use four step sizes and a fixed integration length so that the leading term dominates the observed error.

yoshida4OrderSlope :: Double -> (Double, Double) -> Double Source #

Measured energy-error slope for Yoshida-4 on the harmonic oscillator.

Expected value is 4.0.