AI Wiki中文/EN

Conditional probability

条件概率

Why does information change the denominator? Use a fault–alarm table to separate conditional probability, joint probability, and causation.

On this pageIntuitionMathematics & methodImplementationLimitationsExercisesResearch connections

After an alarm, which group should you count?

Consider an invented table of 100 machines: 18 are faulty and alarm, 2 are faulty without alarming, 8 are healthy but alarm, and 72 are healthy without alarming. Assume a machine is chosen uniformly from these 100. We are analyzing the model defined by this table.

Machine conditionAlarmNo alarmTotal
Faulty18220
Healthy87280
Total2674100

Knowing that the selected machine alarmed restricts the count to 26 alarming machines: 18/26=9/1318/26=9/13 are faulty. Knowing instead that it is faulty restricts the count to 20 faulty machines: 18/20=0.918/20=0.9 alarm. The numerator is 18 in both cases, but the denominators and questions differ.

A condition restricts the reference set

For an event BB with P(B)>0P(B)>0, define:

P(A∣B)=P(A∩B)P(B).P(A\mid B)=\frac{P(A\cap B)}{P(B)}.

The numerator keeps outcomes satisfying both AA and condition BB. The denominator rescales the entire conditioning set to probability 1. Thus P(B∣B)=1P(B\mid B)=1, P(Ω∣B)=1P(\Omega\mid B)=1, and P(∅∣B)=0P(\varnothing\mid B)=0. This is a probability model after receiving information, not an exchange of event labels. Deep Learning, Section 3.5

Rearranging gives the product rule. When the relevant conditioning probabilities are positive, the decomposition extends to three events:

P(A∩B)=P(B)P(A∣B),P(A∩B∩C)=P(A)P(B∣A)P(C∣A∩B).P(A\cap B)=P(B)P(A\mid B),\qquad P(A\cap B\cap C)=P(A)P(B\mid A)P(C\mid A\cap B).

The last term retains information from both preceding events; it cannot arbitrarily be replaced by P(C)P(C). The chain decomposition does not require independence. Independence can simplify particular conditional probabilities when its assumptions hold.

For pairwise disjoint events B1,…,BkB_1,\ldots,B_k covering the sample space, with the relevant conditional probabilities defined, total probability gives:

P(A)=∑i=1kP(A∣Bi)P(Bi).P(A)=\sum_{i=1}^{k}P(A\mid B_i)P(B_i).

Partitioning by faulty and healthy machines gives alarm probability 0.9×0.2+0.1×0.8=0.260.9\times0.2+0.1\times0.8=0.26. Group weights matter. Directly averaging 0.9 and 0.1 would incorrectly give 0.5 because the groups differ in size. MML, Sections 6.2–6.3

Keep the denominator visible

This complete Python program works directly with the table’s counts. Keys mean “faulty?” followed by “alarm?” It calculates exact proportions for this table without automatically treating them as known parameters of another machine population.

from fractions import Fraction as F

counts = {(True, True): 18, (True, False): 2,
          (False, True): 8, (False, False): 72}

def conditional(event, given):
    denominator = sum(n for outcome, n in counts.items() if given(outcome))
    if denominator == 0:
        raise ValueError("conditioning set has zero mass")
    numerator = sum(n for outcome, n in counts.items()
                    if given(outcome) and event(outcome))
    return F(numerator, denominator)

fault = lambda outcome: outcome[0]
alarm = lambda outcome: outcome[1]
assert conditional(fault, alarm) == F(9, 13)
assert conditional(alarm, fault) == F(9, 10)
assert conditional(alarm, alarm) == 1
assert conditional(lambda _: False, alarm) == 0
try:
    conditional(fault, lambda _: False)
    raise AssertionError("zero conditioning mass was accepted")
except ValueError:
    pass

Filtering and summing a table of nn entries takes O(n)O(n) operations. Two scans keep the logic explicit. Engineering implementations can cache common group counts, but should retain denominators to expose small groups and changes in definitions.

Conditioning, selection, and intervention

Observing an alarm is different from actively making a machine sound an alarm. The former can reveal an underlying fault; the latter might mean someone pressed a button. Conditional probability describes associations in a joint distribution, not whether an intervention changes faults. Causal inference distinguishes these questions explicitly.

How information arrives also matters. Randomly selecting an alarming machine and having an engineer select the most suspicious alarming machine can produce different distributions. Using the same 9/139/13 requires checking whether selection matches the table’s model. A table containing only repair-shop machines also need not represent all machines.

Small denominators make empirical proportions unstable. A group containing one faulty machine has an observed rate of 100%, not proof of population probability 1. Conditioning a continuous variable on an exact point can produce 0/00/0 in the finite-event formula. Conditional densities or more general conditional distributions require further definitions; setting the result arbitrarily to zero is not a solution.

State exactly what is known

  1. What fraction of healthy machines alarm? Answer: 8/80=0.18/80=0.1.
  2. What fraction of non-alarming machines are faulty? Answer: 2/74=1/372/74=1/37, not 2/202/20.
  3. Three of ten parts are defective. After drawing one defective part without replacement, what is the probability that the next is defective? Answer: 2/92/9. The remaining population has changed.
  4. Does a high observed alarm rate show that causing more alarms creates more faults? Answer: no. Observational association and causal intervention are different questions.

Connecting to Bayesian updating

The same joint probability can be decomposed in two directions: conditioning on a fault or conditioning on an alarm. Equating those expressions gives Bayes’ theorem. When studying conditional independence, graphical models, and sequence probabilities, continue writing the conditioning set explicitly. Many mistakes occur when a condition silently disappears, before any multiplication is performed.

Make a prediction, then check

There are 26 alarming machines, including 18 faulty ones. Given an alarm, what is the denominator for fault probability?

Choose one answer

Learning objectives

  • Select the correct conditional denominator in a two-way table.
  • Apply product and total-probability rules, and distinguish selection from intervention.

Prerequisites & connections

Explore related knowledge →

References

  1. Mathematics for Machine Learning — mathematical foundations (2024-01-15 draft)
    Marc Peter Deisenroth; A. Aldo Faisal; Cheng Soon Ong · 2020
  2. Deep Learning — Chapter 3: Probability and Information Theory
    Ian Goodfellow; Yoshua Bengio; Aaron Courville · 2016

Version1 · Editorial status: Recorded technical checks completed

View technical check record (AI)

Codex · 2026-09-05 · Codex technical check: cited-source comparison, re-derivation and recalculation, bilingual argument comparison, and executed Python assertions; no independent human peer review.

  • Checked every cell of the 100-machine table and recomputed 9/13, 9/10, 1/37, and alarm rate 0.26.
  • Checked positive denominators, chain decomposition, weighted total probability, and zero-mass rejection; preserved the observation/intervention distinction.
  • Compared the main arguments, numerical examples, exercises, and answers across languages; structural checks additionally compare display equations, source lists, and code.
  • Reviewed the answer-label rendering fix: only Markdown emphasis markers changed to strong tags; normalized text and all code are identical.

Source locations checked:

Related topics

No matches. Try a synonym or acronym.

0 results shown

Wrap the whole query in double quotes for a phrase match.