Skip to content

Commit d42643a

Browse files
committed
fix HMM1
1 parent 0e3c9c2 commit d42643a

File tree

1 file changed

+110
-30
lines changed

1 file changed

+110
-30
lines changed

post/hmm1/index.html

Lines changed: 110 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ <h2 id="introduction">Introduction</h2>
7474
<h2 id="an-example">An example</h2>
7575
<p>Imagine there are only 100 people and three cities (New York, Boston, and Houston) in this world. Currently, 50 people live in New York, 30 people live in Boston, and 20 people live in Houston. Every year, a certain proportion of the population moves from one city to another, causing the population of each city to change constantly. Below is a diagram that shows the proportions:</p>
7676
<div style="text-align: center;">
77-
<img src="/images/HMM1/HMM1.png" alt="HMM1" width="50%" />
77+
<img src="/images/HMM1/HMM1.png" alt="HMM1" width="100%" />
7878
</div>
7979
<p> </p>
8080
<p><strong>The question is: what is the population size for each city in the next year?</strong></p>
@@ -103,33 +103,60 @@ <h2 id="an-example">An example</h2>
103103
<p> </p>
104104
<p>For example, to calculate the population of the 2nd year, we simply multiply the matrix with the population of the previous year:</p>
105105
<p>$$
106-
<code>\begin{bmatrix} 0.72 &amp; 0.05 &amp; 0.1 \\\\ 0.1 &amp; 0.75 &amp; 0.15 \\\\ 0.18 &amp; 0.2 &amp; 0.75 \end{bmatrix}</code>
106+
\begin{bmatrix}
107+
0.72 &amp; 0.05 &amp; 0.1 \\
108+
0.1 &amp; 0.75 &amp; 0.15 \\
109+
0.18 &amp; 0.2 &amp; 0.75
110+
\end{bmatrix}
107111
\cdot
108-
<code>\begin{bmatrix} 39.5 \\\\ 30.5 \\\\ 30 \end{bmatrix}</code>
112+
\begin{bmatrix}
113+
39.5 \\
114+
30.5 \\
115+
30
116+
\end{bmatrix}
109117
= \begin{bmatrix}
110118
33 \\
111-
31.3 \\
119+
31.3 \\
112120
35.7
113-
\end{bmatrix}`
121+
\end{bmatrix}
114122
$$</p>
115123
<p>To calculate the 3rd year, we have</p>
116124
<p>$$
117-
<code>\begin{bmatrix} 0.72 &amp; 0.05 &amp; 0.1 \\\\ 0.1 &amp; 0.75 &amp; 0.15 \\\\ 0.18 &amp; 0.2 &amp; 0.75 \end{bmatrix}</code>
125+
\begin{bmatrix}
126+
0.72 &amp; 0.05 &amp; 0.1 \\
127+
0.1 &amp; 0.75 &amp; 0.15 \\
128+
0.18 &amp; 0.2 &amp; 0.75
129+
\end{bmatrix}
118130
\cdot
119-
<code>\begin{bmatrix} 33 \\\\ 31.3 \\\\ 35.7 \end{bmatrix}</code>
131+
\begin{bmatrix}
132+
33 \\
133+
31.3 \\
134+
35.7
135+
\end{bmatrix}
120136
= \begin{bmatrix}
121137
28.9 \\
122-
32.1 \\
138+
32.1 \\
123139
39
124-
\end{bmatrix}`
140+
\end{bmatrix}
125141
$$</p>
126142
<p>This is equivalent to
127143
$$
128-
<code>\begin{bmatrix} 0.72 &amp; 0.05 &amp; 0.1 \\\\ 0.1 &amp; 0.75 &amp; 0.15 \\\\ 0.18 &amp; 0.2 &amp; 0.75 \end{bmatrix} ^ 3 \cdot </code>\begin{bmatrix}
144+
\begin{bmatrix}
145+
0.72 &amp; 0.05 &amp; 0.1 \\
146+
0.1 &amp; 0.75 &amp; 0.15 \\
147+
0.18 &amp; 0.2 &amp; 0.75
148+
\end{bmatrix}^3
149+
\cdot
150+
\begin{bmatrix}
129151
50 \\
130-
30 \\
152+
30 \\
131153
20
132-
\end{bmatrix}<code> = \begin{bmatrix} 28.9 \\\\ 32.1 \\\\ 39 \end{bmatrix}</code>
154+
\end{bmatrix}
155+
= \begin{bmatrix}
156+
28.9 \\
157+
32.1 \\
158+
39
159+
\end{bmatrix}
133160
$$</p>
134161
<p>,which is raising the matrix to the power of the year, and multiply by the initial population vector.</p>
135162
<p> <br>
@@ -142,29 +169,62 @@ <h2 id="stationary-distribution">Stationary distribution</h2>
142169
 </p>
