Module Ppl.Dist
Module used for defining probabilistic models
Contains a type dist which is used to represent probabilistic models.
module Prob : Ppl__.Sigs.ProbThe module used to represent probability, can be switched to use log probs
type prob= Prob.tA type for which values need to sum to 1 (not an enforced property)
type likelihood= Prob.tA type for which values don't need to sum to 1 (not an enforced property)
type 'a samples= ('a * prob) listA set of weighted samples, summing to one
type _ dist= private|Return : 'a -> 'a distdistribution with a single value
|Bind : 'a dist * ('a -> 'b dist) -> 'b distmonadic bind
|Primitive : 'a Primitive.t -> 'a distprimitive exact distribution
|Conditional : ('a -> likelihood) * 'a dist -> 'a distvariant that defines likelihood model
|Independent : 'a dist * 'b dist -> ('a * 'b) distfor combining two independent distributions
GADT for representing distributions, private to avoid direct manipulation
Condition Operators
val observe : 'a -> 'a Primitive.t -> 'b dist -> 'b distSoft conditioning for observations from a known distribution
Monad Functions
Monad functions
val return : 'a -> 'a tval bind : 'a t -> ('a -> 'b t) -> 'b tval (>>=) : 'a t -> ('a -> 'b t) -> 'b tval let* : 'a t -> ('a -> 'b t) -> 'b tval fmap : ('a -> 'b) -> 'a t -> 'b tval liftM : ('a -> 'b) -> 'a t -> 'b tval liftM2 : ('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c tval mapM : ('a -> 'b t) -> 'a list -> 'b list tval sequence : 'a t list -> 'a list t
Primitives
These functions create dist values which correspond to primitive distributions so that they can be used in models.
val binomial : int -> float -> int primitiveval normal : float -> float -> float primitiveval categorical : ('a * float) list -> 'a primitiveval discrete_uniform : 'a list -> 'a primitiveval beta : float -> float -> float primitiveval gamma : float -> float -> float primitiveval continuous_uniform : float -> float -> float primitive
val bernoulli : float -> bool dist
Sampling
val sample : 'a dist -> 'aval sample_n : int -> 'a dist -> 'a arrayval sample_with_score : 'a dist -> 'a * likelihood
Prior Distribution
val prior_with_score : 'a dist -> ('a * likelihood) distval support : 'a dist -> 'a list
module PplOps : Ppl__.Sigs.Ops with type 'a dist := 'a distCommon operators for combining distributions