AI · PROBABILISTIC REASONING

15 · Probabilistic Programming

Represent uncertainty with ordinary program structure: random choices describe possible worlds, and evidence narrows which worlds remain plausible.

15.1 Relational Probability Models

Relational models share uncertainty across entities and their links. A property of one person can depend on the properties of connected people, not just on a fixed list of variables.

15.2 Open-Universe Probability Models

In an open universe, the number and identity of objects are uncertain too. A model can generate a different set of people or events in each possible world.

15.3 Keeping Track of a Complex World

A world contains many dependent random choices. Structured representations and inference algorithms make it practical to reason about only the parts relevant to a query.

15.4 Programs as Probability Models

A probabilistic program combines deterministic computation, random sampling, and observations. Running it samples worlds; conditioning on evidence focuses inference on worlds consistent with what is observed.

Key terms and a world trace

Possible world
One complete assignment to the model's random choices: here, one weather value, one population size, and one health outcome per resident.
Conditioning / evidence
Conditioning incorporates an observed fact (for example, “it is rainy”) so inference considers worlds consistent with that fact. This demo samples worlds; it does not perform posterior inference.
Open universe
The set or count of entities is itself random, rather than fixed in advance.
Shared dependency
Weather is sampled once, then influences every resident's health chance; resident outcomes are conditionally independent given that shared weather in this toy model.

Pseudocode / trace

rainy ~ Bernoulli(0.35); n ~ Uniform{1,…,6}
repeat n times: ill[i] ~ Bernoulli(rainy ? 0.58 : 0.14)
Example: rainy → n=3 → outcomes (ill, well, ill) → 2 ill residents

The numbers illustrate the assumed generator, not evidence that real weather causes illness at these rates.

Interactive model

Sample a changing population

Each run samples shared weather, an uncertain population size, then each resident's health conditional on that weather.

World summary

Not sampled

Residents: —

Ill: —

Ready. Sample a world to see its random choices.

Demo performance

Let n be the sampled resident count. Sampling uses O(1) time for weather and population count plus O(n) health draws, so total time is O(n) worst case; here n ≤ 6, making it bounded O(1) in this fixed demo. Algorithm auxiliary space is O(1) counters beyond the result; the displayed world needs O(n) DOM elements. Reset removes the displayed elements in O(n) time.