package prbnmcn-stats

  1. Overview
  2. Docs

Q-valued finitely supported distributions.

include Stats_intf.Fin_dist with type r = Q.t and type state = Stdlib.Random.State.t
type state = Stdlib.Random.State.t
type r = Q.t
type 'a prb = ('a, r) Stats_intf.fin_prb

The type of finite probability measures with domain 'a and range r.

type 'a mes = ('a, r) Stats_intf.fin_mes

The type of finite measures with domain 'a and range r.

Constructing r-valued finitely supported functions.

val of_fun : int -> (int -> r) -> (int, r) Stats_intf.fin_fun

from_fun len f constructs a finite function with support 0; ...; len-1.

  • raises Invalid_argument

    if len < 0

val of_array : r array -> (int, r) Stats_intf.fin_fun

from_array a returns a finite function wrapping the array a.

val of_assoc : (module Stdlib.Hashtbl.S with type key = 'k) -> ('k * r) array -> ('k, r) Stats_intf.fin_fun

from_assoc h a returns a finite function constructed from the bindings in a. The finite function is backed by a hash table whose implementation is given through the first class module h. The behaviour of the function if elements in the support appear more than once is unspecified.

Constructing measures and probabilities

val measure : ('a, r) Stats_intf.fin_fun -> 'a mes

Creates a finitely supported measure from a finite function. A measure is not necessarily normalized.

  • raises Invalid_argument

    if a point as negative mass.

val probability : ('a, r) Stats_intf.fin_fun -> 'a prb

Creates a finitely supported probability from a finite function. A probability is normalized.

  • raises Invalid_argument

    if a point as negative mass or if the total mass does not sum up to one.

val as_measure : 'a prb -> 'a mes

Forgetful map from the type of finite probabilities to the type of measures.

val normalize : 't mes -> 't prb

Normalize a measure to obtain a probability measure.

  • raises Invalid_argument

    if the measure has zero mass.

val counts_of_empirical : (module Stdlib.Hashtbl.S with type key = 't) -> 't array -> 't mes

Computes the empirical measure of an array of elements. Each element present in the array is mapped to its count.

val uniform : 't array -> 't prb

Finitely supported uniform distribution.

val coin : bias:r -> bool prb

Biased coin. Raises an error if bias is not in 0,1.

val binomial : bool prb -> int -> int prb

Binomial distribution. binomial p n returns the probability of having k successes over n experiments, according to a biased coin p.

Using measures and probabilities

val integrate : 't mes -> ('t -> r) -> r

Integrates a function against a finitely supported measure.

val eval_prb : 't prb -> 't -> r

Evaluates a finitely supported probability on argument. Returns 0 if the argument is out of the support.

val eval_mes : 't mes -> 't -> r

Evaluates a finitely supported measure on argument. Returns 0 if the argument is out of the support.

val iter_prb : 't prb -> ('t -> r -> unit) -> unit

Iterates the given function on the support of the probability.

val iter_mes : 't mes -> ('t -> r -> unit) -> unit

Iterates the given function on the support of the measure.

val sample : 't mes -> (state, 't) Stats_intf.gen

Samples from a finitely supported distribution presented as an unnormalized measure. This is mostly useful when sampling only once or twice from a distribution: consider converting to a categorical sampler when sampling repeatedly. Complexity: O(n) with n the cardinality of the support.

val total_mass : 't mes -> r

Returns the total mass associated to a finitely supported measure.

val mean_generic : (module Basic_structures.Basic_intf.Module with type t = 't and type R.t = r) -> 't mes -> 't

Compute the mean of a finite measure supported on an Intf.Module.

val mean : r mes -> r

Compute the mean of a finite measure supported by r.

val variance : r mes -> r

Compute the variance of a finite measure supported by r.

val quantile : (module Basic_structures.Basic_intf.Ordered with type t = 'elt) -> 'elt mes -> r -> 'elt

quantile ord mes p computes the pth quantile of mes. The underlying data is totally ordered by ord.

  • raises Invalid_argument

    if p < 0 || p > 1 or if the total mass of mes is zero

val list_of_measure : 't mes -> [> `Measure of ('t * r) list ]

Returns the raw data underlying a finitely supported measure.

val list_of_probability : 't prb -> [> `Probability of ('t * r) list ]

Returns the raw data underlying a finitely supported probability.

type 'a pp := Stdlib.Format.formatter -> 'a -> unit
val pp_fin_mes : 'a pp -> 'a mes pp

Pretty print a measure, with elements sorted according to the order relation on the support.

val pp_fin_mes_by_measure : 'a pp -> 'a mes pp

Pretty print a measure, with elements sorted by increasing measure..

val fold_union : (module Stdlib.Hashtbl.S with type key = 't) -> ('t -> r -> r -> 'a -> 'a) -> 't mes -> 't mes -> 'a -> 'a

Fold over the union of the supports of the given measures.

module Dist : sig ... end
OCaml

Innovation. Community. Security.