1. Home
  2. Explore
  3. Statistics
  4. Probabilistic Modeling

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Probabilistic Modeling

Probabilistic Modeling: Joint Distributions, Bayesian Networks, and Dependence

1. Modeling Many Random Variables Together

A probabilistic model describes how one or more random variables can take values and how likely those values are. Real-world situations—such as a person’s symptoms, illnesses, age, and activities—usually involve many random variables that may influence one another.

A model of several random variables must represent probabilities for their possible values together. This is the foundation for answering inference questions: after observing some information, how should belief about other variables change?

Example: Modeling symptoms and illness

A health application might represent variables for:

  • Diseases a person could have, such as flu or a cold

  • Symptoms, such as fever, tiredness, nausea, or sore throat

  • Background characteristics, such as age or whether someone is an undergraduate

If a user reports nausea and tiredness, the application could update its belief about whether the user has the flu. It could also answer other questions, such as how likely a cold is given that the user has no fever.

The general inference pattern is:

  1. Observe values for some random variables.

  2. Use the model to update beliefs about other variables.

  3. Ask about any target variable represented in the model.


2. Joint Distributions

A joint distribution gives the probability of every possible assignment of values to a collection of random variables. For example, with variables for flu, undergraduate status, fever, and tiredness, one joint assignment might specify that a person has no flu, is an undergraduate, has no fever, and is tired.

The joint distribution is a complete description of the probabilistic model: if it is known, any probability or inference question about those variables can, in principle, be answered.

A joint distribution assigns a probability to every possible combination of values taken by the model’s random variables.

Why joint tables become impractical

If there are nnn binary random variables, each can take either 000 or 111. The number of possible joint assignments is therefore:

2n2^n2n

A table representing the complete joint distribution needs one probability for each assignment, except that one probability can be inferred because all probabilities must sum to 111. This small adjustment does not change the exponential growth.

For example:

  • One binary variable has 222 possible assignments.

  • Two binary variables have 22=42^2 = 422=4 assignments.

  • Three binary variables have 23=82^3 = 823=8 assignments.

  • Nine binary variables have 29=5122^9 = 51229=512 assignments.

Consequently, explicitly storing a joint table quickly becomes impractical as the number of variables increases.


3. Inference and Bayes’ Theorem

Inference means updating beliefs about some random variables after observing values of others.

For example, observing a person’s weight could provide information about their gender in a simplified model. Observing symptoms could provide information about possible diseases. The observation does not necessarily determine the hidden state; it changes the probabilities assigned to possible states.

Binary and multi-valued variables

For a binary variable, inference may require updating the probability of just two possible values. For a variable with many possible values, the model must update the probability of every possible value.

For instance, a visual-acuity variable might represent many levels of eyesight rather than merely “can see” and “cannot see.” In that case, inference involves updating a whole distribution across the possible acuity values.

If a target variable can take many values, Bayes’ theorem is applied to each value. A computer can perform this repeated calculation efficiently.

Priors, likelihoods, and posteriors

Bayes’ theorem combines:

  • Prior: the probability assigned to a state before observing new evidence

  • Likelihood: the probability of the evidence given that state

  • Posterior: the updated probability of the state after observing the evidence

For a hypothesis AAA and evidence BBB:

P(A∣B)=P(B∣A)P(A)P(B)P(A \mid B) = \frac{P(B \mid A)P(A)}{P(B)}P(A∣B)=P(B)P(B∣A)P(A)​

Here, P(A)P(A)P(A) is the prior, P(B∣A)P(B \mid A)P(B∣A) is the likelihood, and P(A∣B)P(A \mid B)P(A∣B) is the posterior.

Computing a multi-valued posterior by normalization

When a target variable has many possible values, it is often unnecessary to compute the denominator P(B)P(B)P(B) separately for every value. Instead, calculate the numerator for each possible value and then normalize the resulting numbers so they sum to 111.

For possible states a1,a2,…,aka_1, a_2, \ldots, a_ka1​,a2​,…,ak​, calculate:

P(B∣A=ai)P(A=ai)P(B \mid A=a_i)P(A=a_i)P(B∣A=ai​)P(A=ai​)

