Description Usage Arguments Details Value See Also Examples
Manipulate PIMH objects.
The method biips_pimh_update
performs burn-in iterations for the PIMH
algorithm.
The method biips_pimh_samples
performs iterations for the PIMH
algorithm and returns samples.
1 2 3 4 5 6 7 8 9 | is.pimh(object)
## S3 method for class 'pimh'
biips_pimh_update(object, n_iter, n_part, thin = 1,
output = "l", ...)
## S3 method for class 'pimh'
biips_pimh_samples(object, n_iter, n_part, thin = 1,
output = "l", ...)
|
object |
a |
n_iter |
integer. Number of burn-in iterations. |
n_part |
integer. Number of particles used in SMC algorithms. |
thin |
integer. Thinning interval. Returns samples every |
output |
string. Select additional members to be returned in the
|
... |
Additional arguments to be passed to the SMC
algorithm such as |
The output
string arguments can be used to query additional
members in the mcmcarray.list
output. If output
contains:
returns member log_marg_like
. mcmcarray
with log marginal likelihood estimates over iterations.
returns member info$accept_rate
. mcmcarray
with acceptance rate over
iterations.
The function is.pimh
returns TRUE
if the object is of
class pimh
.
The methods biips_pimh_update
and biips_pimh_update
return an object of class mcmcarray.list
.
biips_pimh_samples
output contains one mcmcarray
member for each monitored variable returned by the variable_names()
member function of the pimh
object.
If the output
argument is not empty, the output contains
additional members. See details.
The members of the mcmcarray.list
object are
mcmcarray
objects for different variables. Assuming dim
is the dimension of the monitored variable, the mcmcarray
object is an array of dimension c(dim, n_iter)
with the following
attributes (accessible with attr
):
string with the name of the variable.
vector with the lower bounds of the variable.
vector with the upper bounds of the variable.
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 46 47 48 | 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)
n_part <- 50
obj_pimh <- biips_pimh_init(model, c('x', 'c[2:10]')) # Initialize
is.pimh(obj_pimh)
out_pimh_burn <- biips_pimh_update(obj_pimh, 100, n_part) # Burn-in
out_pimh <- biips_pimh_samples(obj_pimh, 100, n_part) # Samples
summ_pimh_x <- biips_summary(out_pimh$x, order = 2, probs = c(0.025, 0.975))
dens_pimh_x <- biips_density(out_pimh$x)
summ_pimh_c <- biips_summary(out_pimh[['c[2:10]']])
table_pimh_c <- biips_table(out_pimh[['c[2:10]']])
par(mfrow = c(2, 1))
plot(c(out_pimh_burn$log_marg_like, out_pimh$log_marg_like), type = 'l', col = 'blue',
xlab = 'PIMH iteration', ylab = 'log p(y)')
t <- 5
plot(out_pimh$x[t, ], type = 'l', col = 'blue', xlab = 'PIMH iteration',
ylab = paste0('x[',t,']'))
points(0, model$data()$x_true[t], pch = 17, col = 'green')
par(mfrow = c(2, 2))
plot(model$data()$x_true, type = 'l', col = 'green', xlab = 't', ylab = 'x[t]')
lines(summ_pimh_x$mean, col = 'blue')
matlines(matrix(unlist(summ_pimh_x$quant), data$tmax), lty = 2, col = 'blue')
legend('topright', leg = c('true', 'PIMH estimate'), lty = c(2, 1),
col = c('green', 'blue'), bty = 'n')
barplot(.5*(model$data()$c_true==1), col = 'green', border = NA, space = 0, offset = 1,
ylim=c(0,2), 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,2), labels=NA)
text(data$tmax/2, 1.75, 'true')
barplot(.5*c(NA, summ_pimh_c$mode==1), col = 'blue', border = NA, space = 0,
axes = FALSE, add = TRUE)
text(data$tmax/2, .75, 'PIMH mode')
plot(dens_pimh_x[[t]], col='blue', main = , ylab = 'posterior density')
points(model$data()$x_true[t], 0, pch = 17, col = 'green')
plot(table_pimh_c[[t-1]], col='blue', 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.