-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path06-integration.Rmd
147 lines (119 loc) · 3.8 KB
/
06-integration.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# Integration {#integ}
This chapter deals with abstract and Monte Carlo integration.
The students are expected to acquire the following knowledge:
**Theoretical**
- How to calculate Lebesgue integrals for non-simple functions.
**R**
- Monte Carlo integration.
<style>
.fold-btn {
float: right;
margin: 5px 5px 0 0;
}
.fold {
border: 1px solid black;
min-height: 40px;
}
</style>
<script type="text/javascript">
$(document).ready(function() {
$folds = $(".fold");
$folds.wrapInner("<div class=\"fold-blck\">"); // wrap a div container around content
$folds.prepend("<button class=\"fold-btn\">Unfold</button>"); // add a button
$(".fold-blck").toggle(); // fold all blocks
$(".fold-btn").on("click", function() { // add onClick event
$(this).text($(this).text() === "Fold" ? "Unfold" : "Fold"); // if the text equals "Fold", change it to "Unfold"or else to "Fold"
$(this).next(".fold-blck").toggle("linear"); // "swing" is the default easing function. This can be further customized in its speed or the overall animation itself.
})
});
</script>
```{r, echo = FALSE, warning = FALSE, message = FALSE}
togs <- T
library(ggplot2)
library(dplyr)
library(reshape2)
library(tidyr)
# togs <- FALSE
```
## Monte Carlo integration
```{exercise}
<span style="color:blue">Let $X$ and $Y$ be continuous random variables on the unit interval and $p(x,y) = 6(x - y)^2$. Use Monte Carlo integration to estimate the probability $P(0.2 \leq X \leq 0.5, \: 0.1 \leq Y \leq 0.2)$. Can you find the exact value?</span>
```
<div class="fold">
```{r, echo = togs, message = FALSE, warning=FALSE, eval = togs}
set.seed(1)
nsamps <- 1000
V <- (0.5 - 0.2) * (0.2 - 0.1)
x1 <- runif(nsamps, 0.2, 0.5)
x2 <- runif(nsamps, 0.1, 0.2)
f_1 <- function (x, y) {
return (6 * (x - y)^2)
}
mcint <- V * (1 / nsamps) * sum(f_1(x1, x2))
sdm <- sqrt((V^2 / nsamps) * var(f_1(x1, x2)))
mcint
sdm
F_1 <- function (x, y) {
return (2 * x^3 * y - 3 * x^2 * y^2 + 2 * x * y^3)
}
F_1(0.5, 0.2) - F_1(0.2, 0.2) - F_1(0.5, 0.1) + F_1(0.2, 0.1)
```
</div>
## Lebesgue integrals
```{exercise, name = "borrowed from Jagannathan"}
Find the Lebesgue integral of the following functions on ($\mathbb{R}$, $\mathcal{B}(\mathbb{R})$, $\lambda$).
a.
\begin{align}
f(\omega) =
\begin{cases}
\omega, & \text{for } \omega = 0,1,...,n \\
0, & \text{elsewhere}
\end{cases}
\end{align}
b.
\begin{align}
f(\omega) =
\begin{cases}
1, & \text{for } \omega = \mathbb{Q}^c \cap [0,1] \\
0, & \text{elsewhere}
\end{cases}
\end{align}
c.
\begin{align}
f(\omega) =
\begin{cases}
n, & \text{for } \omega = \mathbb{Q}^c \cap [0,n] \\
0, & \text{elsewhere}
\end{cases}
\end{align}
```
<div class="fold">
```{solution, echo = togs}
a.
\begin{align}
\int f(\omega) d\lambda = \sum_{\omega = 0}^n \omega \lambda(\omega) = 0.
\end{align}
b.
\begin{align}
\int f(\omega) d\lambda = 1 \times \lambda(\mathbb{Q}^c \cap [0,1]) = 1.
\end{align}
c.
\begin{align}
\int f(\omega) d\lambda = n \times \lambda(\mathbb{Q}^c \cap [0,n]) = n^2.
\end{align}
```
</div>
```{exercise, name = "borrowed from Jagannathan"}
Let $c \in \mathbb{R}$ be fixed and ($\mathbb{R}$, $\mathcal{B}(\mathbb{R})$) a measurable space. If for any Borel set $A$, $\delta_c (A) = 1$ if $c \in A$, and $\delta_c (A) = 0$ otherwise, then $\delta_c$ is called a _Dirac measure_. Let $g$ be a non-negative, measurable function. Show that $\int g d \delta_c = g(c)$.
```
<div class="fold">
```{solution, echo = togs}
\begin{align}
\int g d \delta_c &= \sup_{q \in S(g)} \int q d \delta_c \\
&= \sup_{q \in S(g)} \sum_{i = 1}^n a_i \delta_c(A_i) \\
&= \sup_{q \in S(g)} \sum_{i = 1}^n a_i \text{I}_{A_i}(c) \\
&= \sup_{q \in S(g)} q(c) \\
&= g(c)
\end{align}
```
</div>