Particle Initialization

To initialize a particle filter, GenParticleFilters.jl supports both regular initialization via simple random sampling and stratified initialization.

Random initialization

By default, particles are sampled randomly according to the internal proposal of the provided model, or a custem proposal if one is specified.

GenParticleFilters.pf_initializeMethod
pf_initialize(model::GenerativeFunction, model_args::Tuple,
              observations::ChoiceMap, n_particles::Int;
              dynamic=false)

pf_initialize(model::GenerativeFunction, model_args::Tuple,
              observations::ChoiceMap, proposal::GenerativeFunction,
              proposal_args::Tuple, n_particles::Int;
              dynamic=false)

Initialize a particle filter, generating traces (i.e. particles) from the model constrained to the provided observations. A custom proposal can optionally be used to propose choices for the initial set of traces. Returns a ParticleFilterState.

If dynamic is true, the particle filter will not be specialized to a fixed trace type, allowing for sequential Monte Carlo inference over a sequence of models with differing structure, at the expense of more memory usage.

source

Stratified initialization

To reduce variance, particle filters can also be initialized via stratified sampling, given a list of provided strata.

GenParticleFilters.pf_initializeMethod
pf_initialize(model::GenerativeFunction, model_args::Tuple, 
              observations::ChoiceMap, strata, n_particles::Int;
              layout=:contiguous, dynamic=false)

pf_initialize(model::GenerativeFunction, model_args::Tuple,
              observations::ChoiceMap, strata,
              proposal::GenerativeFunction, proposal_args::Tuple,
              n_particles::Int; layout=:contiguous, dynamic=false)

Perform stratified initialization of a particle filter, given a set of strata specified as an iterator over choicemaps. Each generated trace is constrained to both the provided observations and the choicemap for the stratum it belongs to. A custom proposal can optionally be used to propose unconstrained choices.

For a filter with N particles and K strata, each stratum is first allocated B = ⌊N / K⌋ particles. If layout is :contiguous, these particles will be allocated in contiguous blocks (e.g., the particles for the first stratum will have indices 1:B). If layout is :interleaved, then particles from each stratum will have interleaved indices (e.g., the first stratum will have indices 1:K:B*K). The remaining R particles are distributed at random among the strata, and allocated the indices N-R:N.

If dynamic is true, the particle filter will not be specialized to a fixed trace type, allowing for sequential Monte Carlo inference over a sequence of models with differing structure, at the expense of more memory usage.

source

For convenience, strata can be generated using the choiceproduct function.