for each state aia_iai​, then divide each value by the sum of all the values:

P(A=ai∣B)=P(B∣A=ai)P(A=ai)∑j=1kP(B∣A=aj)P(A=aj)P(A=a_i \mid B) = \frac{P(B \mid A=a_i)P(A=a_i)} {\sum_{j=1}^{k}P(B \mid A=a_j)P(A=a_j)}P(A=ai​∣B)=∑j=1k​P(B∣A=aj​)P(A=aj​)P(B∣A=ai​)P(A=ai​)​

This normalization is equivalent to applying Bayes’ theorem because the denominator is the sum of the numerators over all possible states. In code, it is common to store all the numerator values in an array and normalize the array.


4. Bayesian Networks

A Bayesian network is a compact representation of a joint distribution. It combines a directed graph with probability tables.

  • Each node represents a random variable.

  • A directed arrow represents a modeled influence from one variable to another.

  • Each node has a probability distribution conditioned on the values of its immediate parents in the graph.

A Bayesian network provides a more structured alternative to explicitly listing every possible joint assignment.

Causality as a modeling guide

Arrows are often chosen to represent causal relationships. For example, flu may cause fever and tiredness. Fever may provide evidence that a person has the flu, but the observation of fever is not necessarily considered to cause the flu.

This distinction matters:

  • Causation is modeled in a direction: flu may cause fever.

  • Evidence and probability updates can work in either direction: observing fever can increase belief in flu.

A graph is a simplified account of how the world works. There may be plausible additional influences—for example, tiredness might affect susceptibility to illness—but a useful model aims to capture the broad structure without adding every possible relationship.

Adding arrows has a cost: each additional parent can require many more probabilities to be specified or learned. A model with too few arrows may omit important relationships; one with too many arrows may become difficult to estimate and may fit limited data poorly. This is related to the broader trade-off between underfitting and overfitting.

The graph must be acyclic

A Bayesian network must be a directed acyclic graph (DAG). It cannot contain a directed cycle such as one variable causing a second variable, which in turn causes the first.

The acyclic structure allows the variables to be ordered so that each variable can be generated after its parents.


5. Conditional Probability Tables

To specify a Bayesian network, each node must be given a probability distribution conditioned on its parents.

For a binary variable XXX with parents P1,…,PmP_1, \ldots, P_mP1​,…,Pm​, the model specifies the probability that X=1X=1X=1 for every possible assignment of values to the parents. When the parents are binary, there are 2m2^m2m parent assignments.

The probability that X=0X=0X=0 can then be calculated from:

P(X=0∣P1,…,Pm)=1−P(X=1∣P1,…,Pm)P(X=0 \mid P_1,\ldots,P_m) = 1-P(X=1 \mid P_1,\ldots,P_m)P(X=0∣P1​,…,Pm​)=1−P(X=1∣P1​,…,Pm​)

Thus, for binary variables, a table can specify just the probability of 111 for each parent assignment.

Nodes without parents

A node without parents has an unconditional probability distribution. These probabilities resemble priors.

For example, a simplified model might assign:

  • P(flu=1)=0.1P(\text{flu}=1)=0.1P(flu=1)=0.1

  • P(undergraduate=1)=0.8P(\text{undergraduate}=1)=0.8P(undergraduate=1)=0.8

The complementary probabilities are P(flu=0)=0.9P(\text{flu}=0)=0.9P(flu=0)=0.9 and P(undergraduate=0)=0.2P(\text{undergraduate}=0)=0.2P(undergraduate=0)=0.2.

Nodes with parents

Suppose fever has flu as its parent. The model must specify the probability of fever for each possible flu value, such as:

  • P(fever=1∣flu=0)P(\text{fever}=1 \mid \text{flu}=0)P(fever=1∣flu=0)

  • P(fever=1∣flu=1)P(\text{fever}=1 \mid \text{flu}=1)P(fever=1∣flu=1)

If tiredness has both flu and undergraduate status as parents, the model needs one probability for each of the four possible assignments to those two binary parents.

