package prbnmcn-stats

  1. Overview
  2. Docs

Gen allows to manipulate generative probabilities (ie samplers).

type state

Follows the module type of a sampling-based monad

include Basic_structures.Basic_intf.Monad with type 'a t = (state, 'a) gen and type 'a res = (state, 'a) gen
type 'a t = (state, 'a) gen

'a t is the type of computations of type 'a

type 'a res = (state, 'a) gen

'a res is the outcome of running a computation of type 'a

val return : 'a -> 'a t

return x injects a value x as a computation

val bind : 'a t -> ('a -> 'b t) -> 'b t

Monadic bind

val map : 'a t -> ('a -> 'b) -> 'b t

Functorial map

val run : 'a t -> 'a res

Running a monadic computation

module Infix : sig ... end
val iid : 'a t -> 'a Stdlib.Seq.t t

iid gen transforms a sampler into a sequence sampler.

val float : float -> float t

float bound samples uniformly in 0; bound

val int : int -> int t

int bound samples uniformly in 0; bound-1

val bool : bool t

bool samples a boolean uniformly

val shuffle : 'a array -> 'a array t

shuffle a samples a uniform permutation of a. Uses Fisher-Yates shuffle algorithm.

val uniform : 'a array -> 'a t

uniform elts samples an element of the elts array by sampling an index uniformly.

  • raises Invalid_argument

    if elts has length equal to 0

val bernoulli : float -> bool t

bernoulli alpha samples true with probability alpha.

  • raises Invalid_argument

    if alpha is not in the 0;1 interval.

val geometric : float -> int t

geometric p samples a nonnegative integer according to the geometric law of parameter p.

  • raises Invalid_argument

    if p <= 0 || p > 1

val subsample : n:int -> 'a t -> 'a t

subsample ~n gen samples one out of n samples from gen.

val of_empirical : 'a emp -> 'a t

of_empirical emp samples from emp matching exactly the empirical frequencies.

val exponential : rate:float -> float t

Exponential distribution via inverse CDF.

  • raises Invalid_argument

    if rate <=. 0.0.

val box_muller : mean:float -> std:float -> (float * float) t

Gaussian distribution via Box-Muller transform. Returns a pair of independent gaussian variates with prescribed mean and standard deviation.

  • raises Invalid_argument

    if std <= 0.0

val gaussian : mean:float -> std:float -> float t

Gaussian distribution (wrapper over box-muller transform).

  • raises Invalid_argument

    if std <= 0.0

val poisson : lambda:float -> int t

Poisson distribution via inverse transform. Consider using other methods for large lambda.

  • raises Invalid_argument

    if lambda <= 0.0

val range : range -> float t

Samples uniformly in the given range.

  • raises Invalid_argument

    if range is empty.

val rectangle : min:float array -> max:float array -> float array t

Samples uniformly in the n-dimensional axis-aligned box defined by min and max.

  • raises Invalid_argument

    if Array.length min != Array.length max, if the length of min or max is zero or if there exists an index i such that min.(i) > max.(i).

val gamma : shape:float -> scale:float -> float t

Gamma distribution.

val categorical : ('a * float) array -> 'a t

Categorical distribution. Total mass need not be one. Does not aggregate mass of equal elements.

  • raises Invalid_argument

    if some weights are negative or if the total mass is zero.

val without_replacement : int -> 'a list -> ('a list * 'a list) t

without_replacement n l samples a subset of size n from l without replacement.

  • raises Invalid_argument

    if n > List.length l.

val tup2 : 'a t -> 'b t -> ('a * 'b) t

tup2 g1 g2 samples the component of a tuple independently from g1 and g2.

val tup3 : 'a t -> 'b t -> 'c t -> ('a * 'b * 'c) t

See tup2

val tup4 : 'a t -> 'b t -> 'c t -> 'd t -> ('a * 'b * 'c * 'd) t

See tup2

val tup5 : 'a t -> 'b t -> 'c t -> 'd t -> 'e t -> ('a * 'b * 'c * 'd * 'e) t

See tup2

val tup6 : 'a t -> 'b t -> 'c t -> 'd t -> 'e t -> 'f t -> ('a * 'b * 'c * 'd * 'e * 'f) t

See tup2

val mixture : float array -> (int -> 'b t) -> 'b t

mixture weights gens samples from the convex combination of weights. weights need to be normalized, non-negative floats.

  • raises Invalid_argument

    if mixture is empty or if weights is not normalized.

module Rational : sig ... end