commit 595e98a705f87ebb33b8d0066879fec483157149
parent f2fd3c9aa54aa2314e4a47c5a0771cdc7fde1b43
Author: Jared Tobin <jared@jtobin.ca>
Date: Tue, 4 Aug 2015 14:34:05 -0230
Misc cleanup.
Diffstat:
5 files changed, 22 insertions(+), 16 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -7,3 +7,4 @@ dist
working
cabal.sandbox.config
tests
+.stack-work
diff --git a/Setup.hs b/Setup.hs
@@ -0,0 +1,2 @@
+import Distribution.Simple
+main = defaultMain
diff --git a/hnuts.cabal b/hnuts.cabal
@@ -14,18 +14,16 @@ cabal-version: >= 1.18
library
exposed-modules:
Numeric.MCMC.NUTS
- , Numeric.MCMC.NUTS.Examples
other-extensions:
ScopedTypeVariables
build-depends:
- base >= 4.7
- , monad-loops >= 0.4
- , primitive >= 0.5
- , mwc-random >= 0.12
- , statistics >= 0.10
- , ad >= 3.4
+ base
+ , monad-loops
+ , primitive
+ , mwc-random
+ , statistics
hs-source-dirs:
src
diff --git a/src/Numeric/MCMC/NUTS/Examples.hs b/src/Numeric/MCMC/NUTS/Examples.hs
@@ -1,4 +1,4 @@
--- Various examples, using NUTS with dual-averaging. Insert whatever trace
+-- Various examples, using NUTS with dual-averaging. Insert whatever trace
-- (rosenbrockTrace, bnnTrace, etc.) you want into 'main' in order to spit out
-- some observations.
--
@@ -20,27 +20,27 @@ logRosenbrock :: RealFloat a => [a] -> a
logRosenbrock [x0, x1] = negate (5 * (x1 - x0 ^ 2) ^ 2 + 0.05 * (1 - x0) ^ 2)
rosenbrockTrace :: IO [Parameters]
-rosenbrockTrace = withSystemRandom . asGenST $
+rosenbrockTrace = withSystemRandom . asGenST $
nutsDualAveraging logRosenbrock (grad logRosenbrock) 10000 1000 [0.0, 0.0]
logHimmelblau :: RealFloat a => [a] -> a
logHimmelblau [x0, x1] = negate ((x0 ^ 2 + x1 - 11) ^ 2 + (x0 + x1 ^ 2 - 7) ^ 2)
himmelblauTrace :: IO [Parameters]
-himmelblauTrace = withSystemRandom . asGenST $
- nutsDualAveraging logHimmelblau (grad logHimmelblau) 10000 1000 [0.0, 0.0]
+himmelblauTrace = withSystemRandom . asGenST $
+ nutsDualAveraging logHimmelblau (grad logHimmelblau) 100000 10000 [0.0, 0.0]
logBnn :: RealFloat a => [a] -> a
logBnn [x0, x1] = -0.5 * (x0 ^ 2 * x1 ^ 2 + x0 ^ 2 + x1 ^ 2 - 8 * x0 - 8 * x1)
bnnTrace :: IO [Parameters]
-bnnTrace = withSystemRandom . asGenST $
+bnnTrace = withSystemRandom . asGenST $
nutsDualAveraging logBnn (grad logBnn) 10000 1000 [0.0, 0.0]
logBeale :: RealFloat a => [a] -> a
-logBeale [x0, x1]
+logBeale [x0, x1]
| and [x0 >= -4.5, x0 <= 4.5, x1 >= -4.5, x1 <= 4.5]
- = negate $
+ = negate $
(1.5 - x0 + x0 * x1) ^ 2
+ (2.25 - x0 + x0 * x1 ^ 2) ^ 2
+ (2.625 - x0 + x0 * x1 ^ 3) ^ 2
@@ -51,8 +51,8 @@ bealeTrace = withSystemRandom . asGenST $
nutsDualAveraging logBeale (grad logBeale) 10000 1000 [0.0, 0.0]
printTrace :: Show a => [a] -> IO ()
-printTrace = mapM_ (putStrLn . filter (`notElem` "[]") . show)
+printTrace = mapM_ (putStrLn . filter (`notElem` "[]") . show)
main :: IO ()
-main = bealeTrace >>= printTrace
+main = himmelblauTrace >>= printTrace
diff --git a/stack.yaml b/stack.yaml
@@ -0,0 +1,5 @@
+flags: {}
+packages:
+- '.'
+extra-deps: []
+resolver: lts-2.21