-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexercise-sheet-7.Rmd
334 lines (212 loc) · 6.77 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
---
title: "Exercise sheet 7: Jiang algorithm"
---
---------------------------------
# Exercise 1
<!--- --------------------------------- -->
::: {.question data-latex=""}
Please have a look at the reformulated recursion of the Jiang algorithm.
In the lecture, some important properties have been omitted for sake of clarity.
In this exercise your task is to explicitly state some of these properties.
:::
<!--- --------------------------------- -->
### 1.1
::: {.question data-latex=""}
What are the base cases for the table entries, how should the tables be initialized?
:::
#### {.tabset}
##### Hide
##### Solution
::: {.answer data-latex=""}
The empty prefix of each M matrix has to be initialized with 0.
:::
#### {-}
<!--- --------------------------------- -->
### 1.2
::: {.question data-latex=""}
What value has to be assigned to entries outside of the tabulated M matrices, for example element $(3,4)$ in the first table of exercise 2?
:::
#### {.tabset}
##### Hide
##### Solution
::: {.answer data-latex=""}
The elements of the M matrices consist of prefix-alignment below 2 arcs.
Any element outside these matrices is invalid and should never be used. Assign $\infty$.
:::
#### {-}
<!--- --------------------------------- -->
### 1.3
::: {.question data-latex=""}
In what situation do we need to evaluate the fourth case of the recursion?
:::
#### {.tabset}
##### Hide
##### Solution
::: {.answer data-latex=""}
The fourth case has to be evaluated only if there exists a pair of arcs that lies completely inside of the evaluated arcs.
:::
#### {-}
<!--- --------------------------------- -->
### 1.4
::: {.question data-latex=""}
Which entry of each M matrix is used for the $F$ matrix?
:::
#### {.tabset}
##### Hide
##### Solution
::: {.answer data-latex=""}
The matrix $F$ stores the final values of all $M$ matrices. The final values of the M-matrices are located at their lower right corners.
:::
#### {-}
<!--- --------------------------------- -->
# Exercise 2
<!--- --------------------------------- -->
::: {.question data-latex=""}
We would like to align the following two structures with the reformulated recursion of the Jiang algorithm:
```{r, include=knitr::is_html_output(), echo=FALSE, fig.align='center', out.width='40%'}
knitr::include_graphics("assets/figures/exercise-sheet-7/e2-1.svg")
```
The cost for the different operations are $w_d^{\text{end}}=2$, $w_b^{\text{end}}=3$, $w_{am}=6$, $w_d=7$, and $w_m=3$.
The matrices $M^{a_i,a_j}$ and $F$ (with some missing entries) are given as follows:
```{r, include=knitr::is_html_output(), echo=FALSE, fig.align='center', out.width='75%'}
knitr::include_graphics("assets/figures/exercise-sheet-7/e2-2.svg")
```
:::
<!--- --------------------------------- -->
### 2.1
::: {.question data-latex=""}
Which of the four matrices $M^{a_i}_{a_j}$ on the left corresponds to which pair of arcs $a_i$, $a_j$?
:::
#### {.tabset}
##### Hide
##### Solution
::: {.answer data-latex=""}
a. $M^{a_2,a_3}$
b. $M^{a_2,a_4}$
c. $M^{a_1,a_4}$
d. $M^{a_1,a_3}$
:::
#### {-}
<!--- --------------------------------- -->
### 2.2
::: {.question data-latex=""}
Calculate the missing values (shaded in grey) of the $M^{a_i}_{a_j}$ matrices and also calculate the values of the $F$
:::
#### {.tabset}
##### Hide
##### Formula
::: {.answer data-latex=""}
```{r, include=knitr::is_html_output(), echo=FALSE, fig.align='center', out.width='60%'}
knitr::include_graphics("assets/figures/exercise-sheet-7/Jiang-algo-notation.pdf.png")
```
```{r, include=knitr::is_html_output(), echo=FALSE, fig.align='center', out.width='60%'}
knitr::include_graphics("assets/figures/exercise-sheet-7/Jiang-algo-recursion.png")
```
:::
##### Solution
::: {.answer data-latex=""}
```{r, include=knitr::is_html_output(), echo=FALSE, fig.align='center', out.width='75%'}
knitr::include_graphics("assets/figures/exercise-sheet-7/e2-3.svg")
```
:::
#### {-}
<!--- --------------------------------- -->
# Exercise 3
<!--- --------------------------------- -->
::: {.question data-latex=""}
After having calculated the matrices $M^{a_i}_{a_j}$ we compute the matrix containing the alignment of all prefixes of the entire sequences.
Technically, this is a matrix $M^{a_i}_{a_j}$ for some imaginary base pairs $a_i=(0,9)$ and $a_j=(0,9)$.
This matrix is given as:
```{r, include=knitr::is_html_output(), echo=FALSE, fig.align='center', out.width='60%'}
knitr::include_graphics("assets/figures/exercise-sheet-7/e3-1.svg")
```
A part of the final backtrace is also already given by the arrows in the matrix.
Give the missing part of the backtrace and also the alignment corresponding to the backtrace!
:::
#### {.tabset}
##### Hide
##### Solution
::: {.answer data-latex=""}
Traceback:
```{r, include=knitr::is_html_output(), echo=FALSE, fig.align='center', out.width='60%'}
knitr::include_graphics("assets/figures/exercise-sheet-7/e3-2.svg")
```
Alignment:
```{r, include=knitr::is_html_output(), echo=FALSE, fig.align='center', out.width='40%'}
knitr::include_graphics("assets/figures/exercise-sheet-7/e3-3.svg")
```
Example calculations for matrix M:
$$
M(0,1) = \min \left\{
\begin{array}{ll}
+ \infty, \\
M(0,0) + W_{d}^{\text{end}} & = 0 + 2 = \textbf{2}, \\
+ \infty, \\
+ \infty
\end{array}
\right.
$$
$$
M(1,1) = \min \left\{
\begin{array}{ll}
M(0,1) + W_d & = 2 + 7 = 9, \\
M(1,0) + W_{d}^{\text{end}} & = 7 + 2 = 9, \\
M(0,0) + W_m + W_{b}^{\text{end}} & = 0 + 3 + 3 = \textbf{6}, \\
+ \infty
\end{array}
\right.
$$
$$
M(7,7) = \min \left\{
\begin{array}{ll}
M(6,7) + W_{d}^{\text{end}} & = 18 + 2 = \textbf{20}, \\
M(7,6) + W_{d}^{\text{end}} & = 19 + 2 = 21, \\
M(6,6) + W_m + 2 \cdot W_{b}^{\text{end}} & = 17 + 3 + 2 \cdot 3 = 26, \\
M(3,0) + M_{a_3}^{a_2}(6,6) + W_{am} & = 19 + 16 + 6 = 41
\end{array}
\right.
$$
Traceback calculations:
$$
M(8,8) = \min \left\{
\begin{array}{ll}
M(7,8) + W_{d}^{\text{end}} & = 19 + 2 = \textbf{21}, \\
M(8,7) + W_{d}^{\text{end}} & = 22 + 2 = 24, \\
M(7,7) + W_m + 2W_{b}^{\text{end}} & = 20 + 3 + 6 = 29, \\
M(1,3) + M_{a_4}^{a_1}(7,7) + \frac{W_{am}}{2} & = 12 + 13 + 3 = 28
\end{array}
\right.
$$
$$
M(7,8) = \min \left\{
\begin{array}{ll}
M(6,8) + W_{d}^{\text{end}} & = 17 + 2 = \textbf{19}, \\
M(7,7) + W_{d}^{\text{end}} & = 20 + 2 = 22, \\
M(6,7) + W_m + 2W_{b}^{\text{end}} & = 18 + 3 + 6 = 27, \\
+ \infty
\end{array}
\right.
$$
$$
M(6,8) = \min \left\{
\begin{array}{ll}
M(5,8) + W_d & = 16 + 7 = 23, \\
M(6,7) + W_{d}^{\text{end}} & = 18 + 2 = 20, \\
M(5,7) + W_{b}^{\text{end}} & = 14 + 3 = \textbf{17}, \\
+ \infty
\end{array}
\right.
$$
$$
M(5,7) = \min \left\{
\begin{array}{ll}
M(4,7) + W_d & = 21 + 7 = 28, \\
M(5,6) + W_{d}^{\text{end}} & = 12 + 2 = \textbf{14}, \\
M(4,6) + W_m + W_{b}^{\text{end}} & = 19 + 3 + 3 = 25, \\
+ \infty
\end{array}
\right.
$$
:::
#### {-}
<!--- --------------------------------- -->