class: middle, center, title-slide
Lecture 4: Quantifying uncertainty
Prof. Gilles Louppe
[email protected]
class: middle, center
???
Motivate why this is important in AI (and this is not just one more probability theory class).
.grid[ .kol-1-2[
- Random variables
- Probability distributions
- Inference
- Independence
- The Bayes' rule
.alert[Do not overlook this lecture!]
.footnote[Credits: CS188, UC Berkeley.]
class: middle
class: middle
.grid[ .kol-1-2[ A ghost is hidden in the grid somewhere.
Sensor readings tell how close a square is to the ghost:
- On the ghost: red
- 1 or 2 away: orange
- 3 away: yellow
- 4+ away green
]
.kol-1-2[.width-100[
]] ] Sensors are noisy, but we know the probability values
$P(\text{color}|\text{distance})$ , for all colors and all distances.
.footnote[Credits: CS188, UC Berkeley.]
class: middle, black-slide
.center[
.footnote[Credits: CS188, UC Berkeley.]
class: middle
An agent is rational if it chooses the action that yields the highest expected utility, averaged over all the possible outcomes of the action.
.question[What does "expected" mean exactly?]
General setup:
- Observed variables or evidence: agent knows certain things about the state of the world (e.g., sensor readings).
- Unobserved variables: agent needs to reason about other aspects that are uncertain (e.g., where the ghost is).
- (Probabilistic) model: agent knows or believes something about how the observed variables relate to the unobserved variables.
Probabilistic reasoning provides a framework for managing our knowledge and beliefs.
Probabilistic assertions express the agent's inability to reach a definite decision regarding the truth of a proposition.
- Probability values summarize effects of
- ignorance (theoretical, practical)
- laziness (lack of time, resources)
- Probabilities relate propositions to one's own state of knowledge (or lack thereof).
- e.g.,
$P(\text{ghost in cell } [3,2]) = 0.02$
- e.g.,
class: middle
What do probability values represent?
- The objectivist frequentist view is that probabilities are real aspects of the universe.
- i.e., propensities of objects to behave in certain ways.
- e.g., the fact that a fair coin comes up heads with probability
$0.5$ is a propensity of the coin itself.
- The subjectivist Bayesian view is that probabilities are a way of characterizing an agent's beliefs or uncertainty.
- i.e., probabilities do not have external physical significance.
- This is the interpretation of probabilities that we will use!
.question[How shall we assign numerical values to beliefs?]
Begin with a set
A probability space is a sample space equipped with a probability function, i.e. an assignment
- 1st axiom:
$P(\omega) \in \mathbb{R}$ ,$0 \leq P(\omega)$ for all$\omega \in \Omega$ - 2nd axiom:
$P(\Omega) = 1$ - 3rd axiom:
$P(\{ \omega_1, ..., \omega_n \}) = \sum_{i=1}^n P(\omega_i)$ for any set of samples
where
???
The axioms really do constrain the degrees of belief an agent can have concerning logically related propositions.
De Finetti's theorem implies that no rational agent can have beliefs that violate the axioms of probability. Put otherwise, rational beliefs must obey the axioms of probability.
class: middle
-
$\Omega$ = the 6 possible rolls of a die. -
$\omega_i$ (for$i=1, ..., 6$ ) are the sample points, each corresponding to an outcome of the die. - Assignment
$P$ for a fair die:$$P(1) = P(2) = P(3) = P(4) = P(5) = P(6) = \frac{1}{6}$$
- A random variable is a function
$X: \Omega \to D_X$ from the sample space to some domain defining its outcomes.- e.g.,
$\text{Odd}: \Omega \to \{ \text{true}, \text{false} \}$ such that$\text{Odd}(\omega) = (\omega,\text{mod},2 = 1)$ .
- e.g.,
-
$P$ induces a probability distribution for any random variable$X$ .$P(X=x_i) = \sum_{\{\omega: X(\omega)=x_i\}} P(\omega)$ - e.g.,
$P(\text{Odd}=\text{true}) = P(1)+P(3)+P(5) = \frac{1}{2}$ .
- An event
$E$ is a set of outcomes$\{(x_1, ..., x_n), ...\}$ of the variables$X_1, ..., X_n$ , such that$$P(E) = \sum_{(x_1, ..., x_n) \in E} P(X_1=x_1, ..., X_n=x_n).$$
???
In practice, we will use random variables to represent aspects of the world about which we (may) have uncertainty.
-
$R$ : Is it raining? -
$T$ : Is it hot or cold? -
$L$ : Where is the ghost?
class: middle
- Random variables are written in upper roman letters:
$X$ ,$Y$ , etc. - Realizations of a random variable are written in corresponding lower case letters.
E.g.,
$x_1$ ,$x_2$ , ...,$x_n$ could be of outcomes of the random variable$X$ . - The probability value of the realization
$x$ is written as$P(X=x)$ . - When clear from context, this will be abbreviated as
$P(x)$ . - The probability distribution of the (discrete) random variable
$X$ is denoted as${\bf{P}}(X)$ . This corresponds e.g. to a vector of numbers, one for each of the probability values$P(X=x_i)$ (and not to a single scalar value!).
For discrete variables, the probability distribution can be encoded by a discrete list of the probabilities of the outcomes, known as the probability mass function.
One can think of the probability distribution as a table that associates a probability value to each outcome of the variable.
.grid[
.center.kol-1-2[
.footnote[Credits: CS188, UC Berkeley.]
???
- This table can be infinite!
- By construction, probability values are normalized (i.e., sum to
$1$ ).
class: middle
A joint probability distribution over a set of random variables
.center[${\bf P}(T,W)$]
???
From a joint distribution, the probability of any event can be calculated.
- Probability that it is hot and sunny?
- Probability that it is hot?
- Probability that it is hot or sunny?
Interesting events often correspond to partial assignments, e.g.
class: middle
The marginal distribution of a subset of a collection of random variables is the joint probability distribution of the variables contained in the subset.
.center.grid[
.kol-1-3[
] | ||
.kol-1-3[ | ||
Intuitively, marginal distributions are sub-tables which eliminate variables.
class: middle
The conditional probability of a realization
Indeed, observing
class: middle
Conditional distributions are probability distributions over some variables, given fixed values for others.
.center.grid[
.kol-1-3[
] | ||
.kol-1-3[ | ||
${\bf P}(W | T=\text{hot})$ |
] | |
.kol-1-3[ | |
${\bf P}(W | T=\text{cold})$ |
] | |
] |
exclude: true class: middle
.center.grid[
.kol-1-3[
] | ||
.kol-1-3[ | ||
Select the joint probabilities matching the evidence
]
.kol-1-3[
Normalize the selection (make it sum to
] ]
Probabilistic inference is the problem of computing a desired probability from other known probabilities (e.g., conditional from joint).
- We generally compute conditional probabilities.
- e.g.,
$P(\text{on time} | \text{no reported accidents}) = 0.9$ - These represent the agent's beliefs given the evidence.
- e.g.,
- Probabilities change with new evidence:
- e.g.,
$P(\text{on time} | \text{no reported accidents}, \text{5AM}) = 0.95$ - e.g.,
$P(\text{on time} | \text{no reported accidents}, \text{rain}) = 0.8$ - e.g.,
$P(\text{ghost in } [3,2] | \text{red in } [3,2]) = 0.99$ - Observing new evidence causes beliefs to be updated.
- e.g.,
class: middle
-
Evidence variables:
$E_1, ..., E_k = e_1, ..., e_k$ -
Query variables:
$Q$ -
Hidden variables:
$H_1, ..., H_r$ -
$(Q \cup E_1, ..., E_k \cup H_1, ..., H_r)$ = all variables$X_1, ..., X_n$
Inference is the problem of computing
Start from the joint distribution
- Select the entries consistent with the evidence
$E_1, ..., E_k = e_1, ..., e_k$ . - Marginalize out the hidden variables to obtain the joint of the query and the evidence variables:
$${\bf P}(Q,e_1,...,e_k) = \sum_{h_1, ..., h_r} {\bf P}(Q, h_1, ..., h_r, e_1, ..., e_k).$$ - Normalize:
$$\begin{aligned} Z &= \sum_q P(q,e_1,...,e_k) \\\\ {\bf P}(Q|e_1, ..., e_k) &= \frac{1}{Z} {\bf P}(Q,e_1,...,e_k) \end{aligned}$$
class: middle
.grid[ .kol-1-2[
-
${\bf P}(W)$ ? -
${\bf P}(W|\text{winter})$ ? -
${\bf P}(W|\text{winter},\text{hot})$ ?
] .center.kol-1-2[
] ]
class: middle
- Inference by enumeration can be used to answer probabilistic queries for discrete variables (i.e., with a finite number of values).
- However, enumeration does not scale!
- Assume a domain described by
$n$ variables taking at most$d$ values. - Space complexity:
$O(d^n)$ - Time complexity:
$O(d^n)$
- Assume a domain described by
.question[Can we reduce the size of the representation of the joint distribution?]
.center.grid[
.kol-1-3[
] | |
.kol-1-3[ | |
${\bf P}(D | W)$ |
]
.kol-1-3[
? | ||
? | ||
? | ||
? |
] ]
More generally, any joint distribution can always be written as an incremental product of conditional distributions:
-
$P(a|b) = P(a)$ , or -
$P(b|a) = P(b)$ , or $P(a,b) = P(a)P(b)$
Independence is denoted as
???
... from the third expression, one can already notice that assuming independences leads to a factorization in which the factors are smaller.
class: middle
.center[
.width-40[]
.width-45[
]
]
The original 32-entry table reduces to one 8-entry and one 4-entry table (assuming 4 values for
.footnote[Credits: CS188, UC Berkeley.]
class: middle
For
$2^n \to n$
-
$P(a|b,c) = P(a|c)$ , or -
$P(b|a,c) = P(b|c)$ , or $P(a,b|c) = P(a|c)P(b|c)$
Conditional independence is denoted as
class: middle
- Using the chain rule, the join distribution can be factored as a product of conditional distributions.
- Each conditional distribution may potentially be simplified by conditional independence.
- Conditional independence assertions allow probabilistic models to scale up.
class: middle
Assume three random variables
In this case, the representation of the joint distribution reduces to
.footnote[Credits: CS188, UC Berkeley.]
class: middle
More generally, from the product rule, we have
Assuming pairwise conditional independence between the effects given the cause, it comes:
This probabilistic model is called a naive Bayes model.
- The complexity of this model is
$O(n)$ instead of$O(2^n)$ without the conditional independence assumptions. - Naive Bayes can work surprisingly well in practice, even when the assumptions are wrong.
???
This is an important model you should know about!
class: middle, center, red-slide count: false
Study the next slide. .bold[Twice].
.grid[ .kol-2-3[
The product rule defines two ways to factor the joint distribution of two random variables.
]
]
]
-
$P(a)$ is the prior belief on$a$ . -
$P(b)$ is the probability of the evidence$b$ . -
$P(a|b)$ is the posterior belief on$a$ , given the evidence$b$ . -
$P(b|a)$ is the conditional probability of$b$ given$a$ . Depending on the context, this term is called the likelihood.
???
Do it on the blackboard.
class: middle, center
.grid[ .kol-1-2[
]
.kol-1-2[.center.width-80[]]
]
The Bayes' rule is the foundation of many AI systems.
???
Bayes rule/inference: emphasize that is like Sherlock Holmes:
- Start from a set of possibilities (prior)
- Discard/weigh down those not compatible with the observations/evidence.
The Bayes' rule gives us a way to operationalize the update of our beliefs.
class: middle
-
$P(\text{effect}|\text{cause})$ quantifies the relationship in the causal direction. -
$P(\text{cause}|\text{effect})$ describes the diagnostic direction.
Let
???
... or
class: middle
- Let us assume a random variable
$G$ for the ghost location and a set of random variables$R_{i,j}$ for the individual readings. - We start with a uniform prior distribution
${\bf P}(G)$ over ghost locations. - We assume a sensor reading model
${\bf P}(R_{i,j}|G)$ .- That is, we know what the sensors do.
-
$R_{i,j}$ = reading color measured at$[i,j]$ - e.g.,
$P(R_{1,1}=\text{yellow}|G=[1,1])=0.1$
- e.g.,
- Two readings are conditionally independent, given the ghost position.
???
This is a Naive Bayes model!
class: middle
- We can calculate the posterior distribution
${\bf P}(G|R_{i,j})$ using Bayes' rule:$${\bf P}(G|R_{i,j}) = \frac{ {\bf P}(R_{i,j}|G){\bf P}(G)}{ {\bf P}(R_{i,j})}.$$ - For the next reading
$R_{i',j'}$ , this posterior distribution becomes the prior distribution over ghost locations, which we update similarly.
class: middle, black-slide
.center[
.footnote[Credits: CS188, UC Berkeley.]
???
What if we had chosen a different prior?
class: middle
Given some observation
class: middle, black-slide
.footnote[Credits: NSA/JPL-Caltech, 2010.]
class: middle
.center[
.width-25[]
.width-70[
]
]
.footnote[Credits: Vasist et al, 2023.]
- Uncertainty arises because of laziness and ignorance. It is inescapable in complex non-deterministic or partially observable environments.
- Probabilistic reasoning provides a framework for managing our knowledge and beliefs, with the Bayes' rule acting as the workhorse for inference.
class: end-slide, center count: false
The end.