-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path06-ProbabilityAndDistributions.Rmd
More file actions
1932 lines (1351 loc) · 52.7 KB
/
06-ProbabilityAndDistributions.Rmd
File metadata and controls
1932 lines (1351 loc) · 52.7 KB
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
# Probability and Distributions
**Probability** is the study of **uncertainty** — it allows us to measure and reason about the likelihood of events. Probability can be interpreted in two complementary ways:
- As the **fraction of times an event occurs** in repeated experiments.
- As a **degree of belief** in the occurrence of an event.
<p align="center">
<img src="Figure6.1MML.png" alt="A mind map of the concepts related to random variables and
probability distributions, as described in this chapter." width="400">
</p>
In machine learning, probability helps us **quantify uncertainty** in:
- The **data** we collect,
- The **models** we build, and
- The **predictions** those models make.
<div class="definition">
A **random variable** is a function that maps outcomes of a random experiment
to numerical or categorical values that we care about.
</div>
Formally, the idea of a random variable connects:
- The **sample space** (possible outcomes),
- The **events** (collections of outcomes),
- And the **probability distribution**, which assigns a likelihood to each outcome or set of outcomes.
<div class="example">
Consider the simple experiment of rolling a fair six-sided die once.
The sample space \( \Omega \) is the set of all possible outcomes:
\[
\Omega = \{1, 2, 3, 4, 5, 6\}.
\]
Each element of \( \Omega \) is a possible outcome of the experiment.
An event is any subset of the sample space. Some examples include:
- Event \(A\): “Roll an even number”
\[
A = \{2, 4, 6\}.
\]
- Event \(B\): “Roll a number greater than 4”
\[
B = \{5, 6\}.
\]
A random variable \(X\) is defined as a function:
\[
X : \Omega \to \mathbb{R}.
\]
For example, we could let
\[
X(\omega) =
\begin{cases}
1, & \text{if } \omega \text{ is even} \\
0, & \text{if } \omega \text{ is odd}
\end{cases}.
\]
So:
- \(X(2) = 1\), \(X(4) = 1\), \(X(6) = 1\)
- \(X(1) = 0\), \(X(3) = 0\), \(X(5) = 0\)
The random variable turns outcomes into numbers.
Since the die is fair, each outcome has probability:
\[
P(\{\omega\}) = \frac{1}{6}, \quad \omega \in \Omega.
\]
The probability distribution of \(X\) assigns probabilities to the values of \(X\):
\[
P(X = 1) = P(\{2,4,6\}) = \frac{3}{6} = \frac{1}{2},
\]
\[
P(X = 0) = P(\{1,3,5\}) = \frac{3}{6} = \frac{1}{2}.
\]
Thus, the distribution of \(X\) is:
\[
X =
\begin{cases}
1 & \text{with probability } \tfrac{1}{2}, \\
0 & \text{with probability } \tfrac{1}{2}.
\end{cases}
\]
**Big Picture Connection**
- Sample space: all possible outcomes (\(\Omega\))
- Events: subsets of outcomes
- Random variable: a function mapping outcomes to numbers
- Probability distribution: probabilities assigned to the values of the random variable.
</div>
<div class="definition">
A **probability distribution** describes how probabilities are spread over the possible values of a random variable.
</div>
Probability distributions tell us the chance that specific outcomes will occur.
Distributions are foundational tools for:
- Probabilistic modeling,
- Graphical models,
- Model selection, and
- Inference.
<div class="definition">
A **probability space** consists of three key elements:
1. **Sample space** – the set of all possible outcomes
2. **Events** – subsets of the sample space
3. **Probability function** – assigns a number between 0 and 1 to each event
</div>
These components work together to define how probability is assigned and interpreted.
---
## Construction of a Probability Space
The goal of **probability theory** is to define a mathematical framework for describing random outcomes of experiments. For example, while we cannot predict the outcome of a single coin toss, repeating the experiment many times reveals regular patterns in the long run. This structure allows us to perform *automated reasoning* (computer driven), generalizing Boolean *logical reasoning* into a continuous framework for uncertainty.
---
### Philosophical Issues
Classical Boolean logic cannot express **plausible reasoning** — the type of reasoning we use in uncertain, real-world situations. Probability theory extends logic to handle **degrees of plausibility** rather than discrete true/false statements.
> “For plausible reasoning it is necessary to extend the discrete true and false values of truth to continuous plausibilities.” — *E. T. Jaynes (2003)*
<div class="example">
If your friend is late, you may rule out the hypothesis *she is on time* and find *she is delayed by traffic* more plausible, though not logically required.
</div>
This everyday reasoning can be formalized through probability theory.
<div class="definition">
E. T. Jaynes identified three key criteria for plausibility that form the foundation of probability:
1. **Plausibility as real numbers.**
- Degrees of plausibility are represented by real numbers.
- This allows for continuous gradations of belief between complete disbelief (false) and certainty (true).
2. **Consistency with common sense.**
- The rules governing these plausibility values must be consistent with the rules of common sense reasoning.
- For example, if evidence makes an event more likely, the numerical plausibility should increase accordingly.
3. **Consistency in reasoning**, meaning:
- **(a) Non-contradiction:** If the same conclusion can be reached by different arguments, it must have the same plausibility.
- **(b) Honesty:** All available and relevant information must be considered.
- **(c) Reproducibility:** Identical states of knowledge must lead to identical plausibility assignments.
</div>
The Cox–Jaynes theorem shows that any system satisfying these principles must follow the rules of probability.
<div class="theorem">
**Cox-Jaynes:** Under the Jaynes assumptions, the rules governing plausibilities are *isomorphic* to the *rules of probability theory*.
That is, for plausability measure $p$ and probability measure $P$, there exists a monotonic transformation \( f \) such that for any propositions \( A \) and \( B \): \[P(A|B) = f(p(A|B)),\]
where \( P(A|B) \) satisfies the standard **sum** and **product** rules of probability:
\[
P(A \land B|C) = P(A|C) \, P(B|A, C)
\]
\[
P(A \lor B|C) = P(A|C) + P(B|C) - P(A \land B|C).
\]
</div>
---
### Bayesian vs. Frequentist Interpretations
There are two different interpretations of probability that we need to consider when dealing with machine learning models: Bayesian and Frequentist.
| Interpretation | Description | Example Usage |
|----------------|--------------|----------------|
| **Bayesian** | Probability represents degree of belief or subjective uncertainty about an event. | Updating belief after observing data. |
| **Frequentist** | Probability represents the long-run relative frequency of an event over repeated trials. | Estimating event probability as data size $\rightarrow \infty$. |
Both perspectives appear in machine learning, depending on whether the focus is on modeling uncertainty (Bayesian) or empirical frequency (Frequentist).
<div class="example">
We have a coin that might be biased. We toss it 10 times and observe 7 heads. We want to know: *What is the probability that the coin is biased toward heads?*
**Frequentist Perspective:**
The frequentist treats the probability as an *objective long-run frequency*.
- The coin has a fixed, but unknown probability \( p \) of landing heads.
- The data (7 heads out of 10 tosses) are used to **estimate** this parameter.
\[
\hat{p} = \frac{7}{10} = 0.7
\]
A 95% confidence interval for \( p \) (using a binomial model) might be approximately:
\[
p \in [0.35, 0.93]
\]
Therefore, if we were to repeat the entire experiment many times, then 95% of the confidence intervals constructed this way would contain the true \( p \). The parameter \( p \) is fixed — only the data vary.
**Bayesian Perspective:**
The Bayesian treats probability as a *degree of belief* about \( p \). The parameter \( p \) itself is a random variable with a prior distribution. The data are used to update beliefs via Bayes’ theorem.
Assume a uniform prior:
\[
p \sim \text{Beta}(1, 1)
\]
After observing 7 heads and 3 tails:
\[
p | \text{data} \sim \text{Beta}(8, 4)
\]
then,
\[
E[p|\text{data}] = \frac{8}{8 + 4} = 0.67
\]
A 95% **credible interval** is approximately:
\[
p \in [0.42, 0.88]
\]
Therefore, given the data and prior beliefs, there is a 95% probability that \( p \) lies between 0.42 and 0.88. Here, the data are fixed and the parameter is uncertain.
</div>
Below are some of the differences between the frequentist and Bayesian perspective.
| Aspect | Frequentist | Bayesian |
|:--------|:-------------|:----------|
| Definition of Probability | Long-run frequency of events | Degree of belief about parameters |
| Parameter \( p \) | Fixed but unknown | Random variable |
| Data | Random | Fixed (once observed) |
| Interval Meaning | 95% of intervals contain true \( p \) in repeated experiments | 95% probability that \( p \) lies in the given range |
| Uses Prior Information | No | Yes |
---
### Probability and Random Variables
There are three key ideas in probability theory:
1. **Probability Space** – the fundamental mathematical setup.
2. **Random Variables** – functions mapping outcomes to measurable quantities.
3. **Distributions (Laws)** – describe how probabilities are assigned to these quantities.
<div class="definition">
A **probability space** is defined by three components:
- **Sample Space ($\Omega$):**
The set of all possible outcomes of an experiment.
Example: two coin tosses $\longrightarrow \Omega = \{hh, ht, th, tt\}$.
- **Event Space ($\mathcal{A}$):**
The collection of subsets of Ω that can occur as events. Often, for discrete spaces, $\mathcal{A}$ is the **power set** of $\Omega$.
- **Probability Measure ($P$):**
A function assigning probabilities to events:
- \( 0 \leq P(A) \leq 1 \) for all \( A \in \mathcal{A} \)
- \( P(\Omega) = 1 \)
</div>
<div class="definition">
A **random variable** is a function \( X: \Omega \rightarrow T \) that maps outcomes \( \omega \in \Omega \) to values \( x \in T \), the **target space**.
</div>
<div class="example">
Toss two coins and let \( X \) = number of heads. Then \( T = \{0, 1, 2\} \), and:
\[
X(hh) = 2, \quad X(ht) = 1, \quad X(th) = 1, \quad X(tt) = 0.
\] Here, we see that our function $X$ maps from our set of outcomes $\Omega = \{hh, ht, th, tt\}$ into our target space $T = \{0,1,2\}$.
</div>
The probability of \( X \) taking certain values can be expressed as:
\[
P_X(S) = P(X \in S) = P(\{\omega \in \Omega : X(\omega) \in S\})
\]
This defines the distribution (law) of \( X \), written \( P_X = P \circ X^{-1} \).
- If \( T \) is finite or countable, \( X \) is a **discrete random variable**.
- If \( T = \mathbb{R}^D \), \( X \) is a **continuous random variable**.
<div class="example">
Suppose we draw two coins (with replacement) from a bag containing U.S. coins ($) with probability 0.3 and U.K. coins (£) with probability 0.7.
**Sample space:**
Ω = {(\$,\$), (\$,£), (£,\$), (£,£)}
**Random variable:**
\( X \) = number of U.S. coins drawn \( \longrightarrow T = \{0,1,2\} \)
**Probability mass function:**
\[
\begin{aligned}
P(X=2) &= 0.3 \times 0.3 = 0.09 \\
P(X=1) &= 2 \times 0.3 \times 0.7 = 0.42 \\
P(X=0) &= 0.7 \times 0.7 = 0.49
\end{aligned}
\]
Thus, \( X \) defines a discrete probability distribution over \( T \).
</div>
---
### Statistics
Probability and statistics are related but distinct disciplines:
| Field | Main Focus |
|--------|-------------|
| **Probability** | Starts with a model and derives what outcomes we expect. |
| **Statistics** | Starts with observed data and infers the underlying model. |
In machine learning, we use both:
- Probability helps model uncertainty and future generalization.
- Statistics helps infer model parameters from data.
Probability theory provides the foundation for analyzing **generalization error** and for developing data-driven models that learn from uncertainty.
---
### Exercises {.unnumbered .unlisted}
<div class="exercise">
A hospital researcher is interested in the number of times the average post-op patient will ring the nurse during a 12-hour shift. For a random sample of 50 patients, the following information was obtained. Let $X =$ the number of times a patient rings the nurse during a 12-hour shift.
| \(X\) | \(P(X)\) |
|------:|:--------:|
| 0 | \( \frac{4}{50} \) |
| 1 | \( \frac{8}{50} \) |
| 2 | \( \frac{16}{50} \) |
| 3 | \( \frac{14}{50} \) |
| 4 | \( \frac{6}{50} \) |
| 5 | \( \frac{2}{50} \) |
What is $T$? Do these data follow the rules of probability? What is $P(X\geq 3)$ (use notation)?
<div style="text-align: right;">
[Solution]( )
</div>
</div>
<div class="exercise">
Suppose Nancy has classes three days a week. She attends classes three days a week 80\% of the time, two days 15\% of the time, one day 4\% of the time, and no days 1\% of the time. Suppose one week is randomly selected. What is $T$? Do these data follow the rules of probability? Suppose we select a week at random. What is the probability associated with each value in $T$? What is the probability that Nancy attends at least 2 classes in the week (use notation)?
<div style="text-align: right;">
[Solution]( )
</div>
</div>
## Discrete and Continuous Probabilities
This section discusses two main types of probability distributions — **discrete** and **continuous** — and how they describe the likelihood of events depending on whether the target space is countable or continuous.
---
### Discrete Probabilities
<div class="definition">
The probability that \( X \) takes a particular value \( x \) is given by the **probability mass function (pmf)**:
\[
P(X = x)
\]
</div>
<div class="example">
Suppose a small factory inspects 4 items at random from a large production line. Each item is independently defective with probability \(0.2\).
Let
\[
X = \text{number of defective items among the 4 inspected}.
\]
The possible values of \(X\) are:
\[
\{0,1,2,3,4\}.
\]
Each inspection is a Bernoulli trial, so \(X\) follows a **binomial distribution**:
\[
X \sim \text{Binomial}(n=4, p=0.2).
\]
The PMF of a binomial random variable is:
\[
p_X(x) = P(X = x) = \binom{4}{x}(0.2)^x(0.8)^{4-x}, \quad x = 0,1,2,3,4.
\]
Evaluating:
\[
\begin{aligned}
P(X=0) &= (0.8)^4 = 0.4096 \\
P(X=1) &= 4(0.2)(0.8)^3 = 0.4096 \\
P(X=2) &= 6(0.2)^2(0.8)^2 = 0.1536 \\
P(X=3) &= 4(0.2)^3(0.8) = 0.0256 \\
P(X=4) &= (0.2)^4 = 0.0016
\end{aligned}
\]
Therefore, we have the following PMF as a table:
| \(x\) | \(P(X = x)\) |
|----:|:-------------:|
| 0 | 0.4096 |
| 1 | 0.4096 |
| 2 | 0.1536 |
| 3 | 0.0256 |
| 4 | 0.0016 |
Notice that the PMF is not uniform: some outcomes are much more likely than others. Most of the probability mass is concentrated at \(x=0\) and \(x=1\). Exact probabilities for events can be computed by summing the PMF for example:
\[
P(X \le 1) = P(X=0) + P(X=1) = 0.8192.
\]
We note that this has all of the PMF requirements:
- \(p_X(x) \ge 0\) for all \(x\)
- \(\sum_{x=0}^4 p_X(x) = 1\)
- Each value of \(X\) has a clearly defined probability.
</div>
<div class="definition">
For two random variables \( X \) and \( Y \):
- The **joint probability** is \( P(X = x_i, Y = y_j) \), denoted \( p(x, y) \).
- The **marginal probability** of \( X \) is obtained by summing over all possible \( y \):
\[
P(X = x_i) = \sum_j P(X = x_i, Y = y_j)
\]
- The **conditional probability** of \( Y \) given \( X \) is:
\[
P(Y = y_j \mid X = x_i) = \frac{P(X = x_i, Y = y_j)}{P(X = x_i)}
\]
</div>
<div class="example">
A school surveys students about whether they study regularly and whether they pass a math exam. The events are:
- \(S\): student studies regularly
- \(P\): student passes the exam
The results are summarized in the following **joint probability table**:
| | Pass (\(P\)) | Fail (\(P^c\)) | **Total** |
|--------------|-------------:|---------------:|------:|
| Study (\(S\)) | 0.42 | 0.08 | 0.50 |
| No Study (\(S^c\))| 0.18 | 0.32 | 0.50 |
| **Total** | 0.60 | 0.40 | 1.00 |
Joint probabilities describe the probability that two events occur together. For example,
\[
P(S,P) = P(S \cap P) = 0.42, \quad P(S^c, P^c) = P(S^c \cap P^c) = 0.32.
\]
Marginal probabilities are obtained by summing over rows or columns of the joint table.
\[
\begin{aligned}
P(S) &= 0.42 + 0.08 = 0.50 \\
P(S^c) &= 0.18 + 0.32 = 0.50 \\
P(P) &= 0.42 + 0.18 = 0.60 \\
P(P^c) &= 0.08 + 0.32 = 0.40
\end{aligned}
\]
Conditional probability measures the likelihood of one event given that another event has occurred. For example, the probability of passing given the student studies:
\[
P(P \mid S) = \frac{P(S \cap P)}{P(S)} = \frac{0.42}{0.50} = 0.84.
\]
Another example might be the probability of passing given the student does not study:
\[
P(P \mid S^c) = \frac{0.18}{0.50} = 0.36.
\]
</div>
The probabilities of all possible states must sum to one:
\[
\sum_i P(X = x_i) = 1
\]
Discrete distributions are commonly used to model categorical variables, such as labels or class features.
---
### Continuous Probabilities
<div class="definition">
A **continuous random variable** takes values from an interval on the real line \( \mathbb{R} \).
</div>
The probability that \( X \) lies in an interval \( [a, b] \) is:
\[
P(a \le X \le b) = \int_a^b f(x) \, dx
\]
<div class="definition">
The function \( f(x) \) is the **probability density function (pdf)**, which satisfies:
1. \( f(x) \ge 0 \) for all \( x \)
2. \( \int_{-\infty}^{\infty} f(x) \, dx = 1 \)
The **cumulative distribution function (cdf)** is defined as:
\[
F_X(x) = P(X \le x) = \int_{-\infty}^{x} f(t) \, dt
\]
</div>
<div class="example">
Let \(X\) be a continuous random variable representing the amount of time (in hours) a student spends studying for an exam. Assume \(X\) has the following probability density function (PDF):
\[
f_X(x) =
\begin{cases}
\frac{1}{4}, & 0 \le x \le 4, \\
0, & \text{otherwise}.
\end{cases}
\]
This is a uniform distribution on the interval \([0,4]\). The height of the density is constant: \(f_X(x) = \frac{1}{4}\). Probabilities are found by computing areas, not by evaluating the PDF at a point. For example, the probability that a student studies between 1 and 3 hours is:
\[
P(1 \le X \le 3) = \int_1^3 \frac{1}{4} \, dx = \frac{1}{4}(3 - 1) = \frac{1}{2}.
\]
The cumulative distribution function (CDF) is defined by:
\[
F_X(x) = P(X \le x).
\]
Compute \(F_X(x)\) by integrating the PDF:
\[
F_X(x) =
\begin{cases}
0, & x < 0, \\
\displaystyle \int_0^x \frac{1}{4} \, dt = \frac{x}{4}, & 0 \le x \le 4, \\
1, & x > 4.
\end{cases}
\]
\(F_X(x)\) gives the probability that the study time is at most \(x\) hours. For example:
\[
P(X \le 2) = F_X(2) = \frac{2}{4} = 0.5.
\]
</div>
Note that \( P(X = x) = 0 \) for continuous random variables.
<div class="example">
Let \(X\) be a continuous random variable (CRV) with probability density function (PDF) \(f_X(x)\). By definition, probabilities for a CRV are computed using integrals:
\[
P(a \le X \le b) = \int_a^b f_X(x)\,dx.
\]
Consider the probability that \(X\) takes exactly one value \(x_0\):
\[
P(X = x_0).
\]
This probability corresponds to the integral over an interval of zero width:
\[
P(X = x_0) = \int_{x_0}^{x_0} f_X(x)\,dx.
\]
Since the limits of integration are the same,
\[
\int_{x_0}^{x_0} f_X(x)\,dx = 0.
\]
Therefore,
\[
P(X = x_0) = 0
\]
for any real number \(x_0\).
</div>
---
### Contrasting Discrete and Continuous Distributions
| Property | Discrete | Continuous |
|:----------|:----------|:------------|
| Representation | Probability Mass Function \( p(x) \) | Probability Density Function \( f(x) \) |
| Domain | Finite or countable set | Interval in \( \mathbb{R} \) |
| Probability of a single value | \( P(X = x) \geq 0 \) | \( P(X = x) = 0 \) |
| Normalization | \( \sum_x p(x) = 1 \) | \( \int f(x)dx = 1 \) |
| Example | Categorical variable, coin toss | Gaussian, uniform distribution on an interval |
<div class="example">
**Discrete case:**
A variable \( Z \) with three equally likely outcomes \(\{-1.1, 0.3, 1.5\}\):
\[
P(Z = z_i) = \frac{1}{3}
\]
</div>
<div class="example">
**Continuous case:**
A variable \( X \) uniformly distributed over \( [0.9, 1.6] \) has:
\[
\int_{0.9}^{1.6} p(x) \, dx = 1
\]
The height of \( p(x) \) can exceed 1 as long as the total area equals 1.
</div>
---
### Exercises {.unnumbered .unlisted}
<div class="exercise">
Consider the table below:
| | \(x_1\) | \(x_2\) | \(x_3\) | \(x_4\) |
|--------|--------:|--------:|--------:|--------:|
| \(y_1\) | 10 | 40 | 65 | 35 |
| \(y_2\) | 15 | 55 | 25 | 60 |
| \(y_3\) | 20 | 30 | 50 | 45 |
1. \( p(x_i, y_j) = p(x, y) \). What is this called and what is \( p(x_3, y_2) \)?
2. \( p(X = x) = p(x) \). What is this called and what is the formula?
3. Find \( p(x_4) \). Write it out using the formula.
4. Find \( p(y_2) \). Write it out using the formula.
5. \( p(X = x_i \mid Y = y_j) = p(x \mid y) \). What is this called and what is the formula?
6. Find \( p(x_2 \mid y_3) \) and \( p(y_1 \mid x_4) \).
7. \( p(x) = \sum_{y \in Y} p(x, y) \). What is this called? Use the formula to find \( p(x_2) \).
<div style="text-align: right;">
[Solution]( )
</div>
</div>
<div class="exercise">
Let $X$ be a random variable with PDF given by \[f_X(x)= \begin{cases} cx^2 & |x| \leq 1\\0 & otherwise \end{cases}.\]
1. Find the constant $c$.
2. Find $P(X \geq 1/2)$
<div style="text-align: right;">
[Solution]( )
</div>
</div>
<div class="exercise">
Let $X$ be a continuous random variable with PDF \[f_X(x) = \dfrac{1}{2}e^{-|x|}, \;\;\;\; x \in \mathbb{R}.\] If $Y = X^2$, find the CDF of $Y$.
<div style="text-align: right;">
[Solution]( )
</div>
</div>
<div class="exercise">
Let $X$ be a continuous random variable with PDF \[f_X(x) = \begin{cases} 4x^3 & 0 < x \leq 1\\0 & otherwise \end{cases}.\] Find $P(X\leq 2/3 | X > 1/3)$.
<div style="text-align: right;">
[Solution]( )
</div>
</div>
<div class="exercise">
Let $f(x) = k(3x^2 + 1)$.
1. Find the value of $k$ that makes the given function a PDF on the interval $0 \leq x \leq 2$.
2. Let $X$ be a continuous random variable whose PDF is $f(x)$. Compute the probability that $X$ is between 1 and 2.
3. Find the distribution function of $X$.
4. Find the probability that $X$ is exactly equal to 1.
<div style="text-align: right;">
[Solution]( )
</div>
</div>
<div class="exercise">
Let \[f(t) = \begin{cases}t & 0 < t \leq 1\\ 2-t & 1 < t \leq 2 \\ 0 & otherwise \end{cases}.\]
1. Prove this is a PDF.
2. Find $p(x \leq 1.5)$
3. Find $p(x > 1.2)$
4. Find $p(1.2 < x \leq 1.5)$
5. Find $p(x = 1)$
<div style="text-align: right;">
[Solution]( )
</div>
</div>
<div class="exercise">
Show that the normal distribution is a PDF. Note that the normal distribution is given by \[f(z) = \dfrac{1}{\sqrt{2\pi}}e^{-z^2/2}.\]
<div style="text-align: right;">
[Solution]( )
</div>
</div>
## Sum Rule, Product Rule, and Bayes’ Theorem
Probability theory can be viewed as an extension of logic that allows reasoning under uncertainty. All of probability theory can be built from two fundamental rules — the **Sum Rule** and the **Product Rule** — both of which arise naturally from the desiderata of plausible reasoning (Jaynes, 2003).
---
### The Sum Rule (Marginalization Property)
The **Sum Rule** relates a **joint distribution** to its **marginal distribution** by summing or integrating over unobserved variables.
<div class="theorem">
**Sum Rule:** If \( x \) and \( y \) are random variables with joint probability \( p(x, y) \), then:
\[
p(x) =
\begin{cases}
\sum\limits_{y \in Y} p(x, y), & \text{if } y \text{ is discrete} \\
\int_Y p(x, y) \, dy, & \text{if } y \text{ is continuous}
\end{cases}
\]
- \( p(x, y) \): joint probability of \( x \) and \( y \)
- \( p(x) \): marginal probability of \( x \)
- \( Y \): set of all possible values of \( y \)
</div>
<div class="example">
Discrete Joint Distribution
Let \( X \) and \( Y \) be discrete random variables with joint probability mass function given by:
| \(Y \backslash X\) | 1 | 2 | 3 |
|------------------:|---|---|---|
| 0 | 0.10 | 0.15 | 0.05 |
| 1 | 0.20 | 0.30 | 0.20 |
Use the **sum rule** to find the marginal probability \( P(X = 2) \).
**Solution**
For discrete random variables, the sum rule states:
\[
P(X=x) = \sum_{y} P(X=x, Y=y)
\]
Thus,
\[
P(X=2) = P(2,0) + P(2,1)
= 0.15 + 0.30
= 0.45
\]
</div>
<div class="example">
Continuous Joint Distribution
Let \( X \) and \( Y \) be continuous random variables with joint probability density function:
\[
f_{X,Y}(x,y) =
\begin{cases}
\frac{1}{6}, & 0 \le x \le 3,\; 0 \le y \le 2 \\
0, & \text{otherwise}
\end{cases}
\]
Use the sum rule (integral form) to find the marginal probability
\[
P(1 \le X \le 2)
\]
**Solution**
For continuous random variables, the sum rule is:
\[
P(X \in A) = \int_A \int_{-\infty}^{\infty} f_{X,Y}(x,y)\,dy\,dx
\]
So,
\[
P(1 \le X \le 2)
= \int_1^2 \int_0^2 \frac{1}{6}\,dy\,dx
\]
Evaluate the integrals:
\[
= \int_1^2 \frac{1}{6}(2)\,dx
= \int_1^2 \frac{1}{3}\,dx
= \frac{1}{3}
\]
</div>
For multiple variables \( x = [x_1, \dots, x_D]^\top \), the marginal distribution of one component \( x_i \) is obtained by integrating/summing over all other variables:
\[
p(x_i) = \int p(x_1, \dots, x_D) \, dx_{\backslash i}
\]
<div class="note">
Marginalization often involves **high-dimensional integrals or sums**, which are computationally expensive to evaluate exactly.
</div>
---
### The Product Rule (Factorization Property)
The **Product Rule** expresses a joint distribution in terms of a marginal and a conditional distribution:
<div class="theorem">
If \( x \) and \( y \) are random variables, then:
\[
p(x, y) = p(y \mid x)\,p(x)
\]
Equivalently,
\[
p(x, y) = p(x \mid y)\,p(y)
\]
where:
- \( p(x, y) \) — joint probability of \( x \) and \( y \)
- \( p(y \mid x) \) — conditional probability of \( y \) given \( x \)
- \( p(x) \) — marginal (or prior) probability of \( x \)
</div>
The product rule states that the joint probability can always be factorized into two parts:
- The **marginal probability** \( p(x) \)
- The **conditional probability** \( p(y \mid x) \)
<div class="example">
Let \(X\) and \(Y\) be discrete random variables defined as follows:
- \(X\): the type of coin selected
- \(x_1\): Fair coin
- \(x_2\): Biased coin
- \(Y\): outcome of a single coin toss
- \(y_1\): Heads
- \(y_2\): Tails
Suppose:
\[
P(X = x_1) = 0.6, \quad P(X = x_2) = 0.4
\]
Assume the following conditional probabilities:
- If the coin is fair:
\[
P(y_1 \mid x_1) = 0.5, \quad P(y_2 \mid x_1) = 0.5
\]
- If the coin is biased:
\[
P(y_1 \mid x_2) = 0.8, \quad P(y_2 \mid x_2) = 0.2
\]
Using the formula
\[
P(x,y) = P(y \mid x)\,P(x),
\]
we compute each joint probability.
- \(P(x_1, y_1)\):
\[
P(y_1 \mid x_1)P(x_1) = (0.5)(0.6) = 0.30
\]
- \(P(x_1, y_2)\):
\[
(0.5)(0.6) = 0.30
\]
- \(P(x_2, y_1)\):
\[
(0.8)(0.4) = 0.32
\]
- \(P(x_2, y_2)\):
\[
(0.2)(0.4) = 0.08
\]
Thus, we have the following results:
| \(Y \backslash X\) | \(x_1\) | \(x_2\) |
|------------------:|:------:|:------:|
| \(y_1\) (Heads) | 0.30 | 0.32 |
| \(y_2\) (Tails) | 0.30 | 0.08 |
</div>
Because the ordering of variables is arbitrary, the rule is symmetric:
\[
p(x, y) = p(x \mid y) \, p(y) = p(y \mid x) \, p(x)
\]
---
### Bayes’ Theorem (Probabilistic Inversion)
By combining the Sum and Product Rules, we obtain **Bayes’ Theorem**:
<div class="theorem">
Let \( p(x) \) be the our initial belief about $x$ before seeing the data (the **prior**), \( p(y \mid x) \) the likelihood of data $y$ given $x$ (the **likelihood**) and \( p(y) \) the probability of event $y$ (the **evidence or marginal likelihood**). Then, the **posterior**, \( p(x \mid y) \), (the updated belief about \( x \) after observing \( y \)) is given by:
\[
p(x \mid y) =
\frac{p(y \mid x) \, p(x)}{p(y)}
\]