smcUtils (version 0.2.2)

resample: Resample

Description

A set of resampling functions with unbiased number of replicates.

Usage

resample(weights, num.samples=length(weights), method = c("stratified","residual","multinomial","systematic","branching"), nonuniformity = c("none","ess","cov","entropy"), threshold = 0.5, rrf = "stratified", engine="R", log=TRUE, normalized=FALSE)

Arguments

weights
a vector of weights, possibly logged, unnormalized, or both
num.samples
a scalar indicating the number of samples to return (for `branching.resample', `num.samples' is the expected number of samples as the actual number is random)
method
a character string indicating the resampling method to use. One of `"multinomial"' (default), `"residual"', `"stratified"', `"systematic"', or `"branching"', can be abbreviated.
nonuniformity
a character string indicating which hueristic to use for measuring weight nonuniformity. One of `"none"' (default), `"ess"', `"cov"', or `"entropy"', can be abbreviated. If "none", resampling will always be performed.
threshold
a scalar in [0,1] indicating when to resample. If `nonuniformity="none"', resampling is always performed regardless of threshold. If `nonuniformity="ess"' or "entropy", resampling is performed when `nonuniformity/num.samples threshold'.
rrf
for residual resampling, the resampling function to use on the residual
engine
run using "R" or "C" code
log
if TRUE, the weights are assumed to be logged
normalized
if TRUE, the weights are assumed to be normalized and no error checking is done

Value

weights
the component weights
indices
an integer vector containing the indices of resampled components. If no resampling was performed, then `indices=1:length(weights)'.

See Also

resampling

Examples

Run this code
ws = dnorm(0:5, log=TRUE)
resample(ws)
resample(ws,13)
resample(ws,method="residual")
resample(ws,method="residual",rrf="stratified")
resample(ws,17,"stratified","ess",0.5)

Run the code above in your browser using DataLab