Particle filter internal state. This object is not ordinarily constructed directly by users, but via the $run_begin method to particle_filter. It provides an advanced interface to the particle filter that allows partially running the particle filter over part of the time trajectory.

This state object has a number of public fields that you can read but must not write (they are not read-only so you could write them, but don't).

Public fields

model

The dust model being simulated

history

The particle history, if created with save_history = TRUE. This is an internal format subject to

restart_state

Full model state at a series of points in time, if the model was created with non-NULL save_restart. This is a 3d (or greater) array as described in particle_filter

log_likelihood

The log-likelihood so far. This starts at 0 when initialised and accumulates value for each step taken.

log_likelihood_step

The log-likelihood attributable to the last step (i.e., the contribution to log_likelihood made on the last call to $step().

current_time_index

The index of the last completed step.

Methods


Method new()

Initialise the particle filter state. Ordinarily this should not be called by users, and so arguments are barely documented.

Usage

particle_filter_state$new(
  pars,
  generator,
  model,
  data,
  data_split,
  times,
  n_particles,
  has_multiple_parameters,
  n_threads,
  initial,
  index,
  compare,
  constant_log_likelihood,
  gpu_config,
  seed,
  min_log_likelihood,
  save_history,
  save_restart,
  stochastic_schedule,
  ode_control
)

Arguments

pars

Parameters for a single phase

generator

A dust generator object

model

If the generator has previously been initialised

data

A particle_filter_data data object

data_split

The same data as data but split by step

times

A matrix of time step beginning and ends

n_particles

Number of particles to use

has_multiple_parameters

Compute multiple likelihoods at once?

n_threads

The number of threads to use

initial

Initial condition function (or NULL)

index

Index function (or NULL)

compare

Compare function

constant_log_likelihood

Constant log likelihood function

gpu_config

GPU configuration, passed to generator

seed

Initial RNG seed

min_log_likelihood

Early termination control

save_history

Logical, indicating if we should save history

save_restart

Vector of time steps to save restart at

stochastic_schedule

Vector of times to perform stochastic updates

ode_control

Tuning control for stepper


Method run()

Run the particle filter to the end of the data. This is a convenience function around $step() which provides the correct value of time_index

Usage

particle_filter_state$run()


Method step()

Take a step with the particle filter. This moves the particle filter forward one step within the data (which may correspond to more than one step with your model) and returns the likelihood so far.

Usage

particle_filter_state$step(time_index, partial = FALSE)

Arguments

time_index

The step index to move to. This is not the same as the model step, nor time, so be careful (it's the index within the data provided to the filter). It is an error to provide a value here that is lower than the current step index, or past the end of the data.

partial

Logical, indicating if we should return the partial likelihood, due to this step, rather than the full likelihood so far.


Method fork_multistage()

Create a new particle_filter_state object based on this one (same model, position in time within the data) but with new parameters, to support the "multistage particle filter". Unlike fork_smc2, here the parameters may imply a different model shape and arbitrary transformations of the state are allowed. The model is not rerun to the current point, just transformed at that point.

Usage

particle_filter_state$fork_multistage(model, pars, transform_state)

Arguments

model

A model object (or NULL)

pars

New model parameters

transform_state

A function to transform the model state from the old to the new parameter set. See multistage_epoch() for details.


Method fork_smc2()

Create a new particle_filter_state object based on this one (same model, position in time within the data) but with new parameters, run up to the date, to support the smc2() algorithm. To do this, we create a new particle_filter_state with new parameters at the beginning of the simulation (corresponding to the start of your data or the initial argument to particle_filter) with your new pars, and then run the filter foward in time until it reaches the same step as the parent model.

Usage

particle_filter_state$fork_smc2(pars)

Arguments

pars

New model parameters