-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generalize from double #171
Closed
Closed
Changes from all commits
Commits
Show all changes
158 commits
Select commit
Hold shift + click to select a range
3263e4b
analytic
9b79de6
docs
c4ae117
docs
9f3e49b
docs
e750b1e
docs
99d4c04
inference
reubenharry 6478c0a
executable docs
reubenharry 97517a2
more comments, added BayesianModel
reubenharry 4577135
Remove MaybeT and use ExceptT
reubenharry e9b7158
remove vscode and update gitignore
reubenharry 6c1214a
delete additional changes: Failure
reubenharry 1bbdb2d
delete broken files
reubenharry 003aca4
update test for enumerator
reubenharry 31d3dd1
update models
reubenharry a48d806
tips on inference
reubenharry cb100df
density
reubenharry 530f4d9
analytic
reubenharry 4d2a447
analytic
reubenharry a057100
more pipes
reubenharry 344fb10
update docs
reubenharry 91f968b
linear outliers as in Gen tutorial
reubenharry 0909ea9
update docs
reubenharry 4ef4ccd
cleanup SMC.hs
reubenharry aa18cfc
more cleanup, and explicit imports
reubenharry 10e464e
remove Rejection
reubenharry 42a8a40
cleanup
reubenharry 753e72a
enumerate
reubenharry e87ab45
binning
reubenharry 7787b2a
comment
reubenharry ae590fc
nested inference example
reubenharry 105a63f
found bug in Gamma
reubenharry a8d9a17
debugging
reubenharry f63cd79
add conjugacy tests
reubenharry 5ea0f16
working branch
reubenharry b446c47
tried symbolic
reubenharry 00f087a
no symbolic
reubenharry dc065ea
Merge branch 'analytic' into models
reubenharry 84633be
remove reflection
reubenharry 8e899cd
Merge branch 'analytic' into models
reubenharry 24f6343
midway: need to finish hmm and enumerator:
reubenharry 5bd1837
update docs
reubenharry b08e9dd
DP mixture: remove
reubenharry 5875b43
build docs manually
reubenharry 656ff50
insegel theme
reubenharry e49115e
stanford theme
reubenharry e8236f0
lint
reubenharry aab90b0
lint
reubenharry 84dd4f0
ormulo
072137a
nix ormolu fixes:
3bce561
merge main
reubenharry 803327b
docs
reubenharry 01512ec
trying to fix mathjax
reubenharry 54814c1
Merge branch 'master' into docs
reubenharry 69173bb
merge docs
reubenharry f3f53c6
remove empirical
reubenharry ec3fe94
merge docs
reubenharry af06b06
notebooks
reubenharry 810aad9
Merge branch 'notebook' into histogram
reubenharry aab8095
notebooks: sampling
reubenharry 8d143d2
merge cleanup
reubenharry 0b94b79
merge notebook
reubenharry 5287df4
cleaning up notebooks
reubenharry 5dddb4f
remove helpers
reubenharry b829b03
Merge branch 'cleanup' into notebook
reubenharry a6d29da
when
reubenharry e7652d7
no helpers
reubenharry 62319ee
models: lts
reubenharry 9cff121
models: lts
reubenharry 1cf551e
SMC notebook
reubenharry c2988d6
merged
reubenharry fd97ec3
weighted sampling
reubenharry 2e6dd30
formatting
reubenharry 70426f6
Merge branch 'notebook' into cleanup
reubenharry 9f887b3
working on analytic
reubenharry 6d36c1c
test enumerator
reubenharry 6d4839c
discovered a bug in Integrator
reubenharry 13cc36f
first attempt to fix normalization bug
reubenharry e19b2db
bug seems to be fixed
reubenharry bf7bdbf
update tests
reubenharry 96ea8df
working tests: normalNormal goes awry if observations are huge
reubenharry 328a16f
cleanup
reubenharry f378401
Bayesian in class, and remove LinearWithOutliers
reubenharry 4b3e4e5
model updates
reubenharry 3e21cff
yaml
77df67d
prepare for PR
93cf699
address warnings
9782c8c
review
4d8e98c
more warnings fixed
ea6cb50
merged
reubenharry 51268c7
less warnings
9978861
update ghc version stated in cabal
reubenharry 1aef717
Merge branch 'cleanup' of github.com:tweag/monad-bayes into cleanup
reubenharry 8e32fbf
remove warnings
16f5e11
merge main
6c78b06
fix build
7c69878
version bump
8174b55
merged but tests fail
0fc99be
remove safe
d7011b5
Merge branch 'cleanup' into histogram
b293eca
fix merge
54b0165
fix rmsmc bug you introduced
reubenharry cb6cc06
integrator as MonadInfer
reubenharry 3777955
updates
reubenharry 165bd24
updates
reubenharry 9fd5c00
updates
reubenharry e2ee3a9
fix the integrator
reubenharry b418558
fix the normalization of the integrator
reubenharry 59ef114
merged
reubenharry fe29850
inference
reubenharry ae07cda
rope in analyticT
reubenharry 7a1f775
remove integratorT
3e388f4
nix notebooks
1dad9f5
notebooks
fdb0177
rmsmc
0a2dd21
hoistFirst bug again
44d3363
hoistFirst bug again
935ad8f
diagrams
277cb63
fp notebook
021aa60
remove integratorT
757d8cc
Merge branch 'cleanup' into histogram
ea01eaa
Merge branch 'histogram' into analytic
463b12f
changelog and version bump
96d6523
notebooks
d1c6a19
cleanup
9ec7a05
got the classes working better
c765c76
got the classes working better
3883adc
got the classes working better
6e643ac
struggling with ad
99575ec
first working example of marginalization
c0cae57
renaming
3b3eb3d
continue cleanup
a71dabe
tests: not yet integrated in
343acde
tests: integrated in
49b72a7
bayesian pmmh
b4baf7b
switch over to new smc
bb4304c
switch over to new smc
d6beee0
improve resampleGeneric sum
78a0d52
independent in Class
b9fa06c
make clean
reubenharry 8c5e533
merge
reubenharry 9f414a3
fix tests
reubenharry f096bf0
fix tests
reubenharry 22c20b8
fix tests
reubenharry 4849cb7
fix tests
reubenharry bb82c1b
pmmh
reubenharry 5453626
withParticles
reubenharry 4890596
withParticles
reubenharry 4428664
erf
reubenharry 0f8bd34
update nix
reubenharry 72c5a79
cabal format
reubenharry d64962c
update nix
reubenharry 7245f09
fix build
reubenharry 86a72ef
merge sampler changes, fix changelog
reubenharry 409b14d
bump changelog and version. bump ghc version to 9.2.3
reubenharry f99ed20
update docs and change mcmc so unweighted is not needed
reubenharry 95bbbe7
comment out HD
reubenharry 8a77047
some merging
reubenharry ede131e
merge
reubenharry File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
src/data | ||
_cache | ||
docs/build | ||
*.csv | ||
|
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 |
---|---|---|
@@ -1,35 +1,43 @@ | ||
module Main where | ||
|
||
import Control.Monad.Bayes.Inference.MCMC | ||
import Control.Monad.Bayes.Inference.PMMH as PMMH (pmmh) | ||
import Control.Monad.Bayes.Inference.RMSMC (rmsmcLocal) | ||
import Control.Monad.Bayes.Inference.SMC (smcMultinomial) | ||
import Control.Monad.Bayes.Inference.RMSMC (rmsmcDynamic) | ||
import Control.Monad.Bayes.Inference.SMC | ||
import Control.Monad.Bayes.Inference.SMC2 as SMC2 (smc2) | ||
import Control.Monad.Bayes.Population (runPopulation) | ||
import Control.Monad.Bayes.Sampler (sampleWith) | ||
import Control.Monad.Bayes.Weighted (prior) | ||
import Control.Monad.Bayes.Population | ||
import Control.Monad.Bayes.Population (population, resampleMultinomial, runPopulation) | ||
import Control.Monad.Bayes.Sampler (sampleIO, sampleIOfixed, sampleWith) | ||
import Control.Monad.Bayes.Weighted (unweighted) | ||
import Control.Monad.IO.Class (MonadIO (liftIO)) | ||
import NonlinearSSM (generateData, model, param) | ||
import System.Random.Stateful (mkStdGen, newIOGenM) | ||
|
||
main :: IO () | ||
main = do | ||
(smcRes, smcrmRes, pmmhRes, smc2Res) <- | ||
newIOGenM (mkStdGen 1729) | ||
>>= ( sampleWith $ do | ||
let t = 5 | ||
dat <- generateData t | ||
let ys = map snd dat | ||
smcRes <- runPopulation $ smcMultinomial t 10 (param >>= model ys) | ||
smcrmRes <- runPopulation $ rmsmcLocal t 10 10 (param >>= model ys) | ||
pmmhRes <- prior $ pmmh 2 t 3 param (model ys) | ||
smc2Res <- runPopulation $ smc2 t 3 2 1 param (model ys) | ||
return (smcRes, smcrmRes, pmmhRes, smc2Res) | ||
) | ||
print "SMC" | ||
print $ show smcRes | ||
print "RM-SMC" | ||
print $ show smcrmRes | ||
print "PMMH" | ||
print $ show pmmhRes | ||
print "SMC2" | ||
print $ show smc2Res | ||
main = sampleIOfixed $ do | ||
let t = 5 | ||
dat <- generateData t | ||
let ys = map snd dat | ||
liftIO $ print "SMC" | ||
smcRes <- population $ smc SMCConfig {numSteps = t, numParticles = 10, resampler = resampleMultinomial} (param >>= model ys) | ||
liftIO $ print $ show smcRes | ||
liftIO $ print "RM-SMC" | ||
smcrmRes <- | ||
population $ | ||
rmsmcDynamic | ||
MCMCConfig {numMCMCSteps = 10, numBurnIn = 0, proposal = SingleSiteMH} | ||
SMCConfig {numSteps = t, numParticles = 10, resampler = resampleSystematic} | ||
(param >>= model ys) | ||
liftIO $ print $ show smcrmRes | ||
liftIO $ print "PMMH" | ||
pmmhRes <- | ||
unweighted $ | ||
pmmh | ||
MCMCConfig {numMCMCSteps = 2, numBurnIn = 0, proposal = SingleSiteMH} | ||
SMCConfig {numSteps = t, numParticles = 3, resampler = resampleSystematic} | ||
param | ||
(model ys) | ||
liftIO $ print $ show pmmhRes | ||
liftIO $ print "SMC2" | ||
smc2Res <- population $ smc2 t 3 2 1 param (model ys) | ||
liftIO $ print $ show smc2Res |
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 |
---|---|---|
|
@@ -2,9 +2,11 @@ | |
{-# LANGUAGE ImportQualifiedPost #-} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is everything commented out? |
||
|
||
import Control.Monad.Bayes.Class | ||
import Control.Monad.Bayes.Inference.MCMC (MCMCConfig (..), Proposal (SingleSiteMH)) | ||
import Control.Monad.Bayes.Inference.RMSMC | ||
import Control.Monad.Bayes.Inference.SMC | ||
import Control.Monad.Bayes.Population | ||
import Control.Monad.Bayes.Population (population) | ||
import Control.Monad.Bayes.Sampler | ||
import Control.Monad.Bayes.Traced | ||
import Control.Monad.Bayes.Weighted | ||
|
@@ -16,75 +18,75 @@ import LogReg qualified | |
import Options.Applicative | ||
import System.Random.MWC (GenIO, createSystemRandom) | ||
|
||
data Model = LR Int | HMM Int | LDA (Int, Int) | ||
deriving stock (Show, Read) | ||
-- data Model = LR Int | HMM Int | LDA (Int, Int) | ||
-- deriving stock (Show, Read) | ||
|
||
parseModel :: String -> Maybe Model | ||
parseModel s = | ||
case s of | ||
'L' : 'R' : n -> Just $ LR (read n) | ||
'H' : 'M' : 'M' : n -> Just $ HMM (read n) | ||
'L' : 'D' : 'A' : n -> Just $ LDA (5, read n) | ||
_ -> Nothing | ||
-- parseModel :: String -> Maybe Model | ||
-- parseModel s = | ||
-- case s of | ||
-- 'L' : 'R' : n -> Just $ LR (read n) | ||
-- 'H' : 'M' : 'M' : n -> Just $ HMM (read n) | ||
-- 'L' : 'D' : 'A' : n -> Just $ LDA (5, read n) | ||
-- _ -> Nothing | ||
|
||
getModel :: MonadInfer m => Model -> (Int, m String) | ||
getModel model = (size model, program model) | ||
where | ||
size (LR n) = n | ||
size (HMM n) = n | ||
size (LDA (d, w)) = d * w | ||
program (LR n) = show <$> (LogReg.logisticRegression (runST $ sampleSTfixed (LogReg.syntheticData n))) | ||
program (HMM n) = show <$> (HMM.hmm (runST $ sampleSTfixed (HMM.syntheticData n))) | ||
program (LDA (d, w)) = show <$> (LDA.lda (runST $ sampleSTfixed (LDA.syntheticData d w))) | ||
-- getModel :: MonadInfer m => Model -> (Int, m String) | ||
-- getModel model = (size model, program model) | ||
-- where | ||
-- size (LR n) = n | ||
-- size (HMM n) = n | ||
-- size (LDA (d, w)) = d * w | ||
-- program (LR n) = show <$> (LogReg.logisticRegression (runST $ sampleSTfixed (LogReg.syntheticData n))) | ||
-- program (HMM n) = show <$> (HMM.hmm (runST $ sampleSTfixed (HMM.syntheticData n))) | ||
-- program (LDA (d, w)) = show <$> (LDA.lda (runST $ sampleSTfixed (LDA.syntheticData d w))) | ||
|
||
data Alg = SMC | MH | RMSMC | ||
deriving stock (Read, Show) | ||
-- -- data Alg = SMC | MH | RMSMC | ||
-- -- deriving stock (Read, Show) | ||
|
||
runAlg :: Model -> Alg -> Sampler GenIO IO String | ||
runAlg model alg = | ||
case alg of | ||
SMC -> | ||
let n = 100 | ||
(k, m) = getModel model | ||
in show <$> runPopulation (smcSystematic k n m) | ||
MH -> | ||
let t = 100 | ||
(_, m) = getModel model | ||
in show <$> prior (mh t m) | ||
RMSMC -> | ||
let n = 10 | ||
t = 1 | ||
(k, m) = getModel model | ||
in show <$> runPopulation (rmsmcBasic k n t m) | ||
-- runAlg :: Model -> Alg -> Sampler GenIO IO String | ||
-- runAlg model alg = | ||
-- case alg of | ||
-- SMC -> | ||
-- let n = 100 | ||
-- (k, m) = getModel model | ||
-- in show <$> population (smc SMCConfig {numSteps = k, numParticles = n, resampler = resampleSystematic} m) | ||
-- MH -> | ||
-- let t = 100 | ||
-- (_, m) = getModel model | ||
-- in show <$> unweighted (mh t m) | ||
-- RMSMC -> | ||
-- let n = 10 | ||
-- t = 1 | ||
-- (k, m) = getModel model | ||
-- in show <$> population (rmsmcBasic MCMCConfig {numMCMCSteps = t, numBurnIn = 0, proposal = SingleSiteMH} (SMCConfig {numSteps = k, numParticles = n, resampler = resampleSystematic}) m) | ||
|
||
infer :: Model -> Alg -> IO () | ||
infer model alg = do | ||
g <- createSystemRandom | ||
x <- sampleWith (runAlg model alg) g | ||
print x | ||
-- infer :: Model -> Alg -> IO () | ||
-- infer model alg = do | ||
-- g <- createSystemRandom | ||
-- x <- sampleWith (runAlg model alg) g | ||
-- print x | ||
|
||
opts :: ParserInfo (Model, Alg) | ||
opts = flip info fullDesc $ liftA2 (,) model alg | ||
where | ||
model = | ||
option | ||
(maybeReader parseModel) | ||
( long "model" | ||
<> short 'm' | ||
<> help "Model" | ||
) | ||
alg = | ||
option | ||
auto | ||
( long "alg" | ||
<> short 'a' | ||
<> help "Inference algorithm" | ||
) | ||
-- -- opts :: ParserInfo (Model, Alg) | ||
-- -- opts = flip info fullDesc $ liftA2 (,) model alg | ||
-- -- where | ||
-- -- model = | ||
-- -- option | ||
-- -- (maybeReader parseModel) | ||
-- -- ( long "model" | ||
-- -- <> short 'm' | ||
-- -- <> help "Model" | ||
-- -- ) | ||
-- -- alg = | ||
-- -- option | ||
-- -- auto | ||
-- -- ( long "alg" | ||
-- -- <> short 'a' | ||
-- -- <> help "Inference algorithm" | ||
-- -- ) | ||
|
||
main :: IO () | ||
main = do | ||
(model, alg) <- execParser opts | ||
startTime <- getCurrentTime | ||
infer model alg | ||
endTime <- getCurrentTime | ||
print (diffUTCTime endTime startTime) | ||
-- -- main :: IO () | ||
-- -- main = do | ||
-- -- (model, alg) <- execParser opts | ||
-- -- startTime <- getCurrentTime | ||
-- -- infer model alg | ||
-- -- endTime <- getCurrentTime | ||
-- -- print (diffUTCTime endTime startTime) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we had already made the changes to use a record to contain the various options?