Description Usage Arguments Value See Also Examples
Run a sequential Monte Carlo algorithm
1 2 3 4 5 | biips_smc_samples(object, ...)
## S3 method for class 'biips'
biips_smc_samples(object, variable_names, n_part, type = "fs",
rs_thres = 0.5, rs_type = "stratified", ...)
|
object |
|
... |
additional arguments to pass to internal functions |
variable_names |
character vector. The names of the unobserved
variables to monitor, e.g.: |
n_part |
integer. Number of particles. |
type |
string containing the characters |
rs_thres |
real. Threshold for the adaptive SMC resampling. (default = 0.5)
|
rs_type |
string. Name of the algorithm used for the SMC
resampling. Possible values are |
A smcarray.fsb.list
object, with one named member for
each monitored variable in the variable_names
argument and a member
named log_marg_like
with an estimate of the log marginal likelihood.
A smcarray.fsb.list
object is a named list of
smcarray.fsb
objects for different variables. Each
smcarray.fsb
object is a named list of smcarray
object, with one member for each type of monitoring (f
, s
and/or b
) in the type
argument. Assuming dim
is the
dimension of the monitored variable, a smcarray
object is a
list with the members:
values |
array of dimension |
weights |
array of dimension |
ess |
array of dimension |
discrete |
array of dimension |
iterations |
array of dimension |
conditionals |
lists of the contitioning variables (observations). Its value is:
|
name |
string with the name of the variable (without subset indices). |
lower |
vector with the lower bounds of the variable. |
upper |
vector with the upper bounds of the variable. |
type |
string with the type of monitor ( |
For instance, if out_smc
is a smcarray.fsb.list
object,
one can access the values of the smoothing particles for the variable
'x'
with: out_smc$x$s$values
.
biips_model
, biips_diagnosis
,
biips_summary
, biips_density
,
biips_table
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | modelfile <- system.file('extdata', 'hmm.bug', package = 'rbiips')
stopifnot(nchar(modelfile) > 0)
cat(readLines(modelfile), sep = '\n')
data <- list(tmax = 10, p = c(.5, .5), logtau_true = log(1), logtau = log(1))
model <- biips_model(modelfile, data, sample_data = TRUE)
n_part <- 100
out_smc <- biips_smc_samples(model, c('x', 'c[2:10]'), n_part, type = 'fs',
rs_thres = 0.5, rs_type = 'stratified')
biips_diagnosis(out_smc)
summ_smc_x <- biips_summary(out_smc$x, order = 2, probs = c(.025, .975))
dens_smc_x <- biips_density(out_smc$x, bw = 'nrd0', adjust = 1, n = 100)
summ_smc_c <- biips_summary(out_smc[['c[2:10]']])
table_smc_c <- biips_table(out_smc[['c[2:10]']])
par(mfrow = c(2, 2))
plot(model$data()$x_true, type = 'l', col = 'green', xlab = 't', ylab = 'x[t]')
lines(summ_smc_x$f$mean, col = 'blue')
lines(summ_smc_x$s$mean, col = 'red')
matlines(matrix(unlist(summ_smc_x$f$quant), data$tmax), lty = 2, col = 'blue')
matlines(matrix(unlist(summ_smc_x$s$quant), data$tmax), lty = 2, col = 'red')
legend('topright', leg = c('true', 'SMC filtering estimate', 'SMC smoothing estimate'),
lty = 1, col = c('green', 'blue', 'red'), bty = 'n')
barplot(.5*(model$data()$c_true==1), col = 'green', border = NA, space = 0, offset=2,
ylim=c(0,3), xlab='t', ylab='c[t]==1', axes = FALSE)
axis(1, at=1:data$tmax-.5, labels=1:data$tmax)
axis(2, line = 1, at=c(0,3), labels=NA)
text(data$tmax/2, 2.75, 'true')
barplot(.5*c(NA, summ_smc_c$f$mode==1), col = 'blue', border = NA, space = 0,
offset=1, axes = FALSE, add = TRUE)
text(data$tmax/2, 1.75, 'SMC filtering mode')
barplot(.5*c(NA, summ_smc_c$s$mode==1), col = 'red', border = NA, space = 0,
axes = FALSE, add = TRUE)
text(data$tmax/2, .75, 'SMC smoothing mode')
t <- 5
plot(dens_smc_x[[t]], col = c('blue','red'), ylab = 'posterior density')
points(model$data()$x_true[t], 0, pch = 17, col = 'green')
plot(table_smc_c[[t-1]], col = c('blue','red'), ylab = 'posterior probability mass')
points(model$data()$c_true[t], 0, pch = 17, col = 'green')
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.