hasty-hamiltonian

Speedy gradient-based traversal through parameter space.
Log | Files | Refs | README | LICENSE

commit 94c6e6a1acad9ac3e32c70d0d5efdd72ca980e0a
parent 21ec191c17f92a9dfd521fedb88f1a70a4f4f8f0
Author: Jared Tobin <jared@jtobin.ca>
Date:   Thu,  8 Oct 2015 21:35:34 +1300

Remove old examples folder.

Diffstat:
DExamples/Example.hs | 30------------------------------
DExamples/Rosenbrock_HMC.hs | 47-----------------------------------------------
DExamples/SPDE_HMC.hs | 55-------------------------------------------------------
3 files changed, 0 insertions(+), 132 deletions(-)

diff --git a/Examples/Example.hs b/Examples/Example.hs @@ -1,30 +0,0 @@ -{-# OPTIONS_GHC -fno-warn-type-defaults #-} - -import Data.Foldable (toList) -import Data.Vector (Vector, fromList) -import Numeric.AD -import Numeric.MCMC.Hamiltonian -import System.Random.MWC - -lRosenbrock :: RealFloat a => Vector a -> a -lRosenbrock xs = negate $ 5 * (x1 - x0 ^ 2) ^ 2 + 0.05 * (1 - x0) ^ 2 where - [x0, x1] = toList xs - -glRosenbrock :: Vector Double -> Vector Double -glRosenbrock = grad lRosenbrock - -rosenbrock :: Target -rosenbrock = Target lRosenbrock glRosenbrock - -tunables :: Tunables -tunables = Tunables 0.001 50 - -options :: Options -options = Options 5000 (fromList [1, 1]) - -main :: IO () -main = do - g <- create - trace <- hmc rosenbrock tunables options g - mapM_ print trace - diff --git a/Examples/Rosenbrock_HMC.hs b/Examples/Rosenbrock_HMC.hs @@ -1,47 +0,0 @@ -import Numeric.MCMC.Hamiltonian -import System.Random.MWC -import System.Environment -import System.Exit -import System.IO -import Numeric.AD -import Control.Monad - -target :: RealFloat a => [a] -> a -target [x0, x1] = (-1)*(5*(x1 - x0^2)^2 + 0.05*(1 - x0)^2) - -gTarget :: [Double] -> [Double] -gTarget = grad target - -main = do - args <- getArgs - when (args == []) $ do - putStrLn "(hasty-hamiltonian) Rosenbrock density " - putStrLn "Usage: ./Rosenbrock_HMC <numSteps> <thinEvery> <nDisc> <stepSize> <inits>" - putStrLn " " - putStrLn "numSteps : Number of Markov chain iterations to run. " - putStrLn "thinEvery : Print every nth iteration. " - putStrLn "nDisc : Number of discretizing steps to take. " - putStrLn "stepSize : Perturbation scaling parameter. " - putStrLn "inits : Filepath containing points at which to " - putStrLn " initialize the chain. " - exitSuccess - - inits <- fmap (map read . words) (readFile (args !! 4)) :: IO [Double] - - let nepochs = read (head args) :: Int - thinEvery = read (args !! 1) :: Int - nDisc = read (args !! 2) :: Double - eps = read (args !! 3) :: Double - params = Options target gTarget nDisc eps - config = MarkovChain inits 0 - - g <- create - results <- runChain params nepochs thinEvery config g - - hPutStrLn stderr $ - let nAcc = accepts results - total = nepochs - in show nAcc ++ " / " ++ show total ++ " (" ++ - show ((fromIntegral nAcc / fromIntegral total) :: Float) ++ - ") proposals accepted" - diff --git a/Examples/SPDE_HMC.hs b/Examples/SPDE_HMC.hs @@ -1,55 +0,0 @@ -{-# LANGUAGE BangPatterns #-} - -import Numeric.MCMC.Hamiltonian -import System.Random.MWC -import System.Environment -import System.Exit -import System.IO -import Control.Monad -import Numeric.AD - -target :: RealFloat a => [a] -> a -target xs = go 0 0 xs - where go t0 t1 [] = (- t0 / (2*h)) - (0.5 * h * t1) - go t0 t1 (u:us:uss) = go (t0 + (us - u)^2) (t1 + v (us + u)) uss - h = 1 / fromIntegral (length xs) - v x = (1 - x^2)^2 -{-# INLINE target #-} - -gTarget :: [Double] -> [Double] -gTarget = grad target -{-# INLINE gTarget #-} - -main = do - args <- getArgs - when (args == []) $ do - putStrLn "(hasty-hamiltonian) Stochastic partial differential equation " - putStrLn "Usage: ./SPDE_HMC <numSteps> <inits> <thinEvery> " - putStrLn " " - putStrLn "numSteps : Number of Markov chain iterations to run. " - putStrLn "thinEvery : Print every nth iteration. " - putStrLn "nDisc : Number of discretizing steps to take. " - putStrLn "stepSize : Perturbation scaling parameter. " - putStrLn "inits : Filepath containing points at which to " - putStrLn " initialize the chain. " - exitSuccess - - inits <- fmap (map read . words) (readFile (args !! 4)) :: IO [Double] - - let nepochs = read (head args) :: Int - thinEvery = read (args !! 1) :: Int - nDisc = read (args !! 2) :: Double - eps = read (args !! 3) :: Double - params = Options target gTarget nDisc eps - config = MarkovChain inits 0 - - g <- create - results <- runChain params nepochs thinEvery config g - - hPutStrLn stderr $ - let nAcc = accepts results - total = nepochs - in show nAcc ++ " / " ++ show total ++ " (" ++ - show ((fromIntegral nAcc / fromIntegral total) :: Float) ++ - ") proposals accepted" -