Probability and Uncertainty in AI


Probability and Uncertainty in AI

Hope
Welcome back. Today we’re tackling probability—not as a collection of formulas to memorize, but as the foundation for representing and reasoning about uncertainty in artificial intelligence.

Maria
That’s a shift from many earlier AI topics. We’ve often reasoned with symbols and rules: if one thing is true, then another follows. Those methods can work well for settings like games with clear logical rules, but real situations are often uncertain.

Hope
Right. A model can be incomplete, or it may be impossible or impractical to make it detailed enough to predict everything deterministically. Some events are outside our control, and some calculations are simply too difficult. Probability gives us a formal way to represent and reason about that uncertainty.

Maria
And later, machine learning connects to this by helping us learn the parameters of probabilistic models—or models more generally—from data and experience. Today’s probability concepts are the groundwork we’ll keep using.

Hope
Let’s make that concrete with Ghostbusters. There’s a hidden ghost somewhere on a board, and we get one chance to bust it. We can spend points on sensor readings first, but those readings are noisy: a color may suggest the ghost is near or far without telling us for certain.

Maria
So before any readings, we have a prior belief about the ghost’s location. If the game treats every square as equally likely, that prior is uniform. As sensor readings arrive, we want a posterior distribution: the probability of each location given the evidence we’ve collected.

Hope
Exactly. A single reading doesn’t settle the matter, because the sensor can be wrong. The useful question is how all the evidence together changes our beliefs about the location. We could also ask whether another sensing action is worth its cost—that’s a value-of-information question, although we’re not calculating it yet.

Maria
The same setup applies outside the game. In medical diagnosis, symptoms or lab results can be evidence, while a condition we’re trying to infer is a query. Probabilistic inference combines the model with the evidence to calculate the probabilities we need for decisions.

Hope
The basic building block is a random variable: a named aspect of the world that matters enough to include in our model. For example, R might represent whether it’s raining, T whether it’s hot or cold, D how long a drive takes, and L where the ghost is.

Maria
Like variables in a constraint-satisfaction problem, random variables have domains. R might be True or False; temperature might be Hot or Cold; weather might have several categories; and a travel time could be a real number.

Hope
We usually write random variables with capital letters and their values with lowercase names. For a Boolean variable R, a compact convention is plus R for R equals true and minus R for R equals false. That notation saves space, but we still have to name the variable if a value like true could refer to more than one thing.

Maria
In this course, we’ll mostly calculate with discrete-valued variables. The same broad ideas apply to continuous variables, but the mechanics change: sums become integrals, and there are additional cases to think through.

Hope
A probability distribution over one random variable assigns a probability to every value in its domain. Those probabilities must be nonnegative and add up to one. For example, Hot and Cold could each have probability 0.5.

Maria
A nonbinary weather variable could assign 0.6 to Sun, 0.1 to Rain, and 0.3 to Fog. You could also list an outcome such as Meteor with probability zero, but in practical models exact zeros can be risky: later evidence might make that outcome the only one consistent with what was observed.

Hope
So, in a real model, it’s often safer to represent an outcome as extremely unlikely rather than impossible. A zero should mean that the outcome can never occur, no matter what evidence comes in.

Maria
There’s a useful distinction in the notation, too. P of capital W means the whole distribution over W—a table or vector of probabilities. P of W equals Rain is one particular entry, a single number. When a value is unambiguous, we may shorten that to P of Rain.

Hope
Now we can put variables together in a joint distribution. A joint distribution gives a probability to every complete assignment of values to all the variables in the model. For temperature T and weather W, it might give separate probabilities to Hot-and-Sun, Hot-and-Rain, Cold-and-Sun, and Cold-and-Rain.

Maria
That table is like a truth table in a CSP, except instead of marking each assignment simply legal or illegal, it assigns a likelihood. The probabilities reveal which outcomes are more common and how variables are related.

Hope
For example, suppose the joint table says Hot-and-Sun has probability 0.4, Hot-and-Rain 0.1, Cold-and-Sun 0.2, and Cold-and-Rain 0.3. The probability of Sun is 0.4 plus 0.2, or 0.6. The probability of Hot is 0.4 plus 0.1, or 0.5.

