Add Exo 10-11-12

This commit is contained in:
2024-11-13 18:30:34 +01:00
parent 88d0907535
commit 00388ad6b8
3 changed files with 55 additions and 9 deletions

View File

@@ -37,12 +37,4 @@ h <- function(x, y) {
I2 <- mean(h(X, Y))
I2
```
### Exponential + Truncated Normal distributions
```{r}
```
## Computational cost of these methods.
```

View File

@@ -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))
```

View File

@@ -0,0 +1,6 @@
# Exercise 13 : Gaussian integral and Variance reduction
```{r}
n <- 10000
```