The number of entries needed for a node therefore depends exponentially on its number of parents. A node with mmm binary parents requires probabilities for 2m2^m2m parent assignments. Keeping the number of parents modest is important for compactness.

Where probability values come from

The numerical probabilities in a model can come from:

  • Data: observed frequencies in a dataset can be used to estimate probabilities.

  • Expert judgment: an expert may provide reasonable estimates when suitable data are unavailable.

Expert estimates are useful but should be treated cautiously. Their accuracy depends on the expert’s assumptions and knowledge.


6. The Joint Distribution Implied by a Bayesian Network

A Bayesian network specifies the joint distribution by multiplying the probability of each variable conditioned on its parents. If the variables are X1,…,XnX_1,\ldots,X_nX1​,…,Xn​, then:

P(X1,…,Xn)=∏i=1nP(Xi∣Parents⁡(Xi))P(X_1,\ldots,X_n) = \prod_{i=1}^{n} P(X_i \mid \operatorname{Parents}(X_i))P(X1​,…,Xn​)=∏i=1n​P(Xi​∣Parents(Xi​))

Each conditional probability uses the particular values assigned to that variable and its parents.

Example network

Consider four binary variables:

  • FFF: whether the person has flu

  • UUU: whether the person is an undergraduate

  • VVV: whether the person has a fever

  • TTT: whether the person is tired

Suppose the graph contains these relationships:

  • Flu influences fever.

  • Flu influences tiredness.

  • Undergraduate status influences tiredness.

The joint distribution factors as:

P(F,U,V,T)=P(F)P(U)P(V∣F)P(T∣F,U)P(F,U,V,T) = P(F)P(U)P(V \mid F)P(T \mid F,U)P(F,U,V,T)=P(F)P(U)P(V∣F)P(T∣F,U)

For a particular assignment, such as no flu, undergraduate, no fever, and tired, the joint probability is:

P(F=0,U=1,V=0,T=1)=P(F=0)P(U=1)P(V=0∣F=0)P(T=1∣F=0,U=1)P(F=0,U=1,V=0,T=1) = P(F=0)P(U=1)P(V=0 \mid F=0)P(T=1 \mid F=0,U=1)P(F=0,U=1,V=0,T=1)=P(F=0)P(U=1)P(V=0∣F=0)P(T=1∣F=0,U=1)

Using the illustrative values P(F=0)=0.9P(F=0)=0.9P(F=0)=0.9, P(U=1)=0.8P(U=1)=0.8P(U=1)=0.8, P(V=1∣F=0)=0.05P(V=1 \mid F=0)=0.05P(V=1∣F=0)=0.05, and P(T=1∣F=0,U=1)=0.8P(T=1 \mid F=0,U=1)=0.8P(T=1∣F=0,U=1)=0.8:

P(F=0,U=1,V=0,T=1)=0.9×0.8×0.95×0.8=0.5472P(F=0,U=1,V=0,T=1) = 0.9 \times 0.8 \times 0.95 \times 0.8 = 0.5472P(F=0,U=1,V=0,T=1)=0.9×0.8×0.95×0.8=0.5472

The fever probability in this assignment is P(V=0∣F=0)=1−0.05=0.95P(V=0 \mid F=0)=1-0.05=0.95P(V=0∣F=0)=1−0.05=0.95.


7. Why Bayesian Networks Compress Models

A Bayesian network encodes assumptions about which variables influence one another. These assumptions imply independencies that allow the joint distribution to be represented with fewer numbers.

For example, if there is no modeled connection between flu and undergraduate status, the network treats them as independent in this model. Their probabilities can be specified separately rather than requiring a separate probability for every combination of flu and undergraduate status.

The compression depends on the graph:

  • With a small number of parents per node, the probability representation can grow roughly in proportion to the number of nodes.

  • With many parents per node, the conditional tables can become large.

  • If every node is connected to many others, the network may approach the complexity of a full joint table.

Thus, the graph’s structure—not just the number of variables—determines how compact the representation is.

The compactness of a Bayesian network comes from its conditional-independence assumptions. These assumptions are useful when reasonable, but they can make the model inaccurate if important relationships are omitted.