Maria
That illustrates events. An outcome is one complete assignment; an event can include several outcomes. To find an event’s probability, add the probabilities of all outcomes that match it. Hot-and-Sun is one row, while simply Hot includes both Hot rows.

Hope
And an event can be described in other ways too. In that same table, Hot or Sun includes three rows, so its probability is 0.4 plus 0.1 plus 0.2, which is 0.7. Most often, though, we’ll focus on partial assignments, such as Hot or Sun, rather than more complicated combinations of alternatives.

Maria
A joint distribution is powerful because it lets us answer many questions about the variables. But its size is a serious problem. If there are N variables and each has D possible values, we need a probability for each assignment—D to the N entries.

Hope
That exponential growth makes a full joint table impractical for large models. Real graphical models can have thousands of variables. The plan in later lessons is to use compact structures that capture local relationships, instead of building the entire table. For now, though, the full joint is useful for understanding the calculations.

Maria
A probabilistic model, in the basic sense we’re using today, is a joint distribution over its random variables. A valid model is normalized—the probabilities of all complete outcomes add to one. Later we’ll look for ways to represent its interactions more compactly.

Hope
One compact result derived from a joint table is a marginal distribution. It keeps some variables and sums out the others. To get the temperature distribution from the T-and-W table, add together the rows that share each temperature value.

Maria
So P of Hot is 0.4 plus 0.1, or 0.5, and P of Cold is 0.2 plus 0.3, also 0.5. The operation of adding over the values of a variable is called marginalization, or summing out that variable.

Hope
You can also marginalize temperature to get weather: Sun is 0.4 plus 0.2, or 0.6, and Rain is 0.1 plus 0.3, or 0.4. In general, a marginal can retain one variable, several variables, or even all of them.

Maria
The other central calculation is a conditional probability: how likely is A given that B is known to have happened? Its definition is P of A and B divided by P of B. In words, it’s the portion of the probability of B that also falls inside A.

Hope
Using our temperature-and-weather example, the probability of Sun given Cold is the probability of Cold-and-Sun divided by the total probability of Cold. That’s 0.2 divided by 0.5, which gives 0.4.

Maria
The denominator includes every outcome consistent with the evidence Cold—both Cold-and-Sun and Cold-and-Rain. For a small example with X and Y, suppose the four joint probabilities are 0.2 for plus X plus Y, 0.3 for plus X minus Y, 0.4 for minus X plus Y, and 0.1 for minus X minus Y.

Hope
Then P of plus X is 0.2 plus 0.3, or 0.5. P of plus Y is 0.2 plus 0.4, or 0.6. And P of plus X given plus Y is 0.2 divided by 0.6, which is one third.

Maria
Likewise, P of minus X given plus Y is 0.4 divided by 0.6, or two thirds. Those two conditional probabilities add up to one because, once plus Y is known, X must be either plus or minus.

Hope
A conditional distribution gives the probabilities of all possible values of a query variable given some evidence. For example, P of W given T equals Hot is a distribution over Sun and Rain. From our table, Sun given Hot is 0.4 divided by 0.5, or 0.8, and Rain given Hot is 0.1 divided by 0.5, or 0.2.

Maria
That conditional distribution is different from the marginal P of W, which is 0.6 for Sun and 0.4 for Rain. Before learning the temperature, Sun had probability 0.6; after learning it’s Hot, the probability rises to 0.8. Evidence updates belief.

Hope
Here’s a handy way to compute a conditional distribution from a joint table: select the rows that match the evidence, then normalize what remains. To normalize means to divide each remaining probability by their sum so the resulting distribution adds up to one.

Maria
For example, to find the distribution over X given minus Y in our small table, keep only plus X minus Y with probability 0.3 and minus X minus Y with probability 0.1. Their total is 0.4, so after normalization the probabilities are 0.75 and 0.25.

Hope
That is not the same as the marginal distribution over X. The marginal ignores evidence: it combines all rows matching each X value, giving 0.5 for plus X and 0.5 for minus X. The conditional distribution uses only rows consistent with minus Y.

