View source: R/low_var_sample.r
| low_var_sample | R Documentation |
Sample particles using low-variance sampling.
low_var_sample(wts, M=length(wts))
wts |
Vector of weights. |
M |
The number of items to sample. When resampling, should be number of particles |
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.
A numeric vector of length M.
Samuel Ackerman
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.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.