143170
<p>Here we use initial population vector <code>\([50, 30, 20]\)</code>, and we calculate the population after 20 years:</p>
144171
<p>$$
145-
<code>\begin{bmatrix} 0.72 &amp; 0.05 &amp; 0.1 \\\\ 0.1 &amp; 0.75 &amp; 0.15 \\\\ 0.18 &amp; 0.2 &amp; 0.75 \end{bmatrix} ^ {20} \cdot </code>\begin{bmatrix}
172+
\begin{bmatrix}
173+
0.72 &amp; 0.05 &amp; 0.1 \\
174+
0.1 &amp; 0.75 &amp; 0.15 \\
175+
0.18 &amp; 0.2 &amp; 0.75
176+
\end{bmatrix}^{20}
177+
\cdot
178+
\begin{bmatrix}
146179
50 \\
147-
30 \\
180+
30 \\
148181
20
149-
\end{bmatrix}<code> = \begin{bmatrix} 21.7 \\\\ 34.8 \\\\ 43.5 \end{bmatrix}</code>
182+
\end{bmatrix}
183+
= \begin{bmatrix}
184+
21.7 \\
185+
34.8 \\
186+
43.5
187+
\end{bmatrix}
150188
$$</p>
151189
<p>Here is the population after 50 years:
152190
$$
153-
<code>\begin{bmatrix} 0.72 &amp; 0.05 &amp; 0.1 \\\\ 0.1 &amp; 0.75 &amp; 0.15 \\\\ 0.18 &amp; 0.2 &amp; 0.75 \end{bmatrix} ^ {50} \cdot </code>\begin{bmatrix}
191+
\begin{bmatrix}
192+
0.72 &amp; 0.05 &amp; 0.1 \\
193+
0.1 &amp; 0.75 &amp; 0.15 \\
194+
0.18 &amp; 0.2 &amp; 0.75
195+
\end{bmatrix}^{50}
196+
\cdot
197+
\begin{bmatrix}
154198
50 \\
155-
30 \\
199+
30 \\
156200
20
157-
\end{bmatrix}<code> = \begin{bmatrix} 21.7 \\\\ 34.8 \\\\ 43.5 \end{bmatrix}</code>
201+
\end{bmatrix}
202+
= \begin{bmatrix}
203+
21.7 \\
204+
34.8 \\
205+
43.5
206+
\end{bmatrix}
158207
$$</p>
159208
<p> <br>
160209
 </p>
161210
<p>In a parallel universe, at year-0, we have 100 people in NY, 0 people in Boston, and 0 people in Houston. However, after 20 years, we achieve the same population across these three cities:</p>
162211
<p>$$
163-
<code>\begin{bmatrix} 0.72 &amp; 0.05 &amp; 0.1 \\\\ 0.1 &amp; 0.75 &amp; 0.15 \\\\ 0.18 &amp; 0.2 &amp; 0.75 \end{bmatrix} ^ {20} \cdot </code>\begin{bmatrix}
212+
\begin{bmatrix}
213+
0.72 &amp; 0.05 &amp; 0.1 \\
214+
0.1 &amp; 0.75 &amp; 0.15 \\
215+
0.18 &amp; 0.2 &amp; 0.75
216+
\end{bmatrix}^{20}
217+
\cdot
218+
\begin{bmatrix}
164219
100 \\
165-
0 \\
220+
0 \\
166221
0
167-
\end{bmatrix}<code> = \begin{bmatrix} 21.7 \\\\ 34.8 \\\\ 43.5 \end{bmatrix}</code>
222+
\end{bmatrix}
223+
= \begin{bmatrix}
224+
21.7 \\
225+
34.8 \\
226+
43.5
227+
\end{bmatrix}
168228
$$</p>
169229
<p> <br>
170230
 </p>
