Learn R Programming

bssm (version 1.1.7-1)

ekpf_filter: Extended Kalman Particle Filtering

Description

Function ekpf_filter performs a extended Kalman particle filtering with stratification resampling, based on Van Der Merwe et al (2001).

Usage

ekpf_filter(object, particles, ...)

# S3 method for ssm_nlg ekpf_filter( object, particles, seed = sample(.Machine$integer.max, size = 1), ... )

Arguments

object

Model of class ssm_nlg.

particles

Number of particles as a positive integer.

...

Ignored.

seed

Seed for RNG (positive integer).

Value

A list containing samples, filtered estimates and the corresponding covariances, weights, and an estimate of log-likelihood.

References

Van Der Merwe, R., Doucet, A., De Freitas, N., & Wan, E. A. (2001). The unscented particle filter. In Advances in neural information processing systems (pp. 584-590).

Examples

Run this code
# NOT RUN {
 # Takes a while
set.seed(1)
n <- 50
x <- y <- numeric(n)
y[1] <- rnorm(1, exp(x[1]), 0.1)
for(i in 1:(n-1)) {
 x[i+1] <- rnorm(1, sin(x[i]), 0.1)
 y[i+1] <- rnorm(1, exp(x[i+1]), 0.1)
}

pntrs <- cpp_example_model("nlg_sin_exp")

model_nlg <- ssm_nlg(y = y, a1 = pntrs$a1, P1 = pntrs$P1, 
  Z = pntrs$Z_fn, H = pntrs$H_fn, T = pntrs$T_fn, R = pntrs$R_fn, 
  Z_gn = pntrs$Z_gn, T_gn = pntrs$T_gn,
  theta = c(log_H = log(0.1), log_R = log(0.1)), 
  log_prior_pdf = pntrs$log_prior_pdf,
  n_states = 1, n_etas = 1, state_names = "state")

out <- ekpf_filter(model_nlg, particles = 100)
ts.plot(cbind(x, out$at[1:n], out$att[1:n]), col = 1:3)
# }

Run the code above in your browser using DataLab