Skip to content

Commit

Permalink
Cleanup (#142)
Browse files Browse the repository at this point in the history
* docs

* docs

* docs

* docs

* inference

* executable docs

* more comments, added BayesianModel

* Remove MaybeT and use ExceptT

* remove vscode and update gitignore

* delete additional changes: Failure

* delete broken files

* update test for enumerator

* tips on inference

* more pipes

* update docs

* update docs

* cleanup SMC.hs

* more cleanup, and explicit imports

* remove Rejection

* update docs

* build docs manually

* insegel theme

* stanford theme

* lint

* lint

* ormulo

* nix ormolu fixes:
git push

* docs

* trying to fix mathjax

* remove empirical

* notebooks

* remove helpers

* formatting

* yaml

* prepare for PR

* address warnings

* review

* more warnings fixed

* less warnings

* update ghc version stated in cabal

* remove warnings

* fix build

* version bump

* remove safe

* fix rmsmc bug you introduced

* fix bug

* linter

* 1980 -> 2022

Co-authored-by: Reuben Cohn-Gordon <reubencohn-gordon@Reubens-MacBook-Air.local>
Co-authored-by: System Administrator <root@Reubens-MacBook-Air.local>
  • Loading branch information
3 people authored Jun 17, 2022
1 parent 8509452 commit 771ce2e
Show file tree
Hide file tree
Showing 112 changed files with 68,061 additions and 16,648 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
.ghc.environment.*
.hpc
.hsenv
.vscode
.stack-work/
cabal-dev
cabal.project.local
Expand Down
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,23 @@

- No unreleased changes so far.

# 0.1.1.2 (2021-06-08)

Clean up of unused functions and broken code

- remove unused functions in `Weighted` and `Population`
- remove broken models in `models`
- explicit imports
- added some global language extensions

# 0.1.1.1 (2021-06-08)

Add documentation

- docs written in markdown
- docs built by sphinx


# 0.1.1.0 (2020-04-08)

- New exported function: `Control.Monad.Bayes.Class` now exports `discrete`.
Expand Down
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
# monad-bayes

[![Hackage](https://img.shields.io/hackage/v/monad-bayes.svg)](https://hackage.haskell.org/package/monad-bayes)
<!-- [![Hackage](https://img.shields.io/hackage/v/monad-bayes.svg)](https://hackage.haskell.org/package/monad-bayes)
[![Stackage](http://stackage.org/package/monad-bayes/badge/lts)](http://stackage.org/lts/package/monad-bayes)
[![Hackage Deps](https://img.shields.io/hackage-deps/v/monad-bayes.svg)](http://packdeps.haskellers.com/reverse/monad-bayes)
[![Build status](https://badge.buildkite.com/147af088063e8619fcf52ecf93fa7dd3353a2e8a252ef8e6ad.svg?branch=master)](https://buildkite.com/tweag-1/monad-bayes)
[![Build status](https://badge.buildkite.com/147af088063e8619fcf52ecf93fa7dd3353a2e8a252ef8e6ad.svg?branch=master)](https://buildkite.com/tweag-1/monad-bayes) -->

A library for **probabilistic programming in Haskell** using probability
monads. The emphasis is on composition of inference algorithms implemented in
terms of monad transformers.
A library for **probabilistic programming in Haskell**. The emphasis is on composition of inference algorithms, and is implemented in terms of monad transformers.

Created by [Adam Scibior][adam-web] ([@adscib][adam-github]), maintained by
[Tweag I/O][tweagio].
See the [documentation](https://monad-bayes.netlify.app/) for a quick-start user guide and a reference overview of how it all works.

Created by [Adam Scibior][adam-web] ([@adscib][adam-github]), documentation by [Reuben][reuben-web], maintained by [Tweag I/O][tweagio].

## Project status

Now that `monad-bayes` has been released on Hackage, we will focus on improving
documentation. In the meantime, see the [`models` folder][models] for examples.

documentation, adding a variety of applications, improving the API, and making inference more easily customizable.
## Background

The basis for the code in this repository is the ICFP 2018 paper [2]. For the
Expand Down Expand Up @@ -49,6 +47,7 @@ Now you can use `stack build`, `stack test` and `stack ghci`.

[adam-github]: https://github.com/adscib
[adam-web]: https://www.cs.ubc.ca/~ascibior/
[reuben-web]: https://reubencohngordon.com/
[haskell2015-doi]: https://doi.org/10.1145/2804302.2804317
[haskell2015-tag]: https://github.com/tweag/monad-bayes/tree/haskell2015
[icfp2018-doi]: https://doi.org/10.1145/3236778
Expand Down
18 changes: 9 additions & 9 deletions benchmark/SSM.hs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
module Main where

import Control.Monad.Bayes.Inference.PMMH as PMMH
import Control.Monad.Bayes.Inference.RMSMC
import Control.Monad.Bayes.Inference.SMC
import Control.Monad.Bayes.Inference.SMC2 as SMC2
import Control.Monad.Bayes.Population
import Control.Monad.Bayes.Sampler
import Control.Monad.Bayes.Weighted
import Control.Monad.IO.Class
import NonlinearSSM
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.SMC2 as SMC2 (smc2)
import Control.Monad.Bayes.Population (runPopulation)
import Control.Monad.Bayes.Sampler (sampleIO)
import Control.Monad.Bayes.Weighted (prior)
import Control.Monad.IO.Class (MonadIO (liftIO))
import NonlinearSSM (generateData, model, param)

main :: IO ()
main = sampleIO $ do
Expand Down
13 changes: 8 additions & 5 deletions benchmark/Single.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE ImportQualifiedPost #-}

import Control.Monad.Bayes.Class
import Control.Monad.Bayes.Inference.RMSMC
import Control.Monad.Bayes.Inference.SMC
Expand All @@ -6,14 +9,14 @@ import Control.Monad.Bayes.Sampler
import Control.Monad.Bayes.Traced
import Control.Monad.Bayes.Weighted
import Data.Time
import qualified HMM
import qualified LDA
import qualified LogReg
import HMM qualified
import LDA qualified
import LogReg qualified
import Options.Applicative
import System.Random.MWC (createSystemRandom)

data Model = LR Int | HMM Int | LDA (Int, Int)
deriving (Show, Read)
deriving stock (Show, Read)

parseModel :: String -> Maybe Model
parseModel s =
Expand All @@ -36,7 +39,7 @@ getModel model = (size model, program model)
program (LDA (d, w)) = show <$> synthesize (LDA.syntheticData d w) LDA.lda

data Alg = SMC | MH | RMSMC
deriving (Read, Show)
deriving stock (Read, Show)

runAlg :: Model -> Alg -> SamplerIO String
runAlg model alg =
Expand Down
55 changes: 35 additions & 20 deletions benchmark/Speed.hs
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE ImportQualifiedPost #-}
{-# OPTIONS_GHC -Wall #-}

module Main (main) where

import Control.Monad.Bayes.Class
import Control.Monad.Bayes.Inference.RMSMC
import Control.Monad.Bayes.Inference.SMC
import Control.Monad.Bayes.Population
import Control.Monad.Bayes.Sampler
import Control.Monad.Bayes.Traced
import Control.Monad.Bayes.Weighted
import Control.Monad.Bayes.Class (MonadInfer)
import Control.Monad.Bayes.Inference.RMSMC (rmsmcLocal)
import Control.Monad.Bayes.Inference.SMC (smcSystematic)
import Control.Monad.Bayes.Population (runPopulation)
import Control.Monad.Bayes.Sampler (SamplerIO, sampleIOwith)
import Control.Monad.Bayes.Traced (mh)
import Control.Monad.Bayes.Weighted (prior)
import Criterion.Main
import Criterion.Types
import qualified HMM
import qualified LDA
import qualified LogReg
( Benchmark,
Benchmarkable,
bench,
defaultConfig,
defaultMainWith,
nfIO,
)
import Criterion.Types (Config (csvFile, rawDataFile))
import Data.Functor (void)
import HMM qualified
import LDA qualified
import LogReg qualified
import System.Process.Typed (runProcess)
import System.Random.MWC (GenIO, createSystemRandom)

-- | Environment to execute benchmarks in.
newtype Env = Env {rng :: GenIO}

data ProbProgSys = MonadBayes
deriving (Show)
deriving stock (Show)

data Model = LR [(Double, Bool)] | HMM [Double] | LDA [[String]]

Expand Down Expand Up @@ -59,11 +70,11 @@ prepareBenchmark e MonadBayes model alg =
bench (show MonadBayes ++ sep ++ show model ++ sep ++ show alg) $
prepareBenchmarkable (rng e) MonadBayes model alg
where
sep = "_"
sep = "_" :: String

-- | Checks if the requested benchmark is implemented.
supported :: (ProbProgSys, Model, Alg) -> Bool
supported (_, _, RMSMC _ _) = False
supported (_, _, RMSMC _ _) = True
supported _ = True

systems :: [ProbProgSys]
Expand All @@ -74,9 +85,9 @@ systems =
lengthBenchmarks :: Env -> [(Double, Bool)] -> [Double] -> [[String]] -> [Benchmark]
lengthBenchmarks e lrData hmmData ldaData = benchmarks
where
lrLengths = 10 : map (* 100) [1 .. 10]
hmmLengths = 10 : map (* 100) [1 .. 10]
ldaLengths = 5 : map (* 50) [1 .. 10]
lrLengths = 10 : map (* 100) [1 :: Int .. 10]
hmmLengths = 10 : map (* 100) [1 :: Int .. 10]
ldaLengths = 5 : map (* 50) [1 :: Int .. 10]
models =
map (LR . (`take` lrData)) lrLengths
++ map (HMM . (`take` hmmData)) hmmLengths
Expand All @@ -98,9 +109,9 @@ lengthBenchmarks e lrData hmmData ldaData = benchmarks
samplesBenchmarks :: Env -> [(Double, Bool)] -> [Double] -> [[String]] -> [Benchmark]
samplesBenchmarks e lrData hmmData ldaData = benchmarks
where
lrLengths = [50]
hmmLengths = [20]
ldaLengths = [10]
lrLengths = [50 :: Int]
hmmLengths = [20 :: Int]
ldaLengths = [10 :: Int]
models =
map (LR . (`take` lrData)) lrLengths
++ map (HMM . (`take` hmmData)) hmmLengths
Expand All @@ -120,6 +131,9 @@ samplesBenchmarks e lrData hmmData ldaData = benchmarks
main :: IO ()
main = do
g <- createSystemRandom
writeFile "speed-length.csv" ""
writeFile "speed-samples.csv" ""
writeFile "raw.dat" ""
let e = Env g
lrData <- sampleIOwith (LogReg.syntheticData 1000) g
hmmData <- sampleIOwith (HMM.syntheticData 1000) g
Expand All @@ -128,3 +142,4 @@ main = do
defaultMainWith configLength (lengthBenchmarks e lrData hmmData ldaData)
let configSamples = defaultConfig {csvFile = Just "speed-samples.csv", rawDataFile = Just "raw.dat"}
defaultMainWith configSamples (samplesBenchmarks e lrData hmmData ldaData)
void $ runProcess "python plots.py"
Binary file modified docs/build/doctrees/environment.pickle
Binary file not shown.
Binary file modified docs/build/doctrees/index.doctree
Binary file not shown.
Binary file modified docs/build/doctrees/probprog.doctree
Binary file not shown.
Binary file modified docs/build/doctrees/usage.doctree
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/build/html/.buildinfo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: ab9c3aee1cef2c7b4cb6a54bc1a416ce
config: acd02203342909cc9f295870ee4d239a
tags: 645f666f9bcd5a90fca523b33c5a78b7
Binary file removed docs/build/html/.doctrees/environment.pickle
Binary file not shown.
Binary file removed docs/build/html/.doctrees/index 2.doctree
Binary file not shown.
Binary file removed docs/build/html/.doctrees/index.doctree
Binary file not shown.
Binary file removed docs/build/html/.doctrees/probprog.doctree
Binary file not shown.
Binary file removed docs/build/html/.doctrees/usage.doctree
Binary file not shown.
1 change: 0 additions & 1 deletion docs/build/html/_sources/probprog.md.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# User Guide


Probabilistic programming is all about being able to write probabilistic models as programs. For instance, here is a Bayesian linear regression model:

```haskell
Expand Down
Loading

0 comments on commit 771ce2e

Please sign in to comment.