Lecture 18

CDFs, random variables,
and conditional probability

Sparse connections · token sampling · SQL parsing · agent traces

Vishnu Boddeti

Concepts from Today's Lecture

Outcome space

Specify $(\Omega,\mathcal A,P)$. An outcome might be a uniform draw or a complete agent trace.

A probability belongs to a measurable subset of $\Omega$.

Random variable

A measurable map $X$ assigns a value to each outcome.

$P_X(A)=P(X^{-1}(A))$

The preimage identifies the original outcomes whose values lie in $A$.

Cumulative distribution

$F_X(x)=P(\{\omega:X(\omega)\le x\})$

The CDF accumulates the mass of values at or below $x$.

Condition on an event

Choose an event $B$ with $P(B)>0$, restrict to its outcomes, and renormalize.

$P(A\mid B)=\dfrac{P(A\cap B)}{P(B)}$

Read jumps and continuous mass from a CDF

The jump $F_X(x)-F_X(x^-)$ equals $P(X=x)$. A filled endpoint gives the CDF value.

A CDF determines a probability measure on $\mathbb R$. A density describes its absolutely continuous component.

Example 1

Sparse networks use gates with exact zeros

Hard-concrete gates · The distribution induced by clipping

Tail mass becomes endpoint mass

One connection has effective weight $Zw$

The paper learns the distribution of a continuous gate variable $S$. Clipping gives

$Z=\min(1,\max(0,S)).$

$S\le0$$Z=0$
$0<S<1$$Z=S$
$S\ge1$$Z=1$

The whole lower tail maps to one point. This creates the singular, atomic component of the output measure.

Use the source CDF $F_S$

$P(Z=0)=F_S(0)$

$P(0<Z<1)=F_S(1)-F_S(0)$

$P(Z=1)=1-F_S(1)$

The connection is active when $Z>0$. Its activity probability is $1-F_S(0)$, which enters the paper's sparsity penalty.

Hard-concrete gates · Calculate the three components

Read the gate's masses from its CDF

Source $F_S$Clipped output $F_Z$
input
neuron

For $\gamma<t<\zeta$, $F_S(t)=\sigma\!\left(\beta\log\frac{t-\gamma}{\zeta-t}-a\right)$.
$\sigma(v)=1/(1+e^{-v})$, $\beta=2/3$, $\gamma=-0.1$, $\zeta=1.1$.

Mass at zero
Mass inside $(0,1)$
Mass at one
Connection active

Try moving $a$ left and right. Identify the two jumps and check that the three masses sum to 1.

Example 2

Decoding maps a uniform draw to a token

Token decoding · Give the random variable a numeric value

Interval lengths become token masses

Choose a numeric encoding

$i$Token$p_i$ at $T=1$$F_X(i)$
1The0.50.5
2A0.30.8
3This0.21.0

These illustrative masses describe a small vocabulary at a fixed prompt. The indices provide an ordering for the CDF.

Define the measurable map

Use length measure on $\Omega=(0,1]$ and let $U$ be its coordinate.

$X(u)=\min\{i:F_X(i)\ge u\}.$

The preimage of token 2 is $(0.5,0.8]$. Its length is $0.3$, giving $P(X=2)=0.3$.

At $u=0.65$, the decoder emits token 2.

Where would $u=0.90$ land? Which set of uniform draws emits token 3?

Token decoding · Follow one uniform draw

Connect each interval to a CDF jump

Token$p_i$$F_X(i)$Preimage of $i$
The
A
This
Emitted index and token
Selected interval's mass

Moving $U$ changes the selected outcome. Changing $T$ changes the interval lengths through $p_i\propto e^{\log(p_i^{\rm base})/T}$.

Example 3

PICARD checks tokens against a SQL parser state

PICARD · Restrict to admissible outcomes

Condition the next token on parser validity

A small teaching schema

students(name, age)courses(title, credits)

The prefix is the query text written so far. Our teaching grammar expects a column after SELECT and a table after FROM.

The four candidate masses are $0.4,0.3,0.2,0.1$ for name, age, students, courses.

