Module Ppl__.Dist

exception Undefined
module Prob : Ppl__.Sigs.Prob

The module used to represent probability, can be switched to use log probs

type prob = Prob.t

A type for which values need to sum to 1 (not an enforced property)

type likelihood = Prob.t

A type for which values don't need to sum to 1 (not an enforced property)

type 'a samples = ('a * prob) list

A set of weighted samples, summing to one

type _ dist = private
| Return : 'a -> 'a dist

distribution with a single value

| Bind : 'a dist * ('a -> 'b dist) -> 'b dist

monadic bind

| Primitive : 'a Ppl.Primitive.t -> 'a dist

primitive exact distribution

| Conditional : ('a -> likelihood) * 'a dist -> 'a dist

variant that defines likelihood model

| Independent : 'a dist * 'b dist -> ('a * 'b) dist

for combining two independent distributions

GADT for representing distributions, private to avoid direct manipulation

Condition Operators

val condition' : ('a -> float) -> 'a dist -> 'a dist

The most general condition operator

val condition : bool -> 'a dist -> 'a dist

Hard conditioning

val score : float -> 'a dist -> 'a dist

Soft conditioning, add a constant score to a trace

val observe : 'a -> 'a Ppl.Primitive.t -> 'b dist -> 'b dist

Soft conditioning for observations from a known distribution

Monad Functions

Monad functions

type 'a t
val return : 'a -> 'a t
val bind : 'a t -> ('a -> 'b t) -> 'b t
val (>>=) : 'a t -> ('a -> 'b t) -> 'b t
val let* : 'a t -> ('a -> 'b t) -> 'b t
val fmap : ('a -> 'b) -> 'a t -> 'b t
val liftM : ('a -> 'b) -> 'a t -> 'b t
val liftM2 : ('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c t
val mapM : ('a -> 'b t) -> 'a list -> 'b list t
val sequence : 'a t list -> 'a list t
val and* : 'a dist -> 'b dist -> ('a * 'b) dist

Primitives

These functions create dist values which correspond to primitive distributions so that they can be used in models.

type 'a primitive
val binomial : int -> float -> int primitive
val normal : float -> float -> float primitive
val categorical : ('a * float) list -> 'a primitive
val discrete_uniform : 'a list -> 'a primitive
val beta : float -> float -> float primitive
val gamma : float -> float -> float primitive
val continuous_uniform : float -> float -> float primitive
val bernoulli : float -> bool dist

Sampling

val sample : 'a dist -> 'a
val sample_n : int -> 'a dist -> 'a array
val sample_with_score : 'a dist -> 'a * likelihood

Prior Distribution

val prior' : 'a dist -> 'a dist
val prior_with_score : 'a dist -> ('a * likelihood) dist
val support : 'a dist -> 'a list
module PplOps : Ppl__.Sigs.Ops with type 'a dist := 'a dist

Common operators for combining distributions