mirror of
https://github.com/ArthurDanjou/ArtStudies.git
synced 2026-01-14 13:54:06 +01:00
Add Exo 10-11-12
This commit is contained in:
@@ -37,12 +37,4 @@ h <- function(x, y) {
|
||||
|
||||
I2 <- mean(h(X, Y))
|
||||
I2
|
||||
```
|
||||
|
||||
### Exponential + Truncated Normal distributions
|
||||
|
||||
```{r}
|
||||
|
||||
```
|
||||
|
||||
## Computational cost of these methods.
|
||||
```
|
||||
48
M1/Monte Carlo Methods/Exercise12.rmd
Normal file
48
M1/Monte Carlo Methods/Exercise12.rmd
Normal 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))
|
||||
```
|
||||
6
M1/Monte Carlo Methods/Exercise13.rmd
Normal file
6
M1/Monte Carlo Methods/Exercise13.rmd
Normal file
@@ -0,0 +1,6 @@
|
||||
# Exercise 13 : Gaussian integral and Variance reduction
|
||||
|
||||
```{r}
|
||||
n <- 10000
|
||||
|
||||
```
|
||||
Reference in New Issue
Block a user