-
Notifications
You must be signed in to change notification settings - Fork 0
/
exercise-sheet-7.Rmd
343 lines (207 loc) · 6.76 KB
/
exercise-sheet-7.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
---
title: "Exercise sheet 7: Markov chains"
---
---------------------------------
# Exercise 1 - Up-to-date or Behind
Alex is taking a bioinformatics class and in each week he can be either up-to-date or he may have fallen behind. If he is up-to-date in a given week, the probability that he will be up-to-date in the next week is 0.75. If he is behind in the given week, the probability that he will be up-to-date in the next week is 0.5.
If we assume that these probabilities do not depend on whether he was up-to-date or behind in previous weeks, we can model the problem using a Markov chain.
### 1a)
Draw a Markov chain that models the states of being Up-to-date or behind
#### {.tabset }
##### Hide
##### Solution
::::{#img1-p .extra-m}
::: {#img3 .tutorial-img}
```{r, echo=FALSE, out.width="100%", fig.align='center', include=knitr::is_html_output()}
knitr::include_graphics("figures/sheet-7/sheet7-exercise1-markov.svg")
```
:::
::::
#### {-}
### 1b)
Assume Alex is up-to-date in the first class; what is the probability that he is up-to-date two classes later?
#### {.tabset}
##### Hide
##### Hint : Formulae
\begin{align}
\pi(0) &: initial\ probabilities\\
P&: transition\ matrix\\
\pi(t) &= \pi(0) * P^{t}
\end{align}
##### Solution
The Probability is 0.6875
\begin{align}
\pi(0) &=
\begin{pmatrix}
1 & 0
\end{pmatrix}\\
\\
P &=
\begin{pmatrix}
0.75 & 0.25\\
0.5 & 0.5
\end{pmatrix}\\
\\
\pi(2) &= \pi(0) \times P^{2}\\
&=
\begin{pmatrix}
0.6875 & 0.3125
\end{pmatrix}
\end{align}
#### {-}
### 1c)
What is the expected probability that he is behind after an infinitely long semester?
#### {.tabset}
##### Hide
##### Hint : Formulae
\begin{align}
\pi(0) &: initial\ probabilities\\
P&: transition\ matrix\\
\lim \limits_{t \to \infty} \pi(t) &= \pi(0) * P^{t}
\end{align}
##### Solution
The Probability is 1/3
$$
\lim \limits_{t \to \infty} \pi(t) = \pi(0) * P^{t} =
\begin{pmatrix}
2/3 & 1/3
\end{pmatrix}
$$
#### {-}
### 1d)
What is the transition probability matrix product for limit of $P^{t}$ as $t$ approaches infinity?
#### {.tabset}
##### Hide
##### Solution
\begin{align}
\lim \limits_{t \to \infty} P^t &=
\begin{pmatrix}
2/3 & 1/3 \\
2/3 & 1/3
\end{pmatrix}
\end{align}
#### {-}
# Exercise 2 - Stationary distribution
Consider a three-state Markov chain having the following transition probability matrix:
$$
\begin{pmatrix}
0.5 & 0.4 & 0.1\\
0.3 & 0.4 & 0.3\\
0.2 & 0.3 & 0.5
\end{pmatrix}
$$
### 2a)
In the long run, what proportion of time is the process in each of the three states?
#### {.tabset}
##### Hide
##### Hint: Formulae
See Question 1B
##### Solution
\begin{align}
\lim \limits_{t \to \infty} P^t &=
\begin{pmatrix}
0.339 & 0.371 & 0.290\\
0.339 & 0.371 & 0.290\\
0.339 & 0.371 & 0.290
\end{pmatrix}\\
\\
\lim \limits_{t \to \infty} \pi(t) &= \
\begin{pmatrix}
0.339 & 0.371 & 0.290
\end{pmatrix}
\end{align}
:::: {#explaining .message-box }
::: {#note-exp .note-header}
```{r, include=knitr::is_html_output(), echo=FALSE,}
knitr::include_graphics("figures/infoicon.svg")
```
**Note**
:::
::: {#note-exp .note-body}
$$
\lim \limits_{t \to \infty} \pi(t)
$$
is independent of $\pi(0)$ as long as $P$ does not contain disconnected subgraphs and only if the limit exists.
:::
::::
#### {-}
#### {.tabset}
# Exercise 3 - Reversibility
Consider a three-state Markov chain having the following transition probability matrix
$$
\begin{pmatrix}
0 & 1 & 0 \\
\dfrac{1}{3} & 0 & \dfrac{2}{3}\\
0 & 1 & 0
\end{pmatrix}
$$
### 3a)
Draw the Markov chain for this problem
#### {.tabset}
##### Hide
##### Solution
::::{#img1-p .extra-m}
::: {#img3 .tutorial-img}
```{r, echo=FALSE, out.width="60%", fig.align='center', include=knitr::is_html_output()}
knitr::include_graphics("figures/sheet-7/sheet7-exercise2-markov.svg")
```
:::
::::
#### {-}
### 3b)
Given the stationary distribution $\begin{pmatrix} \dfrac{1}{6} & \dfrac{1}{2} & \dfrac{1}{3} \end{pmatrix}$,
is this Markov chain reversible and what does this property tell you?
#### {.tabset}
##### Hide
##### Hint
A markov chain is reversible if:
$$
\pi_i^{*}P_{i,j} = \pi_j^{*}P_{j,i}
$$
Easiest way is to calculate it for all pairs of $i$ and $j$
##### Solution
Because $\pi_i^{*}P_{i,j} = \pi_j^{*}P_{j,i}\ \forall\ i,j$ the Markov chain is reversible
\begin{align}
\pi^{ * }_1 P_{1,2} &=& \dfrac{1}{6} \times 1 &=& \dfrac{1}{6} &=& \dfrac{1}{2} \times \dfrac{1}{3} &=& \pi^{ * }_2 P_{2,1}\\
\pi^{ * }_1 P_{1,3} &=& \dfrac{1}{6} \times 0 &=& 0 &=& \dfrac{1}{3} \times 0 &=& \pi^{ * }_3 P_{3,1}\\
\pi^{ * }_2 P_{2,3} &=& \dfrac{1}{2} \times \dfrac{2}{3} &=& \dfrac{1}{3} &=& \dfrac{1}{3} \times 1 &=& \pi^{ * }_3 P_{3,2}
\end{align}
#### {-}
# Exercise 4 - Markov chain representation
### 4a)
Decide which of the following figures represents a valid Markov Chain
::::{#img1-p .extra-m}
::: {#img3 .tutorial-img}
```{r, echo=FALSE, out.width="100%", fig.align='center', include=knitr::is_html_output()}
knitr::include_graphics("figures/sheet-7/sheet7-exercise4-markov-chains.svg")
```
:::
::::
#### {.tabset}
##### Hide
##### Solution
+ [x] i
+ [ ] ii - initial probabilities add up to 0.2
+ [ ] iii - transition probabilities for states A and B do not add up to 1
+ [ ] iv - duplicate state A
+ [ ] v - initial probabilities add up to 1.1
+ [x] vi
+ [ ] vii missing transition probabilites (0.1) for state C
#### {-}
### 4b)
Which of these statements about Markov Chains are valid?
#### {.tabset}
##### Statements
- [ ] In the graph representation of Markov chains, a single state cannot have more than 3 outgoing edges.
- [ ] In the matrix representation of Markov chains, values in each row have to add up to 1.
- [ ] In the matrix representation of Markov chains, values in each column have to add up to 1.
- [ ] The diagonal entries of the Markov chain matrix represent the transition probability of remaining in the current state.
- [ ] In the graph representation of Markov chains, a single state cannot have more than 3 ingoing edges.
- [ ] The graph representation of Markov chains is directed and acyclic by definition.
##### Solution
- [ ] In the graph representation of Markov chains, a single state cannot have more than 3 outgoing edges.
- [x] In the matrix representation of Markov chains, values in each row have to add up to 1.
- [ ] In the matrix representation of Markov chains, values in each column have to add up to 1.
- [x] The diagonal entries of the Markov chain matrix represent the transition probability of remaining in the current state.
- [ ] In the graph representation of Markov chains, a single state cannot have more than 3 ingoing edges.
- [ ] The graph representation of Markov chains is directed and acyclic by definition.