Create a bootstrap particle filter algorithm for a given NIMBLE state space model.
buildBootstrapFilter(model, nodes, control = list())
A nimble model object, typically representing a state space model or a hidden Markov model
A character vector specifying the latent model nodes over which the particle filter will stochastically integrate over to estimate the log-likelihood function
A list specifying different control options for the particle filter. Options are described in the details section below.
Calling the returnESS()
method of a bootstrap filter after that filter has been run()
for a given model will return a vector of ESS (effective
sample size) values, one value for each time point.
Each of the control()
list options are described in detail here:
A number between 0 and 1 specifying when to resample: the resampling step will occur when the
effective sample size is less than thresh
times the number of particles. Defaults to 0.8.
Indicates whether to save state samples for all time points (TRUE), or only for the most recent time point (FALSE)
Decides whether to save smoothed estimates of latent states, i.e., samples from f(x[1:t]|y[1:t]) if smoothing = TRUE
, or instead to save filtered samples from f(x[t]|y[1:t]) if smoothing = FALSE
. smoothing = TRUE
only works if saveAll = TRUE
.
An integer used to manually specify which dimension of the latent state variable indexes time. Only needs to be set if the number of time points is less than or equal to the size of the latent state at each time point.
A logical value indicating whether to initialize the model before running the filtering algorithm. Defaults to TRUE.
The bootstrap filter starts by generating a sample of estimates from the prior distribution of the latent states of a state space model. At each time point, these particles are propagated forward by the model's transition equation. Each particle is then given a weight proportional to the value of the observation equation given that particle. The weights are used to draw an equally-weighted sample of the particles at this time point. The algorithm then proceeds to the next time point. Neither the transition nor the observation equations are required to be normal for the bootstrap filter to work.
The resulting specialized particle filter algorthm will accept a
single integer argument (m
, default 10,000), which specifies the number
of random \'particles\' to use for estimating the log-likelihood. The algorithm
returns the estimated log-likelihood value, and saves
unequally weighted samples from the posterior distribution of the latent
states in the mvWSamples
modelValues object, with corresponding logged weights in mvWSamples['wts',]
.
An equally weighted sample from the posterior can be found in the mvEWsamp
modelValues
object.
Gordon, N.J., D.J. Salmond, and A.F.M. Smith. (1993). Novel approach to nonlinear/non-Gaussian Bayesian state estimation. IEEE Proceedings F (Radar and Signal Processing). Vol. 140. No. 2. IET Digital Library, 1993.
Other particle filtering methods: buildAuxiliaryFilter
,
buildEnsembleKF
,
buildLiuWestFilter
# NOT RUN {
model <- nimbleModel(code = ...)
my_BootF <- buildBootstrapFilter(model, 'x[1:100]')
Cmodel <- compileNimble(model)
Cmy_BootF <- compileNimble(my_BootF, project = model)
logLike <- Cmy_BootF$run(m = 100000)
ESS <- Cmy_BootF$returnESS()
boot_X <- as.matrix(Cmy_BootF$mvEWSamples)
# }
Run the code above in your browser using DataLab