-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaicourse.tex
4381 lines (3240 loc) · 167 KB
/
aicourse.tex
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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\documentclass[a4, 12pt, english, USenglish]{scrreprt}
% \usepackage{venn}
\usepackage[latin1]{inputenc}
\usepackage{makeidx}
\usepackage{pdftricks}
\usepackage[final]{pdfpages}
\usepackage{geometry, upgreek, booktabs, babel}
\usepackage[journal=rsc,xspace=true]{chemstyle}
\usepackage[version=3]{mhchem}
% \usepackage[footnotes]{notes2bib}
\usepackage[final]{microtype}
\usepackage[final, inactive]{pst-pdf}
\usepackage[colorlinks]{hyperref}
% equals with a "set" on top
\newcommand{\defeq}{\ensuremath{\stackrel{\mbox{set}{=}}}}
% XXX Should put a little arrow above its parameter.
\newcommand{\vectorXX}[1]{\ensuremath{#1}}
\newcommand{\fApartial}[1]{\ensuremath{\frac{\partial f}{\partial A_{#1}}}}
\newcommand{\jpartial}[1]{\ensuremath{\frac{\partial J}{\partial \theta_{#1}}}}
\newcommand{\thetaipartial}{\ensuremath{\frac{\partial}{\partial{\theta_i}}}}
\newcommand{\thetapartial}{\ensuremath{\frac{\partial}{\partial{\theta}}}}
\newcommand{\half}{\ensuremath{\frac{1}{2}}}
\newcommand{\sumim}{\ensuremath{\sum_{i=1}^{m}}}
\newcommand{\intinf}{\ensuremath{\int_{-\infty}^{\infty}}}
\newcommand{\Ft}{\ensuremath{{\cal{F}}}}
\newcommand{\ft}[1]{\ensuremath{{\cal{F}}({#1})}}
\newcommand{\sinc}[1]{\ensuremath{\mbox{sinc}{#1}}}
\newcommand{\screenshot}[2]{
\begin{figure}[htb]
\includegraphics[width=150mm]{screenshots/#1.jpg}
\label{#1}
\caption{#2}
\end{figure}}
\newcommand{\bb}[1]{\ensuremath{{\bf{#1}}}} % XXX Should be blackboard bold
\newcommand{\proj}[2]{\ensuremath{{\bb {#1}}_{#2}}}
\newcommand{\braces}[1]{\ensuremath{\left\{{#1}\right\}}}
\newcommand{\brackets}[1]{\ensuremath{\left\[{#1}\right\]}}
\newcommand{\parens}[1]{\ensuremath{\left({#1}\right)}}
\newcommand{\absval}[1]{\ensuremath{\left|{#1}\right|}}
\newcommand{\sqbraces}[1]{\ensuremath{\left[{#1}\right]}}
\newcommand{\commutator}[2]{\sqbraces{{#1}, {#2}}}
\newcommand{\dyad}[1]{\ensuremath{\ket{{#1}}\bra{{#1}}}}
\newcommand{\trace}[1]{\ensuremath{\mbox{tr}\, {#1} }}
\newcommand{\erfc}[1]{\mbox{erfc}\left(#1\right)}
\newcommand{\mXXX}[1]{\marginpar{\tiny{\bf Rmz:} {\it #1}}}
\newcommand{\celcius}{\ensuremath{^\circ}C}
\newcommand{\ev}[1]{\ensuremath{\left\langle{}#1{}\right\rangle}}
\newcommand{\ket}[1]{\ensuremath{\mid{}#1{}\rangle}}
\newcommand{\bra}[1]{\ensuremath{\langle{}#1{}\mid}}
\newcommand{\braKet}[2]{\ensuremath{\left\langle{}#1{}\mid{#2}\right\rangle}}
\newcommand{\BraKet}[3]{\ensuremath{\left\langle{}#1{}\mid{#2}\mid{#3}\right\rangle}}
\newcommand{\evolvesto}[2]{\ensuremath{{#1}\mapsto{#2}}}
\newcommand{\inrange}[3]{\ensuremath{{#1} \in \braces{{#2}, \ldots,{#3}}}}
\newenvironment{wikipedia}[1]
{
{\bf From wikipedia: {\it #1}}
\begin{quote}
}
{
\end{quote}
}
\newcommand{\idx}[1]{{\em #1}\index{#1}}
\newcommand{\idX}[1]{{#1}\index{#1}}
\usepackage{url}
\newcommand{\tm}{\ensuremath{^{\mbox{tm}}}}
\newcommand{\aangstrom}{\AA{}ngstr\"{o}m{}\ }
%\newcommand{\aaunit}{\mbox{\AA}} % Just use A with ring, once encoding works properly
\newcommand{\aaunit}{\angstrom} % Just use A with ring, once encoding works properly
\newcommand{\munchen}{M\"unchen}
\newcommand{\zurich}{Z\"urich}
\newcommand{\schrodinger}{Schr\"odinger}
\newcommand{\ReneJustHauy}{Ren\'e-Just Ha\"uy}
%% Lavousier (with a lot fo weird spelling)
%% Crystallographic notation
%Coordinate
\newcommand{\crCoord}[3]{\mbox{\(#1,#2,#3\)}}
%Direction
\newcommand{\crDir}[3]{\mbox{\(\left[#1 #2 #3\right]\)}}
%Family of directions
\newcommand{\crDirfam}[3]{\mbox{\(\left<{}#1 #2 #3\right>\)}}
%Plane
\newcommand{\crPlane}[3]{\mbox{\(\left(#1 #2 #3\right)\)}}
%Family of planes
\newcommand{\crPlanefam}[3]{\left\{#1 #2 #3\right\}}
\newcommand{\oneCol}[2]{
\ensuremath{\left(\begin{array}{r}{#1}\\{#2}\end{array}\right)}
}
\newcommand{\twoCol}[4]{
\ensuremath{\left(\begin{array}{rr}{#1}&{#2}\\{#3}&{#4}\end{array}\right)}
}
%Negative number
\newcommand{\crNeg}[1]{\bar{#1}}
\makeindex
\begin{document}
\title{Lecture notes from the \\
online Artificial Intelligence course\\
tought by Peter Norvig and Sebatian Thrun \\
fall 2011}
\author{Bj\o{}rn Remseth \\ [email protected]}
\maketitle
\tableofcontents
% Comment out this in final version!
\parskip=\bigskipamount
\parindent=0pt.
\begin{abstract}
\end{abstract}
\chapter*{Introduction}
These are my notes from the course ``Artificial Intelligence'' taught
by Peter Norvig and Sebastian Thrun, fall 2011.
Unfortunately I lost my notes for module one and two in a freakish
accident involving emacs, to goats and a midget, so these notes start
from module three.
I usually watched the videos while typing notes in \LaTeX. I have
experimented with various note-taking techniques including free text,
mindmaps and handwritten notes, but I ended up using \LaTeX, since
it's not too hard, it gives great readability for the math that
inevitably pops up in the things I like to take notes about, and it's
easy to include various types of graphics. The graphics in this video
is exclusively screenshots copied directly out of the videos, and to a
large extent, but not completely, the text is based on Ng's
narrative. I haven't been very creative, that wasn't my purpose. I
did take more screenshots than are actually available in this text.
Some of them are indicated in figures stating that a screenshot is
missing. I may or may not get back to putting these missing
screenshots back in, but for now the are just not there. Deal with
it :-)
A word of warning: These are just my notes. They should't be
interpreted as anything else. I take notes as an aid for myself.
When I take notes I find myself spending more time with the subject at
hand, and that alone lets me remember it better. I can also refer to
the notes, and since I've written them myself, I usually find them
quite useful. I state this clearly since the use of \LaTeX\ will
give some typographical cues that may lead the unwary reader to
believe that this is a textbook or something more ambitious. It's
not. This is a learning tool for me. If anyone else reads this and
find it useful, that's nice. I'm happy, for you, but I didn't have
that, or you in mind when writing this. That said, if you have any
suggestions to make the text or presentation better, please let me
know. My email address is [email protected].
Source code for this document can be found at github
\url{https://github.com/la3lma/aiclassnotes}, a fully processed pdf
file can be found at \url{http://dl.dropbox.com/u/187726/ai-course-notes.pdf}.
\chapter{Module three: Probability in AI}
\mXXX{It is a really good idea to go over those initial modules again
before the final exam. There will be questions, and it needs to be grokked.}
\subsection{Introduction}
Involved material. Bayes networks.
Why won't your car start?. Perhaps a flat battery. Perhaps the battery is dead,
or it's not charging, which in turn be caused by the fanbelt or the
alternator being broken. These set of relationships is a called a bayes network.
We can introduce things to inspect which can be used (lights, oi, gas,
dipstick) etc. Causes affect measurements.
\screenshot{bayesnetwork1}{A Bayes network from the lectures}
Things we cannot measure immediately and measurements we can observe.
The bayes network helps us to reason with hidden causes based on
observable events.
A bayes network consists of nodes and arcs. The non-observable nodes
are called random (or stochastic) variables. The child of a node is
infered in a probabilistic way.
The graph structure and associated probability structure the network
is a compact representation of a very large joint probability
distribution.
With the network in place, we can compute probabilities of the random
variables. We'll talk about how to construct bayes network and to use
them to reason about non-observable variables
Assumptions:
\begin{itemize}
\item Binary events
\item Probability
\item Simple bayes networks
\item Conditional independence
\item Bayes neworks
\item D-separation
\item Paramemeter coount
\item later: Inferences based on bayes networks.
\end{itemize}
B-networks is really imporant, used in diagnostics, predictions,
machine learning. Finance, google, robotics. Also used as basis for
\idx{particle filters}, \idx{hidden markov models}, \idx{MDP}s and \idx{POMDP}s, \idx{Kalman
filters} and others.
\subsection{Probabilities}
Used to express uncertainty. Given a coin with probability for
coming u heads is \( P(H) = 1/2\) the probaility of getting tails is 1/2.
The sum of the probabilities is always one.
Complementary probability (1-p).
\subsection{Independence:}
\[X\bot Y : P(X)P(Y) = P(X, Y) \]
where \(P(X)\) and \(P(Y)\) are called \idx{marginals}.
\subsection{Dependence:}
\subsubsection{Dependence:}
\subsubsection{Notation}
\[ P(X_1) = 1/2 \]
For one coin we have \(H: P(X_2=H | X_1=H) = 0.9\) for another coin
we have \(H: P(X_2=T | X_1=T) = 0.8\)
The probability of the second coin being heads is 0.55. The
calculation is \(0.5 * 0.2 + 0.5 * 0.9 = 0.55\), and amazingly that
took me several minutes to figure out, and I needed to draw
a tree and do the sums to get the answer right. It's obvious I need
this refresher course :-)
\subsubsection{Lessons}
The probability of some variable
\[
P(Y) = \sum_i P(Y|X=i) P(X=i)
\]
this is called the \idx{total probability}. The negation of a probabilityu
\[
P(\neg X | Y) = 1 - P(X|Y)
\]
\subsubsection{Cancer}
One percent cancer in the population. Probability of a positive test
if you have the cancer \(P(+|C) =0.9 \). The probability of a
negative result if you don't have the cancer, \(P(+|C) =0.1 \).
The probability of the test coming out positive if you don't have the
cancer is \(P(+|\neg C) = 0.2 \), the probability of the test being
negative if you don't have the cancer is \(P(-|\neg C) = 0.8 \).
Join probabilities (probability of having a positive test with cancer
and negative without (etc.)).
\subsubsection{The Bayes Rule. }
Thomas Bayes, presbytarian minister. Bayes Theorem is:
\[
P(A|B) = \frac{P(A|B) \cdot P(A)}{P(B)}
\]
The terms are: The \idx{likelyhood} = \(P(B|A)\), the \idx{prior likelyhood} =
\(P(A)\), and the \idx{marginal likelyhood} = \(P(B)\). \idx{the
posterior} = \(P(A|B)\).
The interesting thing is the way that the probabilities are reverted.
We don't really care about the evidedence, we care if we have cancer
or not.
The \idx{marginal likelyhood} is in turn denoted as the \idx{total
probability} of \(B\):
\[
P(B) = \sum_a P(B|A=a) P(A=a)
\]
In the cancer case we are interested in:
\[
\begin{array}{lcl}
P(C|+) &=&\frac{P(+|C)\cdot P(C)}{P(+)} \\
&=& \frac{0.9 \cdot 0.01}{(0.9 \cdot 0.01) + (0.2 \cdot 0.99)} \\
&=& \frac{0.009}{0.009+ 0.198} \\
&=& 0.0434
\end{array}
\]
The Bayes Rule can be drawn graphically. Two variables. B
observable, A not. A causes B to be positive with some probability
\(P(B|A)\). What we care about is \idx{diagnostic reasoning} which is
the inverse of the \idx{causal reasoning}. The graphical
representation is a graph with an arrow going from A to B.
To fully specify a Bayes network with one observable and one
non-observable, we need three parameters: The observed probability (of
the observable), the conditional probability of the non-observable
being true in the case of the observable being true, and the
probability of the non-observable being true when the observable is
false.
\subsubsection{Computing bayes rule}
Given the rule
\[
P(A|B) = \frac{P(A|B) \cdot P(A)}{P(B)}
\]
the denominator is relatively easy to calculate since it's just a
product. The total probability (the divisor) is really hard to
compute since it is a sum over potentially many terms. However, the
denominator isn't dependent on the thing we're trying to find the
probability for. If for instance we are interested in
\[
P(\neg A|B) = \frac{P(\neg A|B) \cdot P(\neg A)}{P(B)}
\]
we use the same denominator. We also know that \(P(A|B) + A(\neg A|B)
= 1\) since these are \idx{compementary events}. This allows us to
compute the bayes rule very differently by ignoring the normalizer.
First we calculate \idx{pseudoprobabilities}
\[
\begin{array}{lcl}
P'(A|B) &=& P(B|A) P(A) \\
P'(\neg A|B) &=& P(B|\neg A) P(\neg A) \\
\end{array}
\]
then we normalize by multiplying the pseudoprobabilities with a
\idx{normalizer} (eta)
\(\eta = \parens{P'(A|B) + P'(\neg A | B)}^{-1} \)
We defer calculating the actual probabilities:
\[
\begin{array}{lcl}
P(A|B)&=& \eta P'(A|B) \\
P(\neg A|B) &=& \eta P'(\neg A|B)\\
\end{array}
\]
\subsubsection{Two cancer}
\screenshot{twocancer}{A Bayes network from the lectures}
\subsection{Conditional Independence}
In the two-cancer example (to be scanned and/or type) we assumed
conditional independence:
\[
P(T_2| C_1T_1) = P(T_2| C)
\]
Conditional independence is a really big thing in bayes networks.
The thing is that if an arrow goes out of something, that will make
variables in the receiving end dependent. It's even better, since
it's a model of the causality behind the dependence.
Snippets
Absolute indepence does not give conditional independence, conditional
independce does not imply absolute independence.
Differen type of bayes network. Two hidden causes that are confounded
into a single state. Happyness may be caused by sunnyness, a raise.
The ``explaining away'' method. If there are multipe causes for
happiness. If we can observe one of them, that makes the other less
likely, and it is ``explained away''.
\screenshot{compactbayes}{Compact bayes}
Bayes networks defines probabiliteis over graphs of random variables.
Instead of enumerating all dependenies, the network is defined by
distributions of probabilities dependent on the incoming arcs. The
joint distribution of probability of the network is defined as the
product of all the product of all the nodes (dependent of the nodes).
This is a very compact definition. It doesn't have to look at the set
of all subsets of dependent variables. In this case only ten
parameters instead of 31. This compactness is the reason bayes
networks are used in so many situations.
Unstructured joint representations sucks compared with bayes
representation.
\subsection{Parameter count}
A bayes network is defined as an equation like this one.
\[
P(A,B,C) = P(C| B, C) * P (A) * P(B) = \prod_i P_i(c_i | c_{1} \cdots c_{n(i)})
\]
The number of parameters that are necessary to specify this network
is \(\sum_i 2^{n(i)} \), so in the case above the count would be \(1 + 1
+ 4 = 6\).
\subsection{D-separation}
\screenshot{dseparation}{D separation}
Two variables are independent if they are independent of Any two
variables independent if they are linked by just unknown variables.
Anything downstreaam
\screenshot{dseparation-1}{More D separation}
Reachability = D-separation
\idx{Active triplets}: render triplets dependent.
\idx{Inactive triplets}: render triplets independent.
\screenshot{reachability}{Reachability}
We'vw learned about graph structure, compact representation,
conditional indepence and some applications.
\section{Probabilistic inference}
Probability theory and bayes net and independence. In this unit we
will look at probabilistic inference.
In probabilisticinference we don't talk about \idx{input variables} and
\idx{output values}, but evidence and query. The \idx{evidence} is
the stuff we know something about, the \idx{query} are the things we
want to find out about. Anything that is neither evicence nor query
is a \idx{hidden variable}. In probabilstic inference, the output
isn't a single number, but a \idx{probability distribution}. The
answer will be a \idx{complete probability distribution} over the query
variables. We call this the \idx{posterior distribution}.
Some notation:
The \(Q\)s are the query variables, the \(E\)s are the evidence
variables. The computation we want to come up with is:
\[
P(Q_1, Q_2, \ldots | E_1= e_1, E_2=2_2, \ldots)
\]
Another question we can ask: What is the most probable distribution.
The notation for that is:
\[
\mbox{argmax}_q\, P(Q_1=1_1, Q_2=1_2, \ldots | E_1= e_1, E_2=e_2, \ldots)
\]
Find the combination of q values that are ``maxible'' given the
evidence. That is the set of qs having the highest probability of
being true.
In an ordinary computer language computation goes only one way, from
input to output. Bayes nets are not restricted to going in only oen
direction. We can go in the causal directing, using the evidence as
input and using the query values at the bottom to figure out what's
the most likely situation given some evidence.
However we can reverse the \idx{causal flow}. We can actually mix the
variables in any way we want.
inference on bayes networks: Enumeration
Goes through all the combinations, adds them up and comes up with an
answer:
\begin{itemize}
\item {\em State the problem:} ``What is the probability that the burglar alarm
went of given that john called and Mary called'': \( P(+b | +j, +m)
\).
\item We will be using a definition of conditional probability that
goes like this:
\[
P(Q|E) = \frac{P(Q,E)}{P(E)}
\]
\item The query we wish to get is the \idx{joint probability distribution}
divided by the \idx{conditionalized variables}.
\[
P(+b|, +j, +m) = \frac{P(+b, +j, +m)}{P(+j, +m)}
\]
Reading this equality from left to right, it can be interpreted as
rewriting the conditioned probability into a fraction of unconditioned
probability.
\end{itemize}
We're using a notation here:
\[
P(E=\mbox{true}) \equiv P(+e) \equiv 1 - P(\neg e) \equiv P(e)
\]
The latter notation may be confusing, since it's unclear if \(e\) is a variable.
First take a conditional probability, and then rewrite it as an
unconditional probability. Now we enumerate all the atomic
probabilities and calculate the sum of products.
We'll take a look at \(P(+b, +j, +m) \). The probability of these
three terms can be expressed like this.
\[
P(+b, +j, +m) = \sum_e \sum_a P(+b, +j, +m)
\]
We get the answer by summing over all the possibilities of \(e\) and \(a\)
being true and false, four terms in total. To get the values of
these atomic events, we need to rewrite the term \(P(+b, +j, +m)\) to
fit the conditional probability tables that we have associated with
he bayes network.
\screenshot{enumeration}{Enumeration}
\[
\begin{array}{lcl}
P(+b, +j, +m) &=& \sum_e \sum_a P(+b, +j, +m) \\
&=& \sum_e \sum_a P(+b)P(e) P(a|+b, e) P(+j|a) P(+m, a) \\
&=& f(+e,+a) + f(+e,\neg a) + f(\neg e,+a) + f(\neg e, \neg a)
\end{array}
\]
The numbers to fill in we get from conditional probability tables
\screenshot{enumerationtables}{Enumeration tables}
For simple networks enumeration is simple to do. For five hidden variables
there will only be 32 terms to consider. If there are several tens of
hidden variables there will be billions or quadrillion rows. That is
not just practical.
\subsubsection{Pulling out terms}
The first optimization we'll consider is \idx{pulling out terms}. If
we start with:
\[
\sum_e \sum_a P(+b)P(e) P(a|+b, e) P(+j|a) P(+m, a)
\]
The probability of \(P(+b)\) will be the same all the time, so we
can pull it outside the summation. That's a little bit less work to
do. We can also move the term \(P(e)\) can be moved in front of the
second summation:
\[
P(+b)\sum_e P(e) \sum_a P(a|+b, e) P(+j|a) P(+m, a)
\]
This is good since it means that each row takes less work, but it's
still a large number of rows.
\subsubsection{Maximize independence}
For instance a network that is a linear string can have inference done
in time that is proportional to the number \(O(n\), whereas a network
that is a \idx{complete network}, i.e. a network where all nodes are
connected, could take time proportional to \(O(2^n)\) for boolean
variables. In the alarm network we took care that we had all the
dependence relations represented in the network. However, we could do
it differently.
The moral is is that bayes networks are written the most compactly
when they are written in that \idx{causal direction}, when the networks
flows from causes to effects.
In the equation
\[
P(+b)\sum_e P(e) \sum_a P(a|+b, e) P(+j|a) P(+m, a)
\]
we sum up everything. That's slow since we end up repeating a lot of
work. We'll now look at another technique called \idx{variable
elimination} which in many network operates much faster. It's
still a hard problem ( \idx{NP-hard}) to inference on Bayes networks
in general, but variable elimination works faster in most practical
cases. It requires an algebra for addressing elements in \idx{multi
dimensional arrays} that comes out of the \(P\) terms in the
expression above.
We look at a network with the variables R (raining), T (Traffic). T
is dependent on R. L (late for next appointment). L is dependent on
T. For a simple network like this enumeration will work fine, but we
can also use eleminitation.
It gives us a way to combine parts of the network into smaller parts,
en then enumerate over those smaller parts and then continue
combining. So we start with a big network we elminiate som of the
variables, then compute by \idx{marginalizing out} and then we have a
smaller network to deal with.
\screenshot{variable-elimination}{Variable elimination}
\begin{enumerate}
\item{\em Joining factors:} We chose two or more of the factors, and
join the together to a new factor. \(P(R,T)\) could be one such
factor. It's just a ``join''operator over the relevant tables where
the probabilities are multiplied. I'm sure an sql statement can be
concocted to calculate this :-)
\item{\em summing out or marginalizing:} Continue the process to
remove factors, so in the end you end up with a much smaller number
of factors.
\end{enumerate}
If we make a god choice of the orde of eliminations to do it can be
very much more efficient than just enumeration.
\subsection{Approximate inference sampling}
Repeat experiments to sample input. Repeat until we can estimate the
joint probability. Large numbers of samples are necessary to get true
to the true distribution.
Sampling has an advantage over inference in that it gives us a
procedure to get to an approximation to the joint distribution,
whereas the exact computation may be very complex.
Sampling has another advantage: If we don't know what the probability
distributions are, we can still proceed with sampling, but we couldn't
do that with inference.
\screenshot{samplingexample}{Sampling example}
Four variables, all boolean. Cloudy, Sprinkler, Rain, WetGrass. To
sample we use the probability tables and traverses the graph and
assigns values randomly (according to the distributions) and then uses
those values to build up an image of the total probability.
The probability of sampling a particular value depends on the parent.
In the limit the count of the counted probability will approach the
true probability. With an infinite number of samplings we would know
the result :-) The sampling method is \idx{consistent}. We can use
this sampling method to compute the complete joint probability
distribution, or we can use it to compute values for an individual
variable.
Now what if we wish to compute a conditioal probability? To do that
we need to to start doing the same thing (generating samples), but
then reject the samples that don't match the condition we are looking
for. This technique is called \idx{rejection sampling} since we
reject the samples that don't have the properties we are interested in
and keep those that do.
This procedure would also be consistent.
Tere is a problem with rejection sampling: If the evidence is
unlikely, you end up rejecting a lot of samples. Let's consider the
alarm network again. If we're interested in calculating the
probability \(B|a+)\) i.e. the probability of a burglary given that
the alarm has gone off. The problem is that burglaries are very
infrequent, so we will end up rejecting a lot of samples.
To counter this we introduce a new method called \idx{likelyhood
weighting} that generates samples that can be used all the time. We
fix the conditional variables (setting \(a+\) in this case), and then
sample the rest of the variables.
We get samples that we want, but the result we get is
\idx{inconsistent}. We can fix that by assigning a probability to
each sample and weighting them correctly.
In \idx{likelyhood weighting} we sample like before but add a
probabilistic weight to each sample. Each time we are forced to make
a choice, we must multiply a probability for the value we choose.
With weighting likelyhood weighting is consistent.
Likelyhood weighting is a great technique but it doesn't solve all
problems. There are cases where we fix some variables, but not all,
and that makes variables that the fixed variables are dependent on
likely to make a lot of values with very low probabilities. It's
consistent, but not efficient.
\idx{Gibbs sampling} takes all the evidence, not just the upstream
evidence into account. It uses a technique called \idx{markov chain
monte carlo} or \idx{mcmc}. We resample just one variable at a
time, conditioned on all the others: Assume we have a set of
variables and initialize them to random values keeping the evidence
values fixed. At each iteration through the loop we select just one
non-evidence variable and resample that based on all the other
variables. That will give us another variable. Repeat.
\screenshot{gibsssampling}{Gibbs sampling}
We end up walking around in the space. In mcmc all the samples are
dependent on each other, in fact adjacent samples are very similar.
However, the technique is still consistent.
\idx{The monty hall problem} Three doors, one with an expensive
sports car, the other two contains a goat. If you choose door number
one, the host will now open a door containing a goat. You can now
stick with your choice or switch.
\chapter{Machine learning}
The world is data rich. Chemihal, financial pharmaceutical databases
etc. To make sense of it macine learning is really important to make
sense of it.
So ar we've talked about bayes networks that are known. In machine
learning addreses how to learn models from data.
\section{Supervised learning}
\screenshot{stanley}{Stanley, the winning robot in the DARPA
grand challenge.}
Thrun shows off the Stanley car that uses a laser that builds a 3d
model of the terrain ahead. It tries to drive on flat ground. The
laser only looks about 25 meters ahead. The camera image sees
further, but the robot uses machine learning to extrapolate the
knowledge about where drivable road is loacated out to two hundred
meters, and that was crucial in rder to get the robot to drive fast.
\begin{itemize}
\item what? Parameters, structure and hidden concepts (some hidden
rules may exist in the data).
\item What from? Some sort of target information. In supervised
learning we have specific target labels
rules) .
\item Unsupervised learning? Target labels are missing.
\item Reinforcement learning. Receiving feedback from the
environment
\item what for? Prediction, diagnosis? Summarization (gisting) ..
\item how? Passive (if the agent is just an observer), otherwise
active Sometimes online (when data is generated) or offline.
\item Classification (fixed no of classes) v.s. regression (continous)
\item Details? Generative v.s. discriminative. Generative tries to
describe stuffs as general as ppossible, dicriminitave
attempts to find things as specific as possible.
\end{itemize}
In supervised learning we have a bunch of features and a target:
\[
x_1, x_2, \ldots , x_n \rightarrow y
\]
\screenshot{supervisedlearning}{Supervised learning}
The learning algorithm gets a learning set and generates a model.
Features, behavior etc. The subject is to identify the function
\(f\).
\screenshot{errorclasses}{Error classes}
When selecting models, \idx{occam's razor} is good: Everything else
being equal choose the less complex hypothesis. In reality there is a
tradeoff between fit and low complexity. \idx{bias variance
methods}.
In practice it's a good idea to push back on complexity to avoid
overfitting and generative errors. \idx{Overfitting} is a major source of
poor performance for machine learning.
\subsection{Spam detection using bayes networks}
\screenshot{spamproblem}{Detecting spam in email}
We wish to categorize into spam/ham. to get things usable for emails
we need a representation. We use the \idx{bag of words}
represention. It is a word frequencey vector. The vector is
obvlivious to the location of the word in the input.
In the ham/spam examle, this the vocabulary
\begin{figure}[htb]
\begin{verbatim}
click
costs
event
is
link
money
offer
play
secret
sport
sports
today
went
\end{verbatim}
\label{vocabulary}
\caption{The spam/ham vocabulary}
\end{figure}
\screenshot{spamham}{Calculating the probability of spam}
the size is 14. The probability that is 3/8 that it's spam
\screenshot{maxlikelyhood}{First maximum likelyhood slide}
\screenshot{maxlikely2}{Second maximum likelyhood slide}
\subsection{Maximum likelyhood}
Since I'm not really conversant on maximum likelyhood issues, I'll
copy a bit in detail, since that is something that frequently helps me
transfer the subject matter into my mind :-)
We assume that there are two possible outcomes of a process, ``S'' and
``H'', and then define \(P(S) = \pi\) and conversely \(P(H) = 1 - \pi
\). Rewriting this yet once more gives:
\[
p(y_i) =
\left\{
\begin{array}{cclcl}
\pi & \mbox{if} & y_i &=& S \\
1-\pi & \mbox{if} & y_i &=& H \\
\end{array}
\right.
\]
Now comes a bit that I don't understand, since he says:
\[
p(y_i) = \pi^{yi} \cdot (1-\pi)^{1 - y_i}
\]
Less mysterious, since it is a a consequence of the above:
\[
p(\mbox{data}) = \pi_{i=1}^n p(y_i) = \pi^{\mbox{count}(y_i=1)} \cdot
(1 - \pi)^{\mbox{count}(y_i=1)}
\]
\[
\begin{array}{lclcl}
P(\mbox{secret}| \mbox{spam}) &=& 3/9 &=& 1/3 \\
P(\mbox{secret}|\mbox{ham}) &=& 1/15 && \\
\end{array}
\]
\subsection{Relationship t Bayes Networks}
We are making a maximum likelyhood etimator modelled as an bayesian
estimator and using machine learning to finding the network.
Given a twelve word vocablary, we need 23 parameters. P(spam), and two
for each word (one for ham, and one for spam). Now, there are 12
words, so that makes 12 parameters for ham probability, but since
these add up to one, we only need eleven :-) The same thing applies
to spam, so that is 11 + 11 + 1 = 23.
So, what i the probability of classifying ``sports'' as spam? Well,
we have to bring out Bayes:
\begin{verbatim}
\[
P(spam|''sports'') =
\frac{p("sports"|spam) \cdot p(spam)}{P(spam)}
=
\frac{p("sports"|spam) \cdot p(spam)}{P(m|spam)P(spam) + P(m|ham)P(ham)}
\]
\end{verbatim}
1/9*3/8 / (1/3 * 3/8 + 1/3 * 5/8) = (3/72)/ (18/72) = 3/18 = 1/6 = 0.667
The answer is 3/18
\screenshot{overfittingbayes}{Overfitting using a naive Bayes classifier}
\subsubsection{Laplace smoothing}
One way of fixing the overfitting is \idx{laplace smoothing}.
\[
\begin{array}{cccc}
\mbox{ML}&p(x) &=& \frac{\mbox{count}(x)}{N} \\
\mbox{LS}(k)&p(x) &=& \frac{\mbox{count}(x) + k }{N + k|x|}
\end{array}
\]
ML = maximum likelyhood. LS = Lapace smoothing
where \(\mbox{count}(x)\) is the number of occurrences of this value of the
variable \(x\). \(|x|\) is the number of values that the variable \(x\) can take
on. \(k\) is a smoothing parameter. And \(N\) is the total number of
occurrences of \(x\) (the variable, not the value) in the sample
size.
This is equivalent of assuming that we have of fake count \(k\) to he
count, and then adding \(k\) to every single class we are estimating over.
if k=1. one message with one spam. For the laplace smoothed thing we
get these nmbers
\screenshot{laplacesmoothingexample}{An example of using Laplace smoothing}
\screenshot{hamspamlapace2}{Using Laplace smooting in a spam detector}
\screenshot{hamspam3}{Calculating even more spam probabilities using
Laplace smoothing}
\subsubsection{Summary naive bayes}
We've got features and labels (e.g. spam/ham). We used ML and
laplacian smoother to make a bayes network. This is called a
\idx{generative model} in that the conditioned probabilities are all
aiming to maximize the predictability of individual features as if
those features describe the physical world. We use the \idx{bag of
words} model.
This is a very powerful method for finding spam. It's unfortunately