Created
February 29, 2012 06:40
-
-
Save GuangchuangYu/1938586 to your computer and use it in GitHub Desktop.
The antithetic variates method is a variance reduction technique used in Monte Carlo methods.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Antithetic sampling reframes our estimate as a sum of negatively | |
## correlated random variables, using the fact that negative | |
## correlation reduces the variance of a sum. | |
## http://en.wikipedia.org/wiki/Antithetic_variates | |
g <- function(x) 1/(1+x) | |
N <- 1500 | |
n <- 50 | |
u1 <- matrix(runif(2 * n * N), ncol = n) | |
theta1 <- colMeans(g(u1)) | |
u2 <- matrix(runif(n * N), ncol = n) | |
theta2 <- 0.5 * (colMeans(g(u2)) + colMeans(g(1 - u2))) | |
var1 <- var(theta1) | |
var2 <- var(theta2) | |
res <- data.frame(Estimate=c(mean(theta1),mean(theta2)), | |
Variance=c(var1,var2)) | |
rownames(res) <- c("Classical Estimate", "Antithetic Variates") | |
print(res) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment