models & model-based reasoning · conditioning and the inference problem · sample & observe · a first probabilistic program and its evaluator
2026-06-17
\[ \newcommand\given{{\,\vert\,}} \]
Learning Objectives
sample + observe. Conditioning is the evaluator’s job, not the program’s.We call flip() once and it returns 1.
What can we rationally conclude about the value x used in that call?
A) Nothing: every \(x \in [0,1]\) can produce 1, so our beliefs about \(x\) are unchanged.
B) Larger values of \(x\) are now more plausible: beliefs shift from uniform toward high \(x\).
C) That \(x > 0.5\): heads happened, so heads must have been the more likely outcome.
D) That \(x = 1\), the value under which the observation is most probable.
flip() is the textbook model, written as code:Computer science
parameters → program → output
run it forward: simulate
Statistics
observations → model → latents
run it backward: infer
Model-based reasoning
The model is written forwards; the questions we ask of it run backwards.
Monte Carlo
Simulators turn integrals into averages: forward questions are just sample means. The catch returns in Section 2, where the answers we want are averages under the posterior, which forward runs never produce.
| latent \(X\) | observed \(Y\) |
|---|---|
| scene description | image |
| simulation | simulator output |
| program source code | program return value |
| policy + world simulator | rewards |
| cognitive process | observed behavior |
For these pairs the joint \(p(X, Y)\) is realistically only denotable as a program: e.g. \(p(\text{image} \given \text{scene})\) is a renderer plus pixel noise.
The pattern
Write the simulator you already know how to write; let conditioning answer the inverse question.
Our second model, the course “hello world”. One unknown quantity \(\mu\), one noisy measurement \(y\):
\[\mu \sim \mathcal{N}(0, 1) \qquad y \sim \mathcal{N}(\mu, 1)\]
In your notebook: write a Python function model() that simulates one \((\mu, y)\) pair, then use it to estimate \(p(y > 2)\). Hint: random.gauss(m, s).
Models run both ways
A model is a stochastic simulator denoting a joint \(p(x,y)\). Simulation runs it forward; the interesting questions (Q1!) run it backward.
Reading
Before next class, read:
Focus while reading
Pay attention to:
sample and observe;Solutions
mu = gauss(0,1); y = gauss(mu,1) many times and take the fraction with \(y>2\), giving \(p(y>2)\approx 0.079\).Introduction to Probabilistic Programming