Let $G$ be the valid-token event

After SELECT, $G=\{\text{name},\text{age}\}$, with $P(G)=0.7$.

$Q(A)=P(A\mid G)=\dfrac{P(A\cap G)}{P(G)}$

Thus $Q(\text{name})=4/7$ and $Q(\text{age})=3/7$.

The numbers and vocabulary are illustrative. The paper supplies the incremental parsing mechanism.

PICARD · Calculate the conditional distribution

A new prefix changes the admissible set

SELECT

CandidateBase $P$Valid?$P(\cdot\mid G)$
name0.40
age0.30
students0.20
courses0.10

The parser chooses the admissible subset at the current prefix. Each surviving mass is divided by that subset's total mass.

Admissible mass $P(G)$

Switch to FROM. Identify the retained rows, add their base masses, and check that the conditional column sums to 1.

students(name, age)courses(title, credits)

Example 4

Agent traces induce a distribution of tool-call counts

ReAct · From structured outcomes to a numeric variable

Which traces map to $X\le2$?

One trace records a sequence

Think about the questionSearch and read an observationLookup and read an observationFinish with an answer

Define $X(\omega)$ as the number of external tool calls in trace $\omega$. The illustrated trace has $X=2$.

Specify the outcome measure

Use six illustrative traces, each with mass $1/6$. Their call counts are $(1,1,2,2,2,3)$.

$X^{-1}((-\infty,2])=\{T_1,T_2,T_3,T_4,T_5\}$

Thus $F_X(2)=5/6$.

Conditioning on the four successful traces restricts the outcome set and gives each retained trace mass $1/4$.

ReAct · Calculate probabilities by selecting records

Filter the trace table and rebuild its CDF

TraceExternal calls$X$Solved?
T1Search1No
T2Search1Yes
T3Search, Lookup2Yes
T4Search, Search2No
T5Search, Lookup2Yes
T6Search, Lookup, Search3Yes

Search and Lookup count toward $X$. Finish returns the answer.

Highlighted records
Records in outcome set
Probability

Uniform mass on the selected records.

Practice problems

Each scenario hides a mathematical structure from this lecture. Identify the structure, justify it, and work through the resulting problem.

Problem 1 Inference systems

Set a latency service threshold from a distribution

A model server's latency follows a known continuous distribution. Rather than sorting a huge pile of requests, you want to compute the deadline that 95% of requests will meet.

Model evidence

Latency $T$ has density $f_T(t)=\frac12e^{-t/2}$ for $t\ge0$ and zero otherwise.

  1. What is the cumulative distribution function?
  2. Which latency is the 95th percentile?
  3. What is the probability of a latency between one and three seconds?
Problem 2 Anomaly detection

Find the distribution of a squared anomaly score

Under normal operation, a detector observes a feature uniformly between $-1$ and $1$, then squares it to produce an anomaly score. Squaring folds the negative and positive halves together—what distribution does that create?

Model evidence

$X\sim\mathrm{Uniform}[-1,1]$ and $Y=X^2$.

  1. What values can $Y$ take, and what is its CDF?
  2. Where a density exists, what is it?
  3. Which threshold is exceeded by only 10% of normal examples?
Problem 3 Data labeling

Condition on a positive annotation

Uniformly choose one of 100 labelled records. Let $Y\in\{0,1\}$ be the true label and $\widehat{Y}\in\{0,1\}$ the weak annotator's label. The table gives record counts.

Model evidence

$\begin{array}{c|cc} & \widehat{Y}=1 & \widehat{Y}=0 \\ \hline Y=1 & 18 & 2 \\ Y=0 & 8 & 72 \end{array}$

  1. Specify the outcome space and normalized counting measure. What is $P(\widehat{Y}=1)$?
  2. What mass does the event $\{Y=0\}\cap\{\widehat{Y}=1\}$ have?
  3. Retain only records with $\widehat{Y}=1$. What fraction have $Y=0$? Write $P(Y=0\mid\widehat{Y}=1)$ and identify its numerator and denominator.