ì ¡
Probability ¡and ¡Statistics ¡ for ¡Computer ¡Science ¡ ¡
“All ¡models ¡are ¡wrong, ¡but ¡some ¡ models ¡are ¡useful”-‑-‑-‑ ¡George ¡Box ¡ ¡ ¡
Hongye ¡Liu, ¡Teaching ¡Assistant ¡Prof, ¡CS361, ¡UIUC, ¡12.10.2019 ¡ Credit: ¡wikipedia ¡
Probability and Statistics for Computer Science All - - PowerPoint PPT Presentation
Probability and Statistics for Computer Science All models are wrong, but some models are useful--- George Box Credit:
“All ¡models ¡are ¡wrong, ¡but ¡some ¡ models ¡are ¡useful”-‑-‑-‑ ¡George ¡Box ¡ ¡ ¡
Hongye ¡Liu, ¡Teaching ¡Assistant ¡Prof, ¡CS361, ¡UIUC, ¡12.10.2019 ¡ Credit: ¡wikipedia ¡
✺ Linear ¡regression ¡(cont.) ¡
✺ Modeling ¡non-‑linear ¡relaRonship ¡with ¡linear ¡
regression ¡
✺ Outliers ¡and ¡over-‑fiVng ¡issues ¡ ✺ Regularized ¡linear ¡regression/Ridge ¡regression ¡
✺ Nearest ¡neighbor ¡regression ¡
✺ A ¡linear ¡model ¡will ¡
not ¡produce ¡a ¡good ¡ fit ¡if ¡the ¡dependent ¡ variable ¡is ¡not ¡linear ¡ combinaRon ¡of ¡the ¡ explanatory ¡variables ¡ ¡ ¡ ¡ ¡
R2 ¡= ¡0.1 ¡
✺ In ¡the ¡word-‑ ¡frequency ¡
example, ¡log-‑transforming ¡ both ¡variables ¡would ¡ allow ¡a ¡linear ¡model ¡to ¡fit ¡ the ¡data ¡well. ¡ ¡
¡ ¡
Yellow ¡Perch ¡
✺ Perch ¡(a ¡kind ¡of ¡fish) ¡in ¡a ¡
lake ¡in ¡Finland, ¡56 ¡data ¡
✺ Variables ¡include: ¡Weight, ¡
Length, ¡Height, ¡Width ¡
✺ In ¡order ¡to ¡illustrate ¡the ¡
point, ¡let’s ¡model ¡Weight ¡ as ¡the ¡dependent ¡variable ¡ and ¡the ¡Length ¡as ¡the ¡ explanatory ¡variable. ¡
¡
✺ R-‑squared ¡is ¡0.87 ¡may ¡
suggest ¡the ¡model ¡is ¡ OK ¡
✺ But ¡the ¡trend ¡of ¡the ¡
data ¡suggests ¡non-‑ linear ¡relaRonship ¡
✺ IntuiRon ¡tells ¡us ¡length ¡
is ¡not ¡linear ¡to ¡weight ¡ given ¡fish ¡is ¡3-‑ dimensional ¡
✺ We ¡can ¡do ¡befer! ¡
Length3 ¡ Weight ¡ 1 ¡
✺ Markov ¡chain ¡ ✺ MoRvaRon ¡ ✺ DefiniRon ¡of ¡Markov ¡model ¡ ✺ Graph ¡representaRon ¡– ¡Markov ¡chain ¡ ✺ TransiRon ¡probability ¡matrix ¡ ✺ The ¡staRonary ¡Markov ¡chain ¡ ✺ The ¡pageRank ¡algorithm ¡
✺ So ¡far, ¡the ¡processes ¡we ¡learned ¡such ¡as ¡
✺ There ¡are ¡a ¡lot ¡of ¡real ¡world ¡situaRons ¡where ¡
✺ Markov ¡chain ¡is ¡one ¡type ¡of ¡characterizaRon ¡
I ¡had ¡a ¡glass ¡of ¡wine ¡with ¡my ¡grilled ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡
✺ Markov ¡chain ¡is ¡a ¡process ¡
✺ Such ¡dependence ¡is ¡called ¡
Andrey ¡Markov ¡(1856-‑1922) ¡
✺ Let ¡ ¡ ¡ ¡ ¡ ¡, ¡ ¡ ¡ ¡ ¡ ¡,… ¡be ¡a ¡sequence ¡of ¡discrete ¡finite-‑valued ¡
random ¡variables ¡ ¡
✺ The ¡sequence ¡is ¡a ¡Markov ¡chain ¡if ¡the ¡probability ¡
distribuRon ¡ ¡ ¡ ¡ ¡ ¡only ¡depends ¡on ¡the ¡distribuRon ¡of ¡the ¡ immediately ¡preceding ¡random ¡variable ¡
✺ If ¡the ¡condiRonal ¡probabiliRes ¡(transiRon ¡probabiliRes) ¡
do ¡NOT ¡change ¡with ¡6me, ¡it’s ¡called ¡constant ¡Markov ¡
P(Xt|X0..., Xt−1) = P(Xt|Xt−1)
P(Xt|Xt−1) = P(Xt−1|Xt−2) = ... = P(X1|X0) X0 X1 Xt Xt−1
✺ Toss ¡a ¡fair ¡coin ¡unRl ¡you ¡see ¡two ¡heads ¡in ¡a ¡row ¡and ¡
then ¡stop, ¡what ¡is ¡the ¡probability ¡of ¡stopping ¡aker ¡ exactly ¡n ¡flips? ¡ ¡
✺ Use ¡a ¡state ¡diagram, ¡which ¡is ¡a ¡directed ¡graph. ¡Circles ¡
are ¡the ¡states ¡of ¡likely ¡outcomes. ¡Arrow ¡direcRons ¡show ¡the ¡ direcRon ¡of ¡transiRons. ¡Numbers ¡over ¡the ¡arrows ¡show ¡ transiRon ¡probabiliRes. ¡ ¡ ¡
3 ¡ 1 ¡-‑> ¡Start ¡or ¡just ¡had ¡tail/restart ¡ 2 ¡-‑> ¡had ¡one ¡head ¡aJer ¡start/restart ¡ 3 ¡-‑> ¡2heads ¡in ¡a ¡row/Stop ¡ 1/2 ¡ 1/2 ¡ 1/2 ¡ 1/2 ¡
3 ¡ 1/2 ¡ 1/2 ¡ 1/2 ¡ 1/2 ¡
3 ¡ 1/2 ¡ 1/2 ¡ 1/2 ¡ 1/2 ¡
✺ Let ¡ ¡ ¡ ¡ ¡ ¡ ¡be ¡the ¡probability ¡of ¡stopping ¡aker ¡n ¡flips ¡ ¡ ✺ If ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡, ¡there ¡are ¡two ¡ways ¡the ¡sequence ¡starts ¡
✺ Toss ¡T ¡and ¡finish ¡in ¡n-‑1 ¡tosses ¡ ✺ Or ¡toss ¡HT ¡and ¡finish ¡in ¡n-‑2 ¡tosses ¡
✺ So ¡we ¡can ¡derive ¡a ¡recurrence ¡relaRon ¡
p1 = 0 p2 = 1/4 p3 = 1/8 p4 = 1/8 n > 2
pn = 1 2pn−1 + 1 4pn−2
… ¡
✺ Let’s ¡model ¡daily ¡weather ¡as ¡one ¡of ¡the ¡three ¡states ¡
(Sunny, ¡Rainy, ¡and ¡Snowy) ¡with ¡Markov ¡chain ¡that ¡ has ¡the ¡transiRon ¡probabiliRes ¡as ¡shown ¡here. ¡
0.7 ¡ 0.6 ¡ 0.5 ¡ 0.2 ¡ 0.2 ¡ 0.1 ¡ 0.4 ¡ 0.1 ¡ 0.2 ¡
✺ Let’s ¡model ¡daily ¡weather ¡as ¡one ¡of ¡the ¡three ¡states ¡
(Sunny, ¡Rainy, ¡and ¡Snowy) ¡with ¡Markov ¡chain ¡that ¡ has ¡the ¡transiRon ¡probabiliRes ¡as ¡shown ¡here. ¡
0.7 ¡ 0.6 ¡ 0.5 ¡ 0.2 ¡ 0.2 ¡ 0.1 ¡ 0.4 ¡ 0.1 ¡ 0.2 ¡
Sunny ¡ Rainy ¡ Snowy ¡ Sunny ¡ Rainy ¡ Snowy ¡ i, ¡the ¡current ¡state ¡at ¡Rme ¡point ¡t ¡ j, ¡the ¡next ¡state ¡at ¡Rme ¡point ¡t+1 ¡
The ¡transiRon ¡probability ¡matrix ¡
1 ¡ 2 ¡ 3 ¡
✺ The ¡transiRon ¡probability ¡matrix ¡ ¡ ¡ ¡ ¡is ¡a ¡square ¡matrix ¡ ¡
with ¡entries ¡ ¡
✺ Since ¡ ¡
¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡
pij
P
pij ≥ 0
pij = 1
and ¡
Sunny ¡ Rainy ¡ Snowy ¡ Sunny ¡ Rainy ¡ Snowy ¡
The ¡transiRon ¡probability ¡matrix ¡
✺ Let ¡ ¡ ¡ ¡ ¡ ¡be ¡a ¡row ¡vector ¡containing ¡the ¡probability ¡
distribuRon ¡over ¡states ¡at ¡t=0 ¡
✺ For ¡example: ¡if ¡it ¡is ¡rainy ¡today, ¡and ¡today ¡is ¡t=0, ¡then ¡ ¡ ✺ Let ¡P(t) ¡ ¡be ¡a ¡row ¡vector ¡containing ¡the ¡probability ¡
distribuRon ¡over ¡states ¡at ¡Rme ¡point ¡t ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡
P (1)
j
= P(X1 = j)
=
P(X1 = j, X0 = i) =
P(X1 = j|X0 = i)P(X0 = i) =
pijπi
✺ PropagaRng ¡from ¡t=0 ¡to ¡t=1, ¡ ✺ In ¡matrix ¡notaRon, ¡
p(1) = πP
✺ Suppose ¡that ¡it ¡is ¡rainy, ¡we ¡have ¡the ¡iniRal ¡probability ¡
✺ What ¡are ¡the ¡probability ¡distribuRons ¡for ¡tomorrow ¡
and ¡the ¡day ¡aker ¡tomorrow? ¡
p(1) = πP
✺ We ¡have ¡just ¡seen ¡that ¡ ¡ ✺ So ¡in ¡general ¡ ¡
p(2) = p(1)P = (πP)P = πP 2
✺ If ¡one ¡state ¡can ¡be ¡reached ¡from ¡any ¡other ¡state ¡in ¡the ¡
graph, ¡the ¡Markov ¡chain ¡is ¡called ¡irreducible ¡(single ¡chain). ¡
✺ Furthermore ¡, ¡if ¡it ¡saRsfies: ¡
¡then ¡the ¡Markov ¡chain ¡is ¡staRonary ¡and ¡S ¡is ¡the ¡ ¡staRonary ¡distribuRon. ¡
✺ The ¡staRonary ¡distribuRon ¡ ¡ ¡ ¡ ¡ ¡has ¡the ¡following ¡
property: ¡ ¡
✺ ¡ ¡ ¡ ¡is ¡a ¡row ¡eigenvector ¡of ¡P ¡with ¡eigenvalue ¡1 ¡ ¡ ✺ In ¡the ¡example ¡of ¡the ¡weather ¡model, ¡regardless ¡of ¡
the ¡iniRal ¡distribuRon, ¡
S = lim
t→∞ π
0.7 0.2 0.1 0.2 0.6 0.2 0.4 0.1 0.5
t
= 18
37 11 37 8 37
1 ¡ 2 ¡
0.2 ¡ 0.6 ¡ 0.8 ¡ 0.4 ¡
State ¡1: ¡Up-‑to-‑date ¡ State ¡2: ¡Behind ¡
What’s ¡the ¡transi6on ¡matrix? ¡ If ¡I ¡start ¡with ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡, ¡what ¡is ¡ my ¡probability ¡of ¡being ¡up-‑to-‑ date ¡eventually? ¡ ¡
3 ¡ 1 ¡ 2 ¡
1.0 ¡ 1.0 ¡ 0.5 ¡ 0.5 ¡
3 ¡ 0.5 ¡ 0.5 ¡ 0.5 ¡ 0.5 ¡
✺ How ¡to ¡rate ¡web ¡pages ¡objecRvely? ¡ ✺ The ¡PageRank ¡algorithm ¡by ¡Page ¡et ¡al. ¡made ¡Google ¡
successful ¡
✺ The ¡method ¡uRlized ¡Markov ¡chain ¡model ¡and ¡applied ¡
it ¡to ¡the ¡large ¡list ¡of ¡webpages. ¡
✺ To ¡illustrate ¡the ¡point, ¡we ¡use ¡a ¡small-‑size ¡example ¡
and ¡assume ¡a ¡simple ¡sta6onary ¡model. ¡
A ¡ B ¡ C ¡
0.5 ¡ 0.5 ¡
D ¡ E ¡ H ¡ F ¡ G ¡
A ¡ B ¡ C ¡
0.5 ¡ 0.5 ¡
D ¡ E ¡ H ¡ F ¡ G ¡
t ¡= ¡0 ¡ 1/8 ¡ 1/8 ¡ 1/8 ¡ 1/8 ¡ 1/8 ¡ 1/8 ¡ 1/8 ¡ 1/8 ¡
A ¡ B ¡ C ¡
0.5 ¡ 0.5 ¡
D ¡ E ¡ H ¡ F ¡ G ¡
t ¡= ¡1 ¡ 8/16 ¡ 1/16 ¡ 1/16 ¡ 1/16 ¡ 1/16 ¡ 1/16 ¡ 2/16 ¡ 1/16 ¡
A ¡ B ¡ C ¡
0.5 ¡ 0.5 ¡
D ¡ E ¡ H ¡ F ¡ G ¡
t ¡= ¡∞ ¡ 4/13 ¡ 2/13 ¡ 1/13 ¡ 1/13 ¡ 2/13 ¡ 1/13 ¡ 1/13 ¡ 1/13 ¡
A ¡ B ¡ C ¡
0.5 ¡ 0.5 ¡
D ¡ E ¡ H ¡ F ¡ G ¡
t ¡= ¡ 4/13 ¡ 2/13 ¡ 1/13 ¡ 1/13 ¡ 2/13 ¡ 1/13 ¡ 1/13 ¡ 1/13 ¡
✺ Allow ¡“teleport” ¡with ¡
small ¡probability ¡from ¡ any ¡page ¡to ¡another ¡
✺ Or ¡allow ¡“teleport” ¡
with ¡user ¡input ¡of ¡URL ¡
✺ CommunicaRon ¡network ¡ ✺ Queue ¡modeling ¡ ✺ DNA ¡sequence ¡modeling ¡ ✺ Natural ¡language ¡processing ¡ ✺ Single-‑cell ¡large ¡data ¡analysis ¡ ✺ Financial/Economic ¡model ¡ ✺ Music ¡
✺ CommunicaRon ¡network ¡ ✺ Queue ¡modeling ¡ ✺ DNA ¡sequence ¡modeling ¡ ✺ Natural ¡language ¡processing ¡ ✺ Single-‑cell ¡large ¡data ¡analysis ¡ ✺ Financial/Economic ¡model ¡ ✺ Music ¡
0.7 ¡ 0.6 ¡ 0.5 ¡ 0.2 ¡ 0.2 ¡ 0.1 ¡ 0.4 ¡ 0.1 ¡ 0.2 ¡
✺ Time: ¡1:30pm ¡Mon. ¡Dec. ¡16 ¡ ✺ Place: ¡in ¡class, ¡DCL1320 ¡ ✺ DuraRon: ¡2hr30mins ¡ ✺ Content ¡coverage: ¡Ch1-‑14, ¡except ¡8 ¡ ✺ Note ¡sheet: ¡2 ¡pages ¡(double ¡sided) ¡hand ¡wrifen ¡or ¡1 ¡page ¡
(double ¡sided, ¡not ¡limited ¡to ¡hand ¡wrifen) ¡
✺ Office ¡hours: ¡Instructor ¡is ¡having ¡open ¡office ¡policy. ¡TAs ¡don’t ¡
have ¡regular ¡OH, ¡but ¡may ¡be ¡available ¡upon ¡requests ¡
¡
✺
Ten ¡years ¡from ¡now ¡I’ll ¡probably ¡remember ¡this ¡course ¡most ¡by ¡
✺
The ¡instructor’s ¡concern ¡for ¡students ¡
✺
The ¡aspects ¡of ¡the ¡course ¡which ¡you ¡found ¡most ¡valuable ¡
✺
The ¡aspects ¡of ¡the ¡course ¡which ¡you ¡found ¡least ¡valuable ¡
✺
My ¡moRvaRon ¡to ¡do ¡well ¡in ¡this ¡course ¡
✺
The ¡type ¡of ¡instrucRon ¡which ¡would ¡be ¡most ¡beneficial ¡for ¡this ¡course ¡
✺
Your ¡effort ¡in ¡this ¡course ¡
✺
Would ¡you ¡be ¡interested ¡in ¡becoming ¡a ¡tutor ¡for ¡the ¡subject? ¡
¡