probly

Types

Represents the outcome of a probabilistic event as a collection of all possible values, tagged with their likelihood.

pub type Dist(a) =
  List(#(a, Prob))

Match an entry in a Dist to a given value of type a.

pub type Event(a) =
  fn(a) -> Bool

The probability of an event occuring. Within [0, 1].

pub type Prob =
  Float

Functions that “spread” values across distributions by assigning them with probabilities. Examples include uniform and binomial.

pub type Spread(a) =
  fn(List(a)) -> Dist(a)

Functions

pub fn combine_dist(
  dist1: List(#(a, Float)),
  dist2: List(#(b, Float)),
) -> List(#(#(a, b), Float))

Combine distributions, assuming independence.

pub fn combine_dist_normalized(
  dist1: List(#(a, Float)),
  dist2: List(#(b, Float)),
) -> List(#(#(a, b), Float))

Normalize the combinination two Dists.

pub fn normalize(dist: List(#(a, Float))) -> List(#(a, Float))

Merge duplicates in a distribution by summing probabilities. “normalize” is a bit overloaded, this function does not ensure that the sum of all probabilities across a Dist is 1.

pub fn probability_of_event(
  event: fn(a) -> Bool,
  dist: List(#(a, Float)),
) -> Float

Retrieve the probability of an Event within a Dist occuring.

Search Document