| Safe Haskell | None |
|---|---|
| Language | GHC2024 |
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
- hmcSamples :: Int -> Double -> Int -> IO [Double]
- momentTest :: [Double] -> (Bool, Double, Double)
- leapfrogStep :: (Double, Double) -> Double -> (Double, Double)
- leapfrog :: Double -> Int -> (Double, Double) -> (Double, Double)
- negateMomentum :: (Double, Double) -> (Double, Double)
- reverseLeapfrog :: Double -> Int -> (Double, Double) -> (Double, Double)
- leapfrogSystem :: Double -> System (->) (Double, Double) (Mono (Double, Double) (Double, Double))
- leapfrogProcess :: Double -> Process (Double, Double) (Double, Double)
- yoshida4Step :: (Double, Double) -> Double -> (Double, Double)
- yoshida4 :: Double -> Int -> (Double, Double) -> (Double, Double)
- yoshida4System :: Double -> System (->) (Double, Double) (Mono (Double, Double) (Double, Double))
- yoshida4Process :: Double -> Process (Double, Double) (Double, Double)
- leapfrogReversible :: Double -> Int -> (Double, Double) -> Bool
- leapfrogJacobianDet :: Double -> Int -> Double
- yoshida4Reversible :: Double -> Int -> (Double, Double) -> Bool
- yoshida4JacobianDet :: Double -> Int -> Double
- leapfrogOrderSlope :: Double -> (Double, Double) -> Double
- yoshida4OrderSlope :: Double -> (Double, Double) -> Double
Sampling
Leapfrog dynamics
leapfrogStep :: (Double, Double) -> Double -> (Double, Double) Source #
One leapfrog step on the Gaussian target.
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.
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.