packages feed

prob-fx 0.1.0.0 → 0.1.0.1

raw patch · 4 files changed

+11/−11 lines, 4 files

Files

README.md view
@@ -1,7 +1,7 @@ ## ProbFX  #### Prelude-ProbFX is a library for probabilistic programming using algebraic effects that implements the paper [**Modular Probabilistic Models via Algebraic Effects**](https://github.com/min-nguyen/prob-fx/blob/master/paper.pdf) -- this paper provides a comprehensive motivation and walkthrough of this library. To have a more interative and visual play-around with ProbFX, please see https://github.com/min-nguyen/prob-fx: this corresponds parts of the paper to the implementation, and also provides an executable version of ProbFX as a script!+ProbFX is a library for probabilistic programming using algebraic effects that implements the paper [**Modular Probabilistic Models via Algebraic Effects**](https://github.com/min-nguyen/prob-fx/blob/master/paper.pdf) -- this paper provides a comprehensive motivation and walkthrough of this library. To have a more interactive and visual play-around with ProbFX, please see https://github.com/min-nguyen/prob-fx: this corresponds parts of the paper to the implementation, and also provides an executable version of ProbFX as a script!  #### Description ProbFx is a PPL that places emphasis on being able to define modular and reusable probabilistic models, where the decision to `sample` or `observe` against a random variable or distribution of a model is delayed until the point of execution; this allows a model to be defined just *once* and then reused for a variety of applications. We also implement a compositional approach towards model execution (inference) by using effect handlers. 
prob-fx.cabal view
@@ -1,6 +1,6 @@ cabal-version:       3.0 name:                prob-fx-version:             0.1.0.0+version:             0.1.0.1 license:             BSD-3-Clause license-file:        LICENSE.md copyright:           2022 Minh Nguyen
src/Model.hs view
@@ -183,7 +183,7 @@ normal mu sigma field = Model $ do   let tag = Just $ varToStr field   maybe_y <- ask @env field-  call (Dist (Normal mu sigma) maybe_y tag)+  call (Dist (NormalDist mu sigma) maybe_y tag)  normal' ::    -- | Mean@@ -192,7 +192,7 @@   -> Double    -> Model env es Double normal' mu sigma = Model $ do-  call (Dist (Normal mu sigma) Nothing Nothing)+  call (Dist (NormalDist mu sigma) Nothing Nothing)  halfNormal :: forall env es x. Observable env x Double =>       Double 
src/PrimDist.hs view
@@ -99,7 +99,7 @@     :: Double           -- ^ Shape k     -> Double           -- ^ Scale θ     -> PrimDist Double-  Normal        +  NormalDist           :: Double           -- ^ Mean     -> Double           -- ^ Standard deviation     -> PrimDist Double@@ -115,7 +115,7 @@     -> PrimDist Double    instance Eq (PrimDist a) where-  (==) (Normal m s) (Normal m' s') = m == m' && s == s'+  (==) (NormalDist m s) (NormalDist m' s') = m == m' && s == s'   (==) (CauchyDist m s) (CauchyDist m' s') = m == m' && s == s'   (==) (HalfCauchyDist s) (HalfCauchyDist s') = s == s'   (==) (HalfNormalDist s) (HalfNormalDist s') = s == s'@@ -137,8 +137,8 @@    "CauchyDist(" ++ show mu ++ ", " ++ show sigma ++ ", " ++ ")"   show (HalfCauchyDist sigma) =    "HalfCauchyDist(" ++ show sigma ++ ", " ++ ")"-  show (Normal mu sigma) =-   "Normal(" ++ show mu ++ ", " ++ show sigma ++ ", " ++ ")"+  show (NormalDist mu sigma) =+   "NormalDist(" ++ show mu ++ ", " ++ show sigma ++ ", " ++ ")"   show (HalfNormalDist sigma) =    "HalfNormalDist(" ++ show sigma ++ ", " ++ ")"   show (BernoulliDist p) =@@ -180,7 +180,7 @@ primDistPrf d = case d of   HalfCauchyDist {} -> IsPrimVal   CauchyDist {} -> IsPrimVal-  Normal {} -> IsPrimVal+  NormalDist {} -> IsPrimVal   HalfNormalDist  {} -> IsPrimVal   UniformDist  {} -> IsPrimVal   DiscrUniformDist {} -> IsPrimVal@@ -211,7 +211,7 @@   createSampler (sampleCauchy μ σ) sample (HalfNormalDist σ )  =   createSampler (sampleNormal 0 σ) >>= pure . abs-sample (Normal μ σ )  =+sample (NormalDist μ σ )  =   createSampler (sampleNormal μ σ) sample (UniformDist min max )  =   createSampler (sampleUniform min max)@@ -258,7 +258,7 @@ prob (HalfNormalDist σ) y   = if y < 0 then 0 else             2 * density (normalDistr 0 σ) y-prob (Normal μ σ) y+prob (NormalDist μ σ) y   = density (normalDistr μ σ) y prob (UniformDist min max) y   = density (uniformDistr min max) y