package prbnmcn-dagger

  1. Overview
  2. Docs

Sequential Monte-Carlo

include Intf.S

Core constructs of the DSL

include Intf.Core
type 'a t

'a t is the type of computations 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 map2 : 'a t -> 'b t -> ('a -> 'b -> 'c) -> 'c t

Applicative structure

val map_array : 'a t array -> ('a array -> 'b) -> 'b t

N-ary applicative structure

val if_ : bool t -> (bool -> 'a t) -> 'a t

If-then-else, mostly useful for monads featuring incremental computation. Allows to efficiently bind on a boolean computation.

module Infix : Intf.Infix with type 'a t := 'a t
val sample : 'a Dist.t -> 'a t

sample dist builds a computation that samples from dist. Note that dist must be a pure computation.

val samplei : 'a Dist.t t -> 'a t

samplei dist is similar to sample except that dist can be an impure computation (ie computing the distribution can involve sampling from other distributions).

val map_score : 'a t -> ('a -> float) -> 'a t

map_score m f behaves similarly to m except that the associated computation will be reweighted according to the result of evaluating f on the value of m.

val map_log_score : 'a t -> ('a -> Log_space.t) -> 'a t

Same as map_score excepts that a log-space likelihood is expected.

val score : float -> unit t

score s reweights the computation by s.

  • raises Invalid_arg

    if s < 0

val log_score : Log_space.t -> unit t

log_score behaves as score except that a log-space weight is expected.

module List_ops : Intf.Foldable with type 'a t = 'a list and type 'a m := 'a t
module Array_ops : Intf.Foldable with type 'a t = 'a array and type 'a m := 'a t
module Seq_ops : Intf.Foldable with type 'a t = 'a Stdlib.Seq.t and type 'a m := 'a t
val fork : int -> unit t

fork n creates n-1 particles. fork 1 does not create any new particle.

  • raises [Invalid_arg]

    if n < 1.

val get_score : Log_space.t t

get_score returns the score of the current particle.

val yield : unit t

yield signals the scheduler that the particle is ready for resampling.

val log_score_noyield : Log_space.t -> unit t

log_score_noyield behaves as log_score but doesn't yield.

val score_noyield : float -> unit t

score_noyield behaves as score but doesn't yield.

val map_log_score_noyield : 'a t -> ('a -> Log_space.t) -> 'a t

map_log_score_noyield behaves as map_log_score but doesn't yield.

val map_score_noyield : 'a t -> ('a -> float) -> 'a t

map_score_noyield behaves as map_score but doesn't yield.

type resampling_strategy

resampling is used to improve the statistical quality of a population. See module Resampling. By default, systematic_resampling is a reasonable choice.

val systematic_resampling : resampling_strategy
val stratified_resampling : resampling_strategy
exception Invalid_population
module Interruptible : sig ... end

The Interruptible module exposes an implementation of Sequential Monte-Carlo that gives back the hand to the user after each resampling.

module Non_interruptible : sig ... end

The Non_interruptible module exposes an implementation of Sequential Monte-Carlo that terminates when all particles terminate. Only use when the probabilistic program terminates almost surely!