Displaying 1 result from an estimated 1 matches for "indnew".
2009 Jul 29
1
Systematic resampling (in sequential Monte Carlo)
..., ..., N.
The following is a piece of R code that implements the procedure.
> ### Systematic resampling
> set.seed(2)
> x <- LETTERS[1 : 6] # labels
> w <- rexp(6)
> w <- w / sum(w) # probabilities
> W <- c(0, cumsum(w)) # cdf
> u <- (1 : 6 + runif(1)) / 6
> indNew <- sapply(seq_along(u),
+ function(i) (sum(W[i] <= u & u < W[i + 1])))
> (y <- rep(x, indNew))
[1] "A" "B" "D" "D" "F"
> ## graphically...
> plot(stepfun(seq_along(u), W), xaxt = "n")
> axis(1,...