low_var_sample {animalEKF} | R Documentation |
Sample particles using low-variance sampling.
Description
Sample particles using low-variance sampling.
Usage
low_var_sample(wts, M=length(wts))
Arguments
wts |
Vector of weights. |
M |
The number of items to sample. When resampling, should be number of particles |
Details
Low-variance sampling guarantees items will be sampled in proportion to their weights. With random sampling with replacement (sample
function), there is some variability in the final proportions of items.
Value
A numeric vector of length M
.
Author(s)
Samuel Ackerman
References
James Edward Baker. Reducing bias and inefficiency in the selection algorithm. Proceedings of the Second International Conference on Genetic Algorithms on Genetic Algorithms and Their Application, 1987.
Examples
n <- 20
w <- runif(n)
#can use M != to length(wts)
low_var_sample(wts=w, M=15)
lv <- low_var_sample(wts=w, M=n)
#usual resampling with weights
a <- sample(x=1:n, size=n, prob=w, replace=TRUE)
#the first should be more in proportion to weights
table(lv)/n
table(a)/n
#proportions
w/sum(w)
[Package animalEKF version 1.2 Index]