-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: finished (1st draft) of presentation
still need to do examples to step through... this will be a separate local repo
- Loading branch information
1 parent
746ccda
commit f5c51bf
Showing
6 changed files
with
267 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
-- | Metropolis Sampling | ||
|
||
{-# LANGUAGE FunctionalDependencies #-} | ||
{-# LANGUAGE RecordWildCards #-} | ||
{-# LANGUAGE DuplicateRecordFields #-} | ||
|
||
module Metropolis where | ||
|
||
import Sampler | ||
import Distributions | ||
|
||
mh :: MHKernel k a => Int -> k -> a -> Sampler [a] | ||
mh 0 _ _ = return [] | ||
mh n k x_0 = do | ||
x_1 <- k `perturb` x_0 | ||
a <- accepts k x_0 x_1 | ||
if a | ||
then (x_1:) <$> mh (n-1) k x_1 | ||
else (x_0:) <$> mh (n-1) k x_0 | ||
|
||
class MHKernel k a | k -> a where | ||
perturb :: k -> a -> Sampler a | ||
accepts :: k -> a -> a -> Sampler Bool | ||
|
||
data MHABC θ ω = MHABC | ||
{ observations :: ω | ||
, model :: θ -> Sampler ω | ||
, prior :: θ -> Double -- ^ density | ||
, transition :: θ -> Sampler θ -- ^ assumed symmetrical | ||
, distance :: ω -> ω -> Double | ||
, tolerance :: Double | ||
} | ||
|
||
instance MHKernel (MHABC θ ω) θ where | ||
perturb :: MHABC θ ω -> θ -> Sampler θ | ||
perturb MHABC{..} = transition | ||
|
||
accepts :: MHABC θ ω -> θ -> θ -> Sampler Bool | ||
accepts MHABC{..} θ θ' = do | ||
x <- model θ' | ||
if distance x observations <= tolerance | ||
then bernoulli $ min 1 (prior θ' / prior θ) | ||
else return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/env sh | ||
|
||
case ${1} in | ||
approxWeibull|weibull) | ||
data=$(echo "weibull" | stack runhaskell Examples.hs); | ||
python -c "import matplotlib.pyplot as plt; plt.hist(${data}, range=(-1, 8), bins=35); plt.show();" | ||
;; | ||
abcgk|gk) | ||
data=$(echo "gk" | stack runhaskell Examples.hs); | ||
datas=( $data ); | ||
g=${datas[0]}; | ||
k=${datas[1]}; | ||
python -c "import matplotlib.pyplot as plt; plt.hist(${g}, range=(-2, 2), bins=35, alpha=0.8); plt.hist(${k}, range=(-2, 2), bins=35, alpha=0.8); plt.show()"; | ||
;; | ||
*) echo "wrong arg" ;; | ||
esac |
Oops, something went wrong.