From 5323793daa2c9ee51fa52eae3182becdd7accb2c Mon Sep 17 00:00:00 2001 From: Arthur DANJOU Date: Wed, 13 Nov 2024 18:30:34 +0100 Subject: [PATCH] Add Exo 10-11-12 --- M1/Monte Carlo Methods/Exercise10.rmd | 10 +----- M1/Monte Carlo Methods/Exercise12.rmd | 48 +++++++++++++++++++++++++++ M1/Monte Carlo Methods/Exercise13.rmd | 6 ++++ 3 files changed, 55 insertions(+), 9 deletions(-) create mode 100644 M1/Monte Carlo Methods/Exercise12.rmd create mode 100644 M1/Monte Carlo Methods/Exercise13.rmd diff --git a/M1/Monte Carlo Methods/Exercise10.rmd b/M1/Monte Carlo Methods/Exercise10.rmd index 2be4a54..5bff6d7 100644 --- a/M1/Monte Carlo Methods/Exercise10.rmd +++ b/M1/Monte Carlo Methods/Exercise10.rmd @@ -37,12 +37,4 @@ h <- function(x, y) { I2 <- mean(h(X, Y)) I2 -``` - -### Exponential + Truncated Normal distributions - -```{r} - -``` - -## Computational cost of these methods. \ No newline at end of file +``` \ No newline at end of file diff --git a/M1/Monte Carlo Methods/Exercise12.rmd b/M1/Monte Carlo Methods/Exercise12.rmd new file mode 100644 index 0000000..4dcfd09 --- /dev/null +++ b/M1/Monte Carlo Methods/Exercise12.rmd @@ -0,0 +1,48 @@ +# Exercise 12 : Rejection vs Importance Sampling +```{r} +set.seed(123) +n <- 10000 + +f <- function(x, y) { + 3 / 2 * exp(-3 / 2 * x) * (x > 0) * 1 / (2 * sqrt(pi)) * + exp(-y^2 / 4) * + (x > 0) +} + +g <- function(x, y, lambda) { + (3 / 2 * exp(-3 / 2 * x)) * + (x >= 0) * + (lambda * exp(-lambda * (y - 2))) * + (y >= 2) +} + +h <- function(x, y) { + sqrt(x + y) * + sin(y^4) * + (x <= 5) * + (x > 0) * + (y >= 2) * + (4 * sqrt(pi) / 3) +} + +X <- rexp(n, 3 / 2) +Y <- rexp(n, 2) + 2 + +mean(h(X, Y) * f(X, Y) / g(X, Y, 0.4)) +``` + +### Monte Carlo method + +```{r} +set.seed(123) +n <- 10e4 + +X <- rexp(n, 3 / 2) +Y <- rexp(n, 3 / 2) + 2 + +X[X > 5] <- 0 +X[X < 0] <- 0 +Y[Y < 2] <- 0 + +mean(h(X, Y)) +``` \ No newline at end of file diff --git a/M1/Monte Carlo Methods/Exercise13.rmd b/M1/Monte Carlo Methods/Exercise13.rmd new file mode 100644 index 0000000..71ac457 --- /dev/null +++ b/M1/Monte Carlo Methods/Exercise13.rmd @@ -0,0 +1,6 @@ +# Exercise 13 : Gaussian integral and Variance reduction + +```{r} +n <- 10000 + +``` \ No newline at end of file