Smc_inference.Make
Make
produces an SMC inference module specialized to the types given in Resampling_types
.
module Resampling_types : Resampling_types_S
Core language API shared across all inference engines.
include Intf.S
val return : 'a -> 'a t
return x
injects a value x
as a computation
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
sample dist
builds a computation that samples from dist
. Note that dist
must be a pure computation.
samplei dist
is similar to sample
except that dist
can be an impure computation (ie computing the distribution can involve sampling from other distributions).
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
.
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
type particle_output = Resampling_types.particle_output
particle_output
is the type of values emitted by particles at yield
points.
type resampling_state = Resampling_types.resampling_state
resampling_state
is the type of values produced by resampling at yield
points.
val fork : int -> unit t
fork n
creates n-1
particles. fork 1
does not create any new particle.
val get_score : Log_space.t t
get_score
returns the score of the current particle.
val set_score : Log_space.t -> unit t
set_score
sets the score of the current particle. This drops the current score of the particle: use wisely.
val yield : particle_output -> resampling_state t
yield o
signals that the particle produced output o
and is ready for resampling. The output o
is associated to the score of that particle at yield
time (i.e. just before resampling) in the output of the SMC sampler (see type population
).
type 'a population = {
terminated : ('a * float) array;
The terminated particles. These carry their return value.
*)active : (particle_output * float) array;
total_mass : float;
The total mass of the population (including terminated particles).
*)}
'a population
is the type of a population.
type resampling_strategy :=
(particle_output, float, resampling_state) Resampling.strategy
val run :
resampling_strategy ->
resampling_state ->
npart:int ->
'a t ->
RNG.t ->
'a population Stdlib.Seq.t
run resampling resampling_state ~npart model rng
returns a lazy sequence of populations. The initial population has size npart
. resampling
corresponds to the resampling strategy. resampling_state
is the initial resampling state.
The model is evaluated as follows:
yield o
, at which point it is suspended;resampling
is executed on all particles (including terminated ones), resulting in a freshened population;The output of the algorithm is a sequence of population
. Each population is composed of yielded particles, attached to some value of type particle_output
, and of terminated particles.
Very important note: the output sequence is ephemeral.
val run_custom :
resampling_strategy ->
resampling_state ->
npart:int ->
(int -> 'a t) ->
RNG.t ->
'a population Stdlib.Seq.t
run_custom resampling resampling_state ~npart model rng
returns a lazy sequence of populations. See the documentation of run
for more details on the meaning of each argument.
The only difference with run
is that run_custom
starts with a custom initial population, obtained by evaluating model
on the integers from 0
to npart-1
.