{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Mcmc.Proposal.Hamiltonian.Hamiltonian
(
HParams (..),
defaultHParams,
hamiltonian,
)
where
import Data.Bifunctor
import Mcmc.Acceptance
import Mcmc.Algorithm.MHG
import Mcmc.Proposal
import Mcmc.Proposal.Hamiltonian.Common
import Mcmc.Proposal.Hamiltonian.Internal
import Mcmc.Proposal.Hamiltonian.Masses
import Numeric.AD.Double
import qualified Numeric.LinearAlgebra as L
import Numeric.Log
import System.Random.Stateful
data HParams = HParams
{ HParams -> Maybe LeapfrogScalingFactor
hLeapfrogScalingFactor :: Maybe LeapfrogScalingFactor,
HParams -> Maybe LeapfrogScalingFactor
hLeapfrogSimulationLength :: Maybe LeapfrogSimulationLength,
HParams -> Maybe Masses
hMasses :: Maybe Masses
}
deriving (Int -> HParams -> ShowS
[HParams] -> ShowS
HParams -> String
(Int -> HParams -> ShowS)
-> (HParams -> String) -> ([HParams] -> ShowS) -> Show HParams
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [HParams] -> ShowS
$cshowList :: [HParams] -> ShowS
show :: HParams -> String
$cshow :: HParams -> String
showsPrec :: Int -> HParams -> ShowS
$cshowsPrec :: Int -> HParams -> ShowS
Show)
defaultHParams :: HParams
defaultHParams :: HParams
defaultHParams = Maybe LeapfrogScalingFactor
-> Maybe LeapfrogScalingFactor -> Maybe Masses -> HParams
HParams Maybe LeapfrogScalingFactor
forall a. Maybe a
Nothing Maybe LeapfrogScalingFactor
forall a. Maybe a
Nothing Maybe Masses
forall a. Maybe a
Nothing
hamiltonianPFunctionWithTuningParameters ::
Traversable s =>
Dimension ->
HStructure s ->
(s Double -> Target) ->
TuningParameter ->
AuxiliaryTuningParameters ->
Either String (PFunction (s Double))
hamiltonianPFunctionWithTuningParameters :: Int
-> HStructure s
-> (s LeapfrogScalingFactor -> Target)
-> LeapfrogScalingFactor
-> AuxiliaryTuningParameters
-> Either String (PFunction (s LeapfrogScalingFactor))
hamiltonianPFunctionWithTuningParameters Int
d HStructure s
hstruct s LeapfrogScalingFactor -> Target
targetWith LeapfrogScalingFactor
_ AuxiliaryTuningParameters
ts = do
HParamsI
hParamsI <- Int -> AuxiliaryTuningParameters -> Either String HParamsI
fromAuxiliaryTuningParameters Int
d AuxiliaryTuningParameters
ts
PFunction (s LeapfrogScalingFactor)
-> Either String (PFunction (s LeapfrogScalingFactor))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PFunction (s LeapfrogScalingFactor)
-> Either String (PFunction (s LeapfrogScalingFactor)))
-> PFunction (s LeapfrogScalingFactor)
-> Either String (PFunction (s LeapfrogScalingFactor))
forall a b. (a -> b) -> a -> b
$ HParamsI
-> HStructure s
-> (s LeapfrogScalingFactor -> Target)
-> PFunction (s LeapfrogScalingFactor)
forall (s :: * -> *).
HParamsI
-> HStructure s
-> (s LeapfrogScalingFactor -> Target)
-> PFunction (s LeapfrogScalingFactor)
hamiltonianPFunction HParamsI
hParamsI HStructure s
hstruct s LeapfrogScalingFactor -> Target
targetWith
hamiltonianPFunction ::
HParamsI ->
HStructure s ->
(s Double -> Target) ->
PFunction (s Double)
hamiltonianPFunction :: HParamsI
-> HStructure s
-> (s LeapfrogScalingFactor -> Target)
-> PFunction (s LeapfrogScalingFactor)
hamiltonianPFunction HParamsI
hparamsi HStructure s
hstruct s LeapfrogScalingFactor -> Target
targetWith s LeapfrogScalingFactor
x IOGenM StdGen
g = do
Momenta
p <- Momenta -> Masses -> IOGenM StdGen -> IO Momenta
forall g (m :: * -> *).
StatefulGen g m =>
Momenta -> Masses -> g -> m Momenta
generateMomenta Momenta
mus Masses
ms IOGenM StdGen
g
LeapfrogScalingFactor
eRan <- (LeapfrogScalingFactor, LeapfrogScalingFactor)
-> IOGenM StdGen -> IO LeapfrogScalingFactor
forall a g (m :: * -> *).
(UniformRange a, StatefulGen g m) =>
(a, a) -> g -> m a
uniformRM (LeapfrogScalingFactor
eL, LeapfrogScalingFactor
eR) IOGenM StdGen
g
let lM :: LeapfrogScalingFactor
lM = LeapfrogScalingFactor
la LeapfrogScalingFactor
-> LeapfrogScalingFactor -> LeapfrogScalingFactor
forall a. Fractional a => a -> a -> a
/ LeapfrogScalingFactor
eRan
lL :: Int
lL = [Int] -> Int
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
maximum [Int
1 :: Int, LeapfrogScalingFactor -> Int
forall a b. (RealFrac a, Integral b) => a -> b
floor (LeapfrogScalingFactor -> Int) -> LeapfrogScalingFactor -> Int
forall a b. (a -> b) -> a -> b
$ LeapfrogScalingFactor
0.9 LeapfrogScalingFactor
-> LeapfrogScalingFactor -> LeapfrogScalingFactor
forall a. Num a => a -> a -> a
* LeapfrogScalingFactor
lM]
lR :: Int
lR = [Int] -> Int
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
maximum [Int
lL, LeapfrogScalingFactor -> Int
forall a b. (RealFrac a, Integral b) => a -> b
ceiling (LeapfrogScalingFactor -> Int) -> LeapfrogScalingFactor -> Int
forall a b. (a -> b) -> a -> b
$ LeapfrogScalingFactor
1.1 LeapfrogScalingFactor
-> LeapfrogScalingFactor -> LeapfrogScalingFactor
forall a. Num a => a -> a -> a
* LeapfrogScalingFactor
lM]
Int
lRan <- (Int, Int) -> IOGenM StdGen -> IO Int
forall a g (m :: * -> *).
(UniformRange a, StatefulGen g m) =>
(a, a) -> g -> m a
uniformRM (Int
lL, Int
lR) IOGenM StdGen
g
case Target
-> MassesI
-> Int
-> LeapfrogScalingFactor
-> Momenta
-> Momenta
-> Maybe
(Momenta, Momenta, Log LeapfrogScalingFactor,
Log LeapfrogScalingFactor)
leapfrog (s LeapfrogScalingFactor -> Target
targetWith s LeapfrogScalingFactor
x) MassesI
msI Int
lRan LeapfrogScalingFactor
eRan Momenta
q Momenta
p of
Maybe
(Momenta, Momenta, Log LeapfrogScalingFactor,
Log LeapfrogScalingFactor)
Nothing -> (PResult (s LeapfrogScalingFactor), Maybe AcceptanceCounts)
-> IO (PResult (s LeapfrogScalingFactor), Maybe AcceptanceCounts)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PResult (s LeapfrogScalingFactor)
forall a. PResult a
ForceReject, AcceptanceCounts -> Maybe AcceptanceCounts
forall a. a -> Maybe a
Just (AcceptanceCounts -> Maybe AcceptanceCounts)
-> AcceptanceCounts -> Maybe AcceptanceCounts
forall a b. (a -> b) -> a -> b
$ Int -> Int -> AcceptanceCounts
AcceptanceCounts Int
0 Int
100)
Just (Momenta
q', Momenta
p', Log LeapfrogScalingFactor
prQ, Log LeapfrogScalingFactor
prQ') -> do
let
prP :: Log LeapfrogScalingFactor
prP = MassesI -> Momenta -> Log LeapfrogScalingFactor
exponentialKineticEnergy MassesI
msI Momenta
p
prP' :: Log LeapfrogScalingFactor
prP' = MassesI -> Momenta -> Log LeapfrogScalingFactor
exponentialKineticEnergy MassesI
msI Momenta
p'
r :: Log LeapfrogScalingFactor
r = Log LeapfrogScalingFactor
prQ' Log LeapfrogScalingFactor
-> Log LeapfrogScalingFactor -> Log LeapfrogScalingFactor
forall a. Num a => a -> a -> a
* Log LeapfrogScalingFactor
prP' Log LeapfrogScalingFactor
-> Log LeapfrogScalingFactor -> Log LeapfrogScalingFactor
forall a. Fractional a => a -> a -> a
/ (Log LeapfrogScalingFactor
prQ Log LeapfrogScalingFactor
-> Log LeapfrogScalingFactor -> Log LeapfrogScalingFactor
forall a. Num a => a -> a -> a
* Log LeapfrogScalingFactor
prP)
Bool
accept <- Log LeapfrogScalingFactor -> IOGenM StdGen -> IO Bool
mhgAccept Log LeapfrogScalingFactor
r IOGenM StdGen
g
let pr :: PResult (s LeapfrogScalingFactor)
pr = if Bool
accept then s LeapfrogScalingFactor -> PResult (s LeapfrogScalingFactor)
forall a. a -> PResult a
ForceAccept (s LeapfrogScalingFactor -> Momenta -> s LeapfrogScalingFactor
fromVec s LeapfrogScalingFactor
x Momenta
q') else PResult (s LeapfrogScalingFactor)
forall a. PResult a
ForceReject
ar :: LeapfrogScalingFactor
ar = LeapfrogScalingFactor -> LeapfrogScalingFactor
forall a. Floating a => a -> a
exp (LeapfrogScalingFactor -> LeapfrogScalingFactor)
-> LeapfrogScalingFactor -> LeapfrogScalingFactor
forall a b. (a -> b) -> a -> b
$ Log LeapfrogScalingFactor -> LeapfrogScalingFactor
forall a. Log a -> a
ln Log LeapfrogScalingFactor
r
getCounts :: a -> a
getCounts a
s = a -> a -> a
forall a. Ord a => a -> a -> a
max a
0 (a -> a) -> a -> a
forall a b. (a -> b) -> a -> b
$ a -> a -> a
forall a. Ord a => a -> a -> a
min a
100 (a -> a) -> a -> a
forall a b. (a -> b) -> a -> b
$ a -> a
forall a b. (RealFrac a, Integral b) => a -> b
round (a -> a) -> a -> a
forall a b. (a -> b) -> a -> b
$ a
s a -> a -> a
forall a. Num a => a -> a -> a
* a
100
ac :: AcceptanceCounts
ac =
if LeapfrogScalingFactor
ar LeapfrogScalingFactor -> LeapfrogScalingFactor -> Bool
forall a. Ord a => a -> a -> Bool
>= LeapfrogScalingFactor
0
then let cs :: Int
cs = LeapfrogScalingFactor -> Int
forall a a. (RealFrac a, Integral a) => a -> a
getCounts LeapfrogScalingFactor
ar in Int -> Int -> AcceptanceCounts
AcceptanceCounts Int
cs (Int
100 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
cs)
else String -> AcceptanceCounts
forall a. HasCallStack => String -> a
error (String -> AcceptanceCounts) -> String -> AcceptanceCounts
forall a b. (a -> b) -> a -> b
$ String
"hamiltonianPFunction: Acceptance rate negative."
(PResult (s LeapfrogScalingFactor), Maybe AcceptanceCounts)
-> IO (PResult (s LeapfrogScalingFactor), Maybe AcceptanceCounts)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (PResult (s LeapfrogScalingFactor)
pr, AcceptanceCounts -> Maybe AcceptanceCounts
forall a. a -> Maybe a
Just AcceptanceCounts
ac)
where
(HParamsI LeapfrogScalingFactor
e LeapfrogScalingFactor
la Masses
ms TParamsVar
_ TParamsFixed
_ MassesI
msI Momenta
mus) = HParamsI
hparamsi
(HStructure s LeapfrogScalingFactor
_ s LeapfrogScalingFactor -> Momenta
toVec s LeapfrogScalingFactor -> Momenta -> s LeapfrogScalingFactor
fromVec) = HStructure s
hstruct
q :: Momenta
q = s LeapfrogScalingFactor -> Momenta
toVec s LeapfrogScalingFactor
x
eL :: LeapfrogScalingFactor
eL = LeapfrogScalingFactor
0.9 LeapfrogScalingFactor
-> LeapfrogScalingFactor -> LeapfrogScalingFactor
forall a. Num a => a -> a -> a
* LeapfrogScalingFactor
e
eR :: LeapfrogScalingFactor
eR = LeapfrogScalingFactor
1.1 LeapfrogScalingFactor
-> LeapfrogScalingFactor -> LeapfrogScalingFactor
forall a. Num a => a -> a -> a
* LeapfrogScalingFactor
e
hamiltonian ::
Traversable s =>
HParams ->
HTuningConf ->
HStructure s ->
HTarget s ->
PName ->
PWeight ->
Proposal (s Double)
hamiltonian :: HParams
-> HTuningConf
-> HStructure s
-> HTarget s
-> PName
-> PWeight
-> Proposal (s LeapfrogScalingFactor)
hamiltonian HParams
hparams HTuningConf
htconf HStructure s
hstruct HTarget s
htarget PName
n PWeight
w =
let
desc :: PDescription
desc = String -> PDescription
PDescription String
"Hamiltonian Monte Carlo (HMC)"
(HStructure s LeapfrogScalingFactor
sample s LeapfrogScalingFactor -> Momenta
toVec s LeapfrogScalingFactor -> Momenta -> s LeapfrogScalingFactor
fromVec) = HStructure s
hstruct
dim :: IndexOf Vector
dim = Momenta -> IndexOf Vector
forall (c :: * -> *) t. Container c t => c t -> IndexOf c
L.size (Momenta -> IndexOf Vector) -> Momenta -> IndexOf Vector
forall a b. (a -> b) -> a -> b
$ s LeapfrogScalingFactor -> Momenta
toVec s LeapfrogScalingFactor
sample
pDim :: PDimension
pDim = Int -> LeapfrogScalingFactor -> PDimension
PSpecial Int
dim LeapfrogScalingFactor
0.65
(HTarget forall a.
(RealFloat a, Typeable a) =>
Maybe (PriorFunctionG (s a) a)
mPrF forall a. (RealFloat a, Typeable a) => LikelihoodFunctionG (s a) a
lhF forall a.
(RealFloat a, Typeable a) =>
Maybe (PriorFunctionG (s a) a)
mJcF) = HTarget s
htarget
tF :: s a -> LikelihoodG a
tF s a
y = case (Maybe (s a -> LikelihoodG a)
forall a.
(RealFloat a, Typeable a) =>
Maybe (PriorFunctionG (s a) a)
mPrF, Maybe (s a -> LikelihoodG a)
forall a.
(RealFloat a, Typeable a) =>
Maybe (PriorFunctionG (s a) a)
mJcF) of
(Maybe (s a -> LikelihoodG a)
Nothing, Maybe (s a -> LikelihoodG a)
Nothing) -> s a -> LikelihoodG a
forall a. (RealFloat a, Typeable a) => LikelihoodFunctionG (s a) a
lhF s a
y
(Just s a -> LikelihoodG a
prF, Maybe (s a -> LikelihoodG a)
Nothing) -> s a -> LikelihoodG a
prF s a
y LikelihoodG a -> LikelihoodG a -> LikelihoodG a
forall a. Num a => a -> a -> a
* s a -> LikelihoodG a
forall a. (RealFloat a, Typeable a) => LikelihoodFunctionG (s a) a
lhF s a
y
(Maybe (s a -> LikelihoodG a)
Nothing, Just s a -> LikelihoodG a
jcF) -> s a -> LikelihoodG a
forall a. (RealFloat a, Typeable a) => LikelihoodFunctionG (s a) a
lhF s a
y LikelihoodG a -> LikelihoodG a -> LikelihoodG a
forall a. Num a => a -> a -> a
* s a -> LikelihoodG a
jcF s a
y
(Just s a -> LikelihoodG a
prF, Just s a -> LikelihoodG a
jcF) -> s a -> LikelihoodG a
prF s a
y LikelihoodG a -> LikelihoodG a -> LikelihoodG a
forall a. Num a => a -> a -> a
* s a -> LikelihoodG a
forall a. (RealFloat a, Typeable a) => LikelihoodFunctionG (s a) a
lhF s a
y LikelihoodG a -> LikelihoodG a -> LikelihoodG a
forall a. Num a => a -> a -> a
* s a -> LikelihoodG a
jcF s a
y
tFnG :: s LeapfrogScalingFactor
-> (LeapfrogScalingFactor, s LeapfrogScalingFactor)
tFnG = (forall s.
(Reifies s Tape, Typeable s) =>
s (ReverseDouble s) -> ReverseDouble s)
-> s LeapfrogScalingFactor
-> (LeapfrogScalingFactor, s LeapfrogScalingFactor)
forall (f :: * -> *).
Traversable f =>
(forall s.
(Reifies s Tape, Typeable s) =>
f (ReverseDouble s) -> ReverseDouble s)
-> f LeapfrogScalingFactor
-> (LeapfrogScalingFactor, f LeapfrogScalingFactor)
grad' (Log (ReverseDouble s) -> ReverseDouble s
forall a. Log a -> a
ln (Log (ReverseDouble s) -> ReverseDouble s)
-> (s (ReverseDouble s) -> Log (ReverseDouble s))
-> s (ReverseDouble s)
-> ReverseDouble s
forall b c a. (b -> c) -> (a -> b) -> a -> c
. s (ReverseDouble s) -> Log (ReverseDouble s)
forall a. (RealFloat a, Typeable a) => LikelihoodFunctionG (s a) a
tF)
targetWith :: s LeapfrogScalingFactor -> Target
targetWith s LeapfrogScalingFactor
x = (LeapfrogScalingFactor -> Log LeapfrogScalingFactor)
-> (s LeapfrogScalingFactor -> Momenta)
-> (LeapfrogScalingFactor, s LeapfrogScalingFactor)
-> (Log LeapfrogScalingFactor, Momenta)
forall (p :: * -> * -> *) a b c d.
Bifunctor p =>
(a -> b) -> (c -> d) -> p a c -> p b d
bimap LeapfrogScalingFactor -> Log LeapfrogScalingFactor
forall a. a -> Log a
Exp s LeapfrogScalingFactor -> Momenta
toVec ((LeapfrogScalingFactor, s LeapfrogScalingFactor)
-> (Log LeapfrogScalingFactor, Momenta))
-> (Momenta -> (LeapfrogScalingFactor, s LeapfrogScalingFactor))
-> Target
forall b c a. (b -> c) -> (a -> b) -> a -> c
. s LeapfrogScalingFactor
-> (LeapfrogScalingFactor, s LeapfrogScalingFactor)
tFnG (s LeapfrogScalingFactor
-> (LeapfrogScalingFactor, s LeapfrogScalingFactor))
-> (Momenta -> s LeapfrogScalingFactor)
-> Momenta
-> (LeapfrogScalingFactor, s LeapfrogScalingFactor)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. s LeapfrogScalingFactor -> Momenta -> s LeapfrogScalingFactor
fromVec s LeapfrogScalingFactor
x
(HParams Maybe LeapfrogScalingFactor
mEps Maybe LeapfrogScalingFactor
mLa Maybe Masses
mMs) = HParams
hparams
hParamsI :: HParamsI
hParamsI =
(String -> HParamsI)
-> (HParamsI -> HParamsI) -> Either String HParamsI -> HParamsI
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either String -> HParamsI
forall a. HasCallStack => String -> a
error HParamsI -> HParamsI
forall a. a -> a
id (Either String HParamsI -> HParamsI)
-> Either String HParamsI -> HParamsI
forall a b. (a -> b) -> a -> b
$
Target
-> Momenta
-> Maybe LeapfrogScalingFactor
-> Maybe LeapfrogScalingFactor
-> Maybe Masses
-> Either String HParamsI
hParamsIWith (s LeapfrogScalingFactor -> Target
targetWith s LeapfrogScalingFactor
sample) (s LeapfrogScalingFactor -> Momenta
toVec s LeapfrogScalingFactor
sample) Maybe LeapfrogScalingFactor
mEps Maybe LeapfrogScalingFactor
mLa Maybe Masses
mMs
ps :: PFunction (s LeapfrogScalingFactor)
ps = HParamsI
-> HStructure s
-> (s LeapfrogScalingFactor -> Target)
-> PFunction (s LeapfrogScalingFactor)
forall (s :: * -> *).
HParamsI
-> HStructure s
-> (s LeapfrogScalingFactor -> Target)
-> PFunction (s LeapfrogScalingFactor)
hamiltonianPFunction HParamsI
hParamsI HStructure s
hstruct s LeapfrogScalingFactor -> Target
targetWith
hamiltonianWith :: Maybe (Tuner (s LeapfrogScalingFactor))
-> Proposal (s LeapfrogScalingFactor)
hamiltonianWith = PName
-> PDescription
-> PSpeed
-> PDimension
-> PWeight
-> PFunction (s LeapfrogScalingFactor)
-> Maybe (Tuner (s LeapfrogScalingFactor))
-> Proposal (s LeapfrogScalingFactor)
forall a.
PName
-> PDescription
-> PSpeed
-> PDimension
-> PWeight
-> PFunction a
-> Maybe (Tuner a)
-> Proposal a
Proposal PName
n PDescription
desc PSpeed
PSlow PDimension
pDim PWeight
w PFunction (s LeapfrogScalingFactor)
ps
ts :: AuxiliaryTuningParameters
ts = HParamsI -> AuxiliaryTuningParameters
toAuxiliaryTuningParameters HParamsI
hParamsI
tuner :: Maybe (Tuner (s LeapfrogScalingFactor))
tuner = do
TuningFunction (s LeapfrogScalingFactor)
tfun <- Int
-> (s LeapfrogScalingFactor -> Momenta)
-> HTuningConf
-> Maybe (TuningFunction (s LeapfrogScalingFactor))
forall a.
Int -> (a -> Momenta) -> HTuningConf -> Maybe (TuningFunction a)
hTuningFunctionWith Int
dim s LeapfrogScalingFactor -> Momenta
toVec HTuningConf
htconf
let pfun :: LeapfrogScalingFactor
-> AuxiliaryTuningParameters
-> Either String (PFunction (s LeapfrogScalingFactor))
pfun = Int
-> HStructure s
-> (s LeapfrogScalingFactor -> Target)
-> LeapfrogScalingFactor
-> AuxiliaryTuningParameters
-> Either String (PFunction (s LeapfrogScalingFactor))
forall (s :: * -> *).
Traversable s =>
Int
-> HStructure s
-> (s LeapfrogScalingFactor -> Target)
-> LeapfrogScalingFactor
-> AuxiliaryTuningParameters
-> Either String (PFunction (s LeapfrogScalingFactor))
hamiltonianPFunctionWithTuningParameters Int
dim HStructure s
hstruct s LeapfrogScalingFactor -> Target
targetWith
Tuner (s LeapfrogScalingFactor)
-> Maybe (Tuner (s LeapfrogScalingFactor))
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Tuner (s LeapfrogScalingFactor)
-> Maybe (Tuner (s LeapfrogScalingFactor)))
-> Tuner (s LeapfrogScalingFactor)
-> Maybe (Tuner (s LeapfrogScalingFactor))
forall a b. (a -> b) -> a -> b
$ LeapfrogScalingFactor
-> AuxiliaryTuningParameters
-> Bool
-> TuningFunction (s LeapfrogScalingFactor)
-> (LeapfrogScalingFactor
-> AuxiliaryTuningParameters
-> Either String (PFunction (s LeapfrogScalingFactor)))
-> Tuner (s LeapfrogScalingFactor)
forall a.
LeapfrogScalingFactor
-> AuxiliaryTuningParameters
-> Bool
-> TuningFunction a
-> (LeapfrogScalingFactor
-> AuxiliaryTuningParameters -> Either String (PFunction a))
-> Tuner a
Tuner LeapfrogScalingFactor
1.0 AuxiliaryTuningParameters
ts Bool
True TuningFunction (s LeapfrogScalingFactor)
tfun LeapfrogScalingFactor
-> AuxiliaryTuningParameters
-> Either String (PFunction (s LeapfrogScalingFactor))
pfun
in case Masses -> HStructure s -> Maybe String
forall (s :: * -> *).
Foldable s =>
Masses -> HStructure s -> Maybe String
checkHStructureWith (HParamsI -> Masses
hpsMasses HParamsI
hParamsI) HStructure s
hstruct of
Just String
err -> String -> Proposal (s LeapfrogScalingFactor)
forall a. HasCallStack => String -> a
error String
err
Maybe String
Nothing -> Maybe (Tuner (s LeapfrogScalingFactor))
-> Proposal (s LeapfrogScalingFactor)
hamiltonianWith Maybe (Tuner (s LeapfrogScalingFactor))
tuner