commit 9817fda834e3e02e82776c9e22e75f8e72de260b
parent 93b0f4b34e6ae7ca21af025f0b97cec99045eb2a
Author: Jared Tobin <jared@jtobin.ca>
Date: Sat, 12 Nov 2016 23:07:44 +1300
Add example executable.
Diffstat:
3 files changed, 35 insertions(+), 0 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -21,3 +21,4 @@ cabal.sandbox.config
.stack-work
debug
Examples
+*prof
diff --git a/flat-mcmc.cabal b/flat-mcmc.cabal
@@ -89,3 +89,14 @@ Test-suite bnn
, flat-mcmc
, vector
+executable bnn-example
+ hs-source-dirs: src
+ main-is: Main.hs
+ default-language: Haskell2010
+ ghc-options:
+ -rtsopts -threaded
+ build-depends:
+ base
+ , flat-mcmc
+ , vector
+
diff --git a/src/Main.hs b/src/Main.hs
@@ -0,0 +1,23 @@
+{-# OPTIONS_GHC -fno-warn-type-defaults #-}
+
+module Main where
+
+import Numeric.MCMC.Flat
+import qualified Data.Vector.Unboxed as U (Vector, toList, fromList)
+import qualified Data.Vector as V (fromList)
+
+bnn :: Particle -> Double
+bnn xs = -0.5 * (x0 ^ 2 * x1 ^ 2 + x0 ^ 2 + x1 ^ 2 - 8 * x0 - 8 * x1) where
+ [x0, x1] = U.toList xs
+
+ensemble :: Ensemble
+ensemble = V.fromList [
+ U.fromList [negate 1.0, negate 1.0]
+ , U.fromList [negate 1.0, 1.0]
+ , U.fromList [1.0, negate 1.0]
+ , U.fromList [1.0, 1.0]
+ ]
+
+main :: IO ()
+main = withSystemRandom . asGenIO $ mcmc 1000 ensemble bnn
+