@@ -191,18 +251,38 @@ <h2 id="a-trillion-dollar-model">A trillion dollar model</h2>
191251
<p>Intuitively, pageA and pageC look like good pages, since a lot of other websites referred these two pages. A user will typically follow the hyperlinks to browse the website. For example, if a user is currently browsing pageC, the next moment, this user will have 50% of the chance to go to pageD, and 50% of the chance to go to pageA. Based on this graph, we can specify the transition matrix</p>
192252
<p>(note row/column order from pageA - pageE):</p>
193253
<p>$$
194-
<code>\begin{bmatrix} 0 &amp; 1 &amp; 0.5 &amp; 0 &amp; 0.5\\\\ 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\ 1 &amp; 0 &amp; 0 &amp; 1 &amp; 0 \\\\ 0 &amp; 0 &amp; 0.5 &amp; 0 &amp; 0 \\\\ 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0.5 \end{bmatrix}</code>
195-
$$</p>
196-
<p>Now assume we have 100 random users, with 20 users in each page. Using the same technique we have discussed above, we can calculate the stationary distribution (a.k.a, how many random users in each page eventually).</p>
254+
\begin{bmatrix}
255+
0 &amp; 1 &amp; 0.5 &amp; 0 &amp; 0.5\\
256+
0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\
257+
1 &amp; 0 &amp; 0 &amp; 1 &amp; 0 \\
258+
0 &amp; 0 &amp; 0.5 &amp; 0 &amp; 0 \\
259+
0 &amp; 0 &amp; 0 &amp; 0 &amp; 0.5
260+
\end{bmatrix}
261+
$$
262+
Now assume we have 100 random users, with 20 users in each page. Using the same technique we have discussed above, we can calculate the stationary distribution (a.k.a, how many random users in each page eventually).</p>
197263
<p>$$
198-
<code>\begin{bmatrix} 0 &amp; 1 &amp; 0.5 &amp; 0 &amp; 0.5\\\\ 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\\\ 1 &amp; 0 &amp; 0 &amp; 1 &amp; 0 \\\\ 0 &amp; 0 &amp; 0.5 &amp; 0 &amp; 0 \\\\ 0 &amp; 0 &amp; 0 &amp; 0 &amp; 0.5 \end{bmatrix}^{50} \cdot </code>\begin{bmatrix}
264+
\begin{bmatrix}
265+
0 &amp; 1 &amp; 0.5 &amp; 0 &amp; 0.5\\
266+
0 &amp; 0 &amp; 0 &amp; 0 &amp; 0 \\
267+
1 &amp; 0 &amp; 0 &amp; 1 &amp; 0 \\
268+
0 &amp; 0 &amp; 0.5 &amp; 0 &amp; 0 \\
269+
0 &amp; 0 &amp; 0 &amp; 0 &amp; 0.5
270+
\end{bmatrix}^{20}
271+
\cdot
272+
\begin{bmatrix}
273+
20 \\
274+
20 \\
275+
20 \\
199276
20 \\
200-
20 \\
201-
20 \\
202-
20 \\
203277
20
204-
\end{bmatrix} =
205-
<code>\begin{bmatrix} 23.3 \\\\ 0 \\\\ 53.4 \\\\ 23.3 \\\\ 0 \end{bmatrix}</code>
278+
\end{bmatrix}
279+
= \begin{bmatrix}
280+
23.3 \\
281+
0 \\
282+
53.4 \\
283+
23.3 \\
284+
0
285+
\end{bmatrix}
206286
$$</p>
207287
<p>According to the PageRank algorithm, eventually we will have 53.4 users landing on pageC, and therefore pageC has the highest quality and should be recommended as the top page to the users.</p>
208288
<p> </p>

0 commit comments

Comments
 (0)