Maria
For a bigger model, we distinguish three groups of variables. Evidence variables are values we know; query variables are the values we want to infer; and hidden variables are unknown values that we don’t need in the final answer.

Hope
Inference by enumeration is the direct, brute-force method for computing a query from a full joint distribution. First select the entries consistent with the evidence. Then sum out the hidden variables. Finally, normalize the remaining probabilities to get a distribution over the query.

Maria
In Ghostbusters, the ghost’s location might be the query, the sensor readings we’ve actually observed are evidence, and readings we never took are neither known nor needed in the answer. We sum over the possibilities for hidden variables rather than pretending we know their values.

Hope
The procedure is straightforward, but it’s often computationally awful. The joint table is exponential in the number of variables, and enumeration can require exponentially many operations. Learning every entry would also require an enormous amount of evidence. That’s why compact models and efficient inference algorithms matter.

Maria
Before we get to those compact models, we need rules for building and rearranging probabilities. The product rule says that a joint distribution can be written as P of X given Y times P of Y. It follows directly from the definition of conditional probability.

Hope
Suppose we know how likely it is to be sunny, and we know how likely it is to be wet given Sun. Then the probability of Wet-and-Sun is the probability of Sun multiplied by the probability of Wet given Sun. For instance, if Sun has probability 0.8 and Wet given Sun has probability 0.1, the joint probability is 0.08.

Maria
A conditional table can contain several distributions side by side—for example, one distribution over Wet and Dry given Sun, and another over Wet and Dry given Rain. Each conditional distribution adds to one, but the combined table isn’t itself one distribution; it’s a family of distributions.

Hope
The chain rule extends the product rule to many variables. For three variables, P of X1, X2, and X3 equals P of X1 times P of X2 given X1 times P of X3 given X1 and X2. Each added conditional probability expands the joint while accounting for what came before.

Maria
More generally, each variable is conditioned on all the variables earlier in the ordering. The matching denominators and numerators cancel as you multiply the terms, leaving the joint probability over the whole set.

Hope
And then there’s Bayes’ rule. It’s famous, but it comes from applying the product rule in two directions: P of X and Y equals P of X given Y times P of Y, and also P of Y given X times P of X. Rearranging gives P of X given Y as P of Y given X times P of X, divided by P of Y.

Maria
Bayes’ rule is useful when the conditional probability we want is hard to model directly, but the reverse conditional is available. It lets us turn a probability of an effect given a cause into a probability of the cause given the observed effect.

Hope
The diagnosis example makes that clear. Let M mean meningitis and S mean stiff neck. We might want P of M given S, but know instead the prevalence of meningitis, P of M, and how often stiff neck occurs among people with meningitis, P of S given M, along with information about stiff neck among people without meningitis.

Maria
With those probabilities, Bayes’ rule lets us calculate the probability of meningitis given a stiff neck. The result can rise above the prior probability of meningitis, even while remaining small. The exact answer depends on the probabilities in the model.

Hope
That leads to an important distinction: the most likely outcome is not automatically the best decision. If missing a serious condition has a very high cost, it may make sense to get checked even when the condition is unlikely. Probability describes belief; utility helps evaluate consequences.

Maria
Finally, return to the ghost and its noisy sensor. If we know the prior distribution over possible locations and the sensor model—the probability of each color given the ghost’s distance—we can use the observed colors to compute a posterior distribution over locations.

Hope
That posterior is the heat map we wanted: a precise belief for every square, updated as readings arrive. It may still show uncertainty, but it gives us a principled basis for deciding where to bust or whether to gather more evidence.

Maria
So the essential toolkit is: represent important unknowns as random variables, describe outcomes with distributions, use joints to capture relationships, marginalize to remove variables we don’t need, and condition on evidence to update beliefs.

Hope
Then use the product rule, chain rule, and Bayes’ rule to connect probabilities, while remembering that full joint tables grow exponentially. Those ideas set up the efficient graphical-model methods we’ll explore next—and, later, learning probabilities from data.

Ask anything
We've read this whole study set, so questions about it get the best answers.