Create an auxiliary particle filter algorithm for a given NIMBLE state space model.
buildAuxiliaryFilter(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 to estimate the log-likelihood function
A list specifying different control options for the particle filter. Options are described in the details section below.
The control
argument can be specified as follows.
The lookahead function used to calculate auxiliary weights. Can choose between 'mean'
and 'simulate'
.
Defaults to 'simulate'
.
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. This need only 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 auxiliary particle filter modifies the bootstrap filter (buildBootstrapFilter
)
by adding a lookahead step to the algorithm: before propagating particles from one time
point to the next via the transition equation, the auxiliary filter calculates a weight
for each pre-propogated particle by predicting how well the particle will agree with the
next data point. These pre-weights are used to conduct an initial resampling step before
propagation.
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.
The auxiliary particle filter uses a lookahead function to select promising particles before propagation. This function can eithre be the expected
value of the latent state at the next time point (lookahead = 'mean'
) or a simulation from the distribution of the latent state at the next time point (lookahead = 'simulate'
), conditioned on the current particle.
@section returnESS()
Method:
Calling the returnESS()
method of an auxiliary particle 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.
Pitt, M.K., and Shephard, N. (1999). Filtering via simulation: Auxiliary particle filters. Journal of the American Statistical Association 94(446): 590-599.
Other particle filtering methods: buildBootstrapFilter
,
buildEnsembleKF
,
buildLiuWestFilter
# NOT RUN {
model <- nimbleModel(code = ...)
my_AuxF <- buildAuxiliaryFilter(model, 'x[1:100]',
control = list(saveAll = TRUE, lookahead = 'mean'))
Cmodel <- compileNimble(model)
Cmy_AuxF <- compileNimble(my_AuxF, project = model)
logLike <- Cmy_AuxF$run(m = 100000)
ESS <- Cmy_AuxF$returnESS(m = 100000)
hist(as.matrix(Cmy_Auxf$mvEWSamples, 'x'))
# }
Run the code above in your browser using DataLab