8. Bayesian Networks as Generative Models

A Bayesian network provides a generative story: a description of how a complete assignment of values could be produced.

To sample one synthetic person from the four-variable network:

  1. Sample flu from its unconditional distribution.

  2. Sample undergraduate status from its unconditional distribution.

  3. Sample fever using the sampled flu value.

  4. Sample tiredness using the sampled flu and undergraduate values.

The result is a complete assignment to all four variables. Repeating the process produces samples from the joint distribution implied by the network.

This process is not inference. It creates hypothetical individuals according to the model. Inference begins when evidence about an actual or hypothetical individual is observed and beliefs about other variables are updated.

A generative model can also be written as a computer program. A program that correctly samples complete assignments from the network is another way of expressing its joint distribution.


9. Inference from a Joint Distribution

Once a joint distribution is available, any conditional probability can be computed from it. The basic conditional-probability definition is:

P(A∣B)=P(A,B)P(B)P(A \mid B)=\frac{P(A,B)}{P(B)}P(A∣B)=P(B)P(A,B)​

For a question such as “What is the probability of flu given that the person has no fever, is not an undergraduate, and is not tired?”, the numerator is the joint probability of all those values together. The denominator is the probability of the evidence, regardless of whether the person has flu.

Marginalization

When a probability is needed for only some variables, the other variables must be summed out. This operation is called marginalization.

For example, if the joint distribution includes flu FFF, undergraduate status UUU, fever VVV, and tiredness TTT, then the probability of an assignment to UUU, VVV, and TTT is:

P(U=u,V=v,T=t)=∑f∈{0,1}P(F=f,U=u,V=v,T=t)P(U=u,V=v,T=t) = \sum_{f \in \{0,1\}} P(F=f,U=u,V=v,T=t)P(U=u,V=v,T=t)=∑f∈{0,1}​P(F=f,U=u,V=v,T=t)

The sum includes the two possible values of flu. These cases are mutually exclusive and together cover all possibilities for flu.

More generally, a query probability is obtained by summing the joint probabilities over all assignments to variables not specified by the query or evidence. For a target QQQ, evidence E=eE=eE=e, and hidden variables HHH:

P(Q∣E=e)=∑hP(Q,E=e,H=h)∑q∑hP(Q=q,E=e,H=h)P(Q \mid E=e) = \frac{\sum_h P(Q,E=e,H=h)} {\sum_q \sum_h P(Q=q,E=e,H=h)}P(Q∣E=e)=∑q​∑h​P(Q=q,E=e,H=h)∑h​P(Q,E=e,H=h)​

The numerator sums over hidden variables while keeping the target and evidence fixed. The denominator sums over all possible target values and hidden-variable assignments consistent with the evidence.

This gives a general strategy for inference:

  1. Express the needed terms using the joint distribution.

  2. Sum over variables whose values are not specified.

  3. Divide the joint probability of the query and evidence by the probability of the evidence.


10. Independence of Random Variables

Two events are independent when the probability that they both occur equals the product of their individual probabilities. For random variables, independence is a stronger claim: the equality must hold for every possible pair of values.

Random variables XXX and YYY are independent if:

P(X=x,Y=y)=P(X=x)P(Y=y)P(X=x,Y=y)=P(X=x)P(Y=y)P(X=x,Y=y)=P(X=x)P(Y=y)

for every possible xxx and yyy.

Intuitively, knowing the value of one independent random variable does not change the probability distribution of the other.

Example: Two dice

Let D1D_1D1​ be the result of the first die, D2D_2D2​ the result of the second die, and S=D1+D2S=D_1+D_2S=D1​+D2​ their sum.

The event D1=1D_1=1D1​=1 has probability 16\frac{1}{6}61​. The event S=7S=7S=7 also has probability 636=16\frac{6}{36}=\frac{1}{6}366​=61​. Their joint event requires the first die to be 111 and the second die to be 666, so:

P(D1=1,S=7)=136P(D_1=1,S=7)=\frac{1}{36}P(D1​=1,S=7)=361​

Since:

136=16×16\frac{1}{36} = \frac{1}{6}\times\frac{1}{6}361​=61​×61​

these two particular events are independent.

However, this does not mean that the random variables D1D_1D1​ and SSS are independent. Independence of the random variables requires the product rule to hold for every possible assignment. For example, knowing D1=6D_1=6D1​=6 rules out a sum of 555, so information about one variable can affect beliefs about the other.


11. Covariance and Correlation

Independence is a strong property. When working with numerical variables, covariance offers a numerical measure of how two variables vary together.

For values xxx and yyy, consider the product of their deviations from their means:

(x−E[X])(y−E[Y])(x-\mathbb{E}[X])(y-\mathbb{E}[Y])(x−E[X])(y−E[Y])
  • If both values are above their means, both deviations are positive and their product is positive.

  • If both are below their means, both deviations are negative and their product is also positive.

  • If one is above its mean and the other is below, the product is negative.

Covariance is the expected value of this product:

Cov⁡(X,Y)=E[(X−E[X])(Y−E[Y])]\operatorname{Cov}(X,Y) = \mathbb{E}\left[(X-\mathbb{E}[X])(Y-\mathbb{E}[Y])\right]Cov(X,Y)=E[(X−E[X])(Y−E[Y])]

An equivalent computational form is:

Cov⁡(X,Y)=E[XY]−E[X]E[Y]\operatorname{Cov}(X,Y) = \mathbb{E}[XY]-\mathbb{E}[X]\mathbb{E}[Y]Cov(X,Y)=E[XY]−E[X]E[Y]

To estimate covariance from paired observations, one approach is to calculate the product XYXYXY for each observation, average those products, and subtract the product of the two variables’ averages.

Interpreting covariance

  • Positive covariance: the variables tend to be above their means together and below their means together.

  • Negative covariance: when one tends to be above its mean, the other tends to be below its mean.

  • Covariance near zero: positive and negative contributions tend to cancel; the variables may have little linear co-variation.

Covariance describes an association in how variables vary. It does not establish that one variable causes the other. Also, zero covariance does not generally prove independence; it only indicates a lack of linear co-variation.

Correlation

Correlation standardizes covariance by the standard deviations of the two variables:

Corr⁡(X,Y)=Cov⁡(X,Y)σXσY\operatorname{Corr}(X,Y) = \frac{\operatorname{Cov}(X,Y)} {\sigma_X\sigma_Y}Corr(X,Y)=σX​σY​Cov(X,Y)​

When both standard deviations are nonzero, correlation is unitless and ranges from −1-1−1 to 111. It provides a standardized measure of linear association, whereas covariance depends on the variables’ measurement scales.


12. Using Covariance to Explore Data

Covariance can be calculated across many pairs of variables to identify which variables tend to vary together. For example, in data about people’s music preferences:

  • Liking punk may have positive covariance with liking rock.

  • Liking metal may have positive covariance with liking hard rock.

  • Liking metal may have negative covariance with liking pop.

These relationships can guide the design of a probabilistic model. If two variables vary together, their relationship may be worth investigating when deciding how to structure the model.

However, covariance alone does not provide a complete causal explanation. It is a useful exploratory statistic, not proof that one preference causes another. A modeler must use both data and reasoning to decide which dependencies are meaningful.


13. Probabilistic Models for Complex Human Behavior

Probabilistic modeling can describe complex processes involving many connected choices. One example is modeling the mistakes made by beginner programmers.

Simple statistics, such as counting mistakes alongside features like loops or conditional statements, may not explain what misconception a student has. A probabilistic model can instead describe a generative process for how a student might construct a program. The resulting model can be used to infer likely misconceptions from the program’s structure.

This approach is related to generative models of handwritten characters: rather than merely recording which character was written, a model describes a process that could generate the character’s parts and structure. A similar approach can describe how a beginner might generate a short program. Properly structured probabilistic models can therefore support useful predictions even when the behavior being modeled has many interacting components.

The general modeling process is to identify relevant variables, decide which relationships are important, specify probabilities for those relationships, and use the resulting joint distribution to perform inference.

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent