Session 10: Detection

Movement III: Two Random Variables

EE 520: Random Processes (Fall 2026). Instructor: John Lipor.

Launch

A lidar range gate either contains the reflected return of a target or it does not. Over the gate’s integration window a photon counter reports a single number: today it reads 77. Target, or no target? The honest news is that you have known everything needed to answer this since Session 2. There are two hypotheses, a prior over them, and a measurement whose distribution depends on which hypothesis is true; Bayes’ rule turns that into a posterior, and a decision is the posterior handed to an arg max\operatorname*{arg\,max}. Today we do not learn new probability. We organize what we have into the standard vocabulary of detection: likelihood ratios, thresholds, and the two ways a detector can be wrong. The one genuinely new idea is small and powerful, that a broad family of these rules collapses to a single comparison “is the raw reading big enough?”

Development

The binary detection problem

Let θ∈{0,1}\theta \in \left\{0, 1\right\} be the latent state: θ=1\theta = 1 means the target is present (the alternative hypothesis H1H_1), θ=0\theta = 0 means it is absent (the null hypothesis H0H_0). Write the prior π1=ℙ(θ=1),π0=ℙ(θ=0)=1−π1.\begin{equation} \pi_1 = \mathbb{P}(\theta = 1), \qquad \pi_0 = \mathbb{P}(\theta = 0) = 1 - \pi_1 . \end{equation} We observe YY, whose distribution depends on θ\theta through the two likelihoods f(y|θ=0)f(y \,|\,\theta = 0) and f(y|θ=1)f(y \,|\,\theta = 1) (densities for continuous YY, PMFs for discrete YY; the theory is identical). A decision rule is any function δ(y)∈{0,1}\delta(y) \in \left\{0, 1\right\} that reads the data and declares a hypothesis. A rule can fail in exactly two ways:

These are not symmetric in general, neither in how often they happen nor in what they cost, and keeping them apart is half of detection.

The MAP and ML rules

Once Y=yY = y is in hand, the posterior over θ\theta is Session 2’s Bayes’ rule: ℙ(θ=1|y)=π1f(y|1)π1f(y|1)+π0f(y|0),\begin{equation} \mathbb{P}(\theta = 1 \,|\,y) = \frac{\pi_1 f(y \,|\,1)}{\pi_1 f(y \,|\,1) + \pi_0 f(y \,|\,0)}, \end{equation} and likewise for θ=0\theta = 0. The most defensible single guess is the more probable state.

Definition 1 (MAP rule). The maximum a posteriori rule declares θ=1\theta = 1 iff ℙ(θ=1|y)≥ℙ(θ=0|y)\mathbb{P}(\theta = 1 \,|\,y) \ge \mathbb{P}(\theta = 0 \,|\,y).

The two posteriors share the same denominator (the evidence), so the comparison is between the numerators, π1f(y|1)≥π0f(y|0)\pi_1 f(y \,|\,1) \ge \pi_0 f(y \,|\,0). Divide by π1f(y|0)\pi_1 f(y \,|\,0) and the prior collects on one side: L(y)=f(y|1)f(y|0)≷01π0π1,\begin{equation} L(y) \;=\; \frac{f(y \,|\,1)}{f(y \,|\,0)} \;\mathrel{\overset{1}{\underset{0}{\gtrless}}}\; \frac{\pi_0}{\pi_1}, \label{eq:maplrt} \end{equation} read: declare θ=1\theta = 1 when the top inequality holds. The single quantity L(y)L(y), the likelihood ratio, carries the entire evidentiary content of the observation; this is the object Session 2 promised would return as the detection statistic. Everything the data say about θ\theta enters through L(y)L(y), and the prior enters only through the threshold π0/π1\pi_0 / \pi_1.

When the two states are equally likely a priori, π0/π1=1\pi_0 / \pi_1 = 1 and the rule keeps only the likelihoods.

Definition 2 (ML rule). The maximum likelihood rule is the equal-prior special case of MAP: declare θ=1\theta = 1 iff L(y)≥1L(y) \ge 1, equivalently f(y|1)≥f(y|0)f(y \,|\,1) \ge f(y \,|\,0).

Both rules are the estimators of Session 9 pointed at a two-valued unknown: θ̂MAP=arg max⁡θℙ(θ|y)\hat{\theta}_{\mathrm{MAP}} = \operatorname*{arg\,max}_{\theta} \mathbb{P}(\theta \,|\,y) and θ̂ML=arg max⁡θf(y|θ)\hat{\theta}_{\mathrm{ML}} = \operatorname*{arg\,max}_{\theta} f(y \,|\,\theta), now written as a threshold on LL.

Remark 1 (Work with the log-likelihood ratio). When YY is a vector of conditionally independent readings the likelihoods multiply, and it is cleaner to take logarithms: the rule L(y)≥π0/π1L(y) \ge \pi_0/\pi_1 becomes log⁡L(y)=∑ilog⁡f(yi|1)f(yi|0)≥log⁡(π0/π1)\log L(y) = \sum_i \log \frac{f(y_i \,|\,1)}{f(y_i \,|\,0)} \ge \log(\pi_0/\pi_1). Products become sums, underflow disappears, and the threshold is a single additive constant. We use the log form in the energy-detector example.

Why MAP is optimal

Proposition 1 (MAP minimizes the probability of error). Among all decision rules δ\delta, the MAP rule minimizes the total error probability ℙ(δ(Y)≠θ)\mathbb{P}(\delta(Y) \ne \theta).

Proof. Both θ\theta and YY are random here: θ\theta is drawn from the prior and then YY from f(y|θ)f(y \,|\,\theta), while the rule δ\delta is a fixed function. Write the error probability as the expectation of an indicator and condition on the observation, using the tower property of Session 9: ℙ(δ(Y)≠θ)=𝔼[𝟙{δ(Y)≠θ}]=𝔼Y[𝔼[𝟙{δ(Y)≠θ}|Y]].\begin{equation} \mathbb{P}(\delta(Y) \ne \theta) = \mathbb{E}\left[\mathbb{1}\left\{\delta(Y) \ne \theta\right\}\right] = \mathbb{E}_Y\left[\mathbb{E}\left[\mathbb{1}\left\{\delta(Y) \ne \theta\right\} \,|\,Y\right]\right]. \end{equation} For the inner expectation, freeze Y=yY = y, so that δ(y)\delta(y) is a fixed 00 or 11 and only θ\theta remains random. Splitting on the two possible decisions, 𝟙{δ(y)≠θ}=δ(y)𝟙{θ=0}+(1−δ(y))𝟙{θ=1}\mathbb{1}\left\{\delta(y) \ne \theta\right\} = \delta(y)\,\mathbb{1}\left\{\theta = 0\right\} + \left(1 - \delta(y)\right)\mathbb{1}\left\{\theta = 1\right\}. Since θ\theta and YY are dependent, the condition cannot be dropped, and the posterior appears: 𝔼[𝟙{δ(Y)≠θ}|Y=y]=δ(y)ℙ(θ=0|y)+(1−δ(y))ℙ(θ=1|y)≥min⁡{ℙ(θ=0|y),ℙ(θ=1|y)},\begin{equation} \begin{split} \mathbb{E}\left[\mathbb{1}\left\{\delta(Y) \ne \theta\right\} \,|\,Y = y\right] &= \delta(y)\,\mathbb{P}(\theta = 0 \,|\,y) + \left(1 - \delta(y)\right)\mathbb{P}(\theta = 1 \,|\,y) \\ &\ge \min\left\{\mathbb{P}(\theta = 0 \,|\,y),\ \mathbb{P}(\theta = 1 \,|\,y)\right\}, \end{split} \end{equation} with equality exactly when the rule declares whichever state has the larger posterior, which is the MAP rule. Averaging over YY, ℙ(δ(Y)≠θ)≥𝔼Y[min{ℙ(θ=0|Y),ℙ(θ=1|Y)}],\begin{equation} \mathbb{P}(\delta(Y) \ne \theta) \ge \mathbb{E}_Y\left[\min\left\{\mathbb{P}(\theta = 0 \,|\,Y),\ \mathbb{P}(\theta = 1 \,|\,Y)\right\}\right], \end{equation} and the MAP rule attains the lower bound at every yy, hence in the average. Choosing the larger posterior pointwise is optimal pointwise, and an average of pointwise-optimal choices is optimal. ◻

The anatomy of error

Two conditional probabilities summarize any fixed rule: PFA=ℙ(δ(Y)=1|θ=0),PMD=ℙ(δ(Y)=0|θ=1),\begin{equation} P_{FA} = \mathbb{P}(\delta(Y) = 1 \,|\,\theta = 0), \qquad P_{MD} = \mathbb{P}(\delta(Y) = 0 \,|\,\theta = 1), \end{equation} and the total error weights them by the prior, ℙ(error)=π0PFA+π1PMD.\begin{equation} \mathbb{P}(\text{error}) = \pi_0 P_{FA} + \pi_1 P_{MD}. \label{eq:toterr} \end{equation} The MAP threshold minimizes this particular weighted sum, the one in which both mistakes count equally per unit prior probability. When the two errors carry different costs, a miss more expensive than a false alarm, the threshold moves off the MAP point: this is precisely Session 7’s expected-utility calculation and the payoff matrix of HW3, and it is why the MAP threshold is only the equal-cost corner of a whole family. We do not develop the cost-weighted rule further here.

Remark 2 (Scope). This is a first course’s detection: MAP and ML, one likelihood ratio, one threshold. The Neyman–Pearson framework (fix PFAP_{FA}, minimize PMDP_{MD}), the receiver operating characteristic that traces PFAP_{FA} against detection probability as the threshold sweeps, and composite hypotheses with unknown parameters all live in the detection-and-estimation course downstream.

Monotone likelihood ratio gives a threshold rule

The rule [eq:maplrt] is a comparison on L(y)L(y), which can be an awkward function of yy. Very often it need not be computed at all.

Proposition 2 (Monotone likelihood ratio ⇒\Rightarrow threshold on the raw data). Suppose L(y)L(y) is nondecreasing in yy. Then every MAP or ML rule has the form “declare θ=1\theta = 1 iff y≥γy \ge \gamma” for a threshold γ\gamma determined by the prior.

Proof. The rule declares θ=1\theta = 1 exactly on the set {y:L(y)≥π0/π1}\left\{y : L(y) \ge \pi_0/\pi_1\right\}. If LL is nondecreasing and L(y0)≥π0/π1L(y_0) \ge \pi_0/\pi_1 at some y0y_0, then L(y)≥L(y0)≥π0/π1L(y) \ge L(y_0) \ge \pi_0/\pi_1 for every y≥y0y \ge y_0, so the acceptance set is an upper interval {y≥γ}\left\{y \ge \gamma\right\} with γ\gamma the smallest value clearing the threshold. Comparing the likelihood ratio to a number has become comparing the reading itself to a number. ◻

This is the practical payoff of the whole session: for the standard sensor models, a detector is one number and one comparison. The next section shows it on the photon counter, and then shows what happens when LL is not monotone in the raw reading.

Worked examples

Photon counting: answering the Launch

A single-photon detector observes the gate for a fixed window. Dark counts alone (no target, θ=0\theta = 0) produce Y∼Poisson(λ0=3)Y \sim \text{Poisson}(\lambda_0 = 3); a target return adds signal photons, so with a target present (θ=1\theta = 1), Y∼Poisson(λ1=12)Y \sim \text{Poisson}(\lambda_1 = 12).

With f(y|θ)=e−λθλθy/y!f(y \,|\,\theta) = e^{-\lambda_\theta}\lambda_\theta^{\,y}/y!, the factorials cancel: L(y)=e−1212y/y!e−33y/y!=e−(12−3)(123)y=e−94y.\begin{equation} L(y) = \frac{e^{-12}\, 12^{\,y}/y!}{e^{-3}\, 3^{\,y}/y!} = e^{-(12 - 3)} \left(\frac{12}{3}\right)^{y} = e^{-9}\, 4^{\,y}. \end{equation} Since 4y4^{y} increases in yy, L(y)L(y) is monotone, so by the previous section every MAP or ML rule for this sensor is a threshold on the raw count.

Now the Launch’s reading. Seven photons give L(7)=47e−9=16384e−9≈2.02:\begin{equation} L(7) = 4^{7} e^{-9} = 16384\, e^{-9} \approx 2.02 : \end{equation} seven photons are about twice as likely with a target as without. That number is the entire contribution of the data; what we declare depends on the prior. By Session 2’s odds form, the posterior odds are L(7)L(7) times the prior odds π1/π0\pi_1/\pi_0.

The same seven photons lead to opposite declarations. Nothing about the measurement changed: the skeptical prior raised the bar that LL must clear from 11 to π0/π1=4\pi_0/\pi_1 = 4, and L(7)≈2.02L(7) \approx 2.02 falls between the two. (Sanity check on the direction, which is exactly the pitfall below: a prior leaning toward θ=0\theta = 0 demands more evidence, a larger LL, before declaring a target.)

Posterior →\to Action. Detection is the whole course in one gesture: the prior π1\pi_1 and the likelihoods f(y|θ)f(y \,|\,\theta) form the posterior ℙ(θ|y)\mathbb{P}(\theta \,|\,y), and the decision is that posterior handed to an arg max\operatorname*{arg\,max}. In the photon counter the data fixed L(7)L(7) once and for all; the prior alone decided which side of the threshold it landed on.

When the shortcut fails: an energy detector

A receiver listens for a weak signal of unknown sign: a zero-mean random waveform that adds power but has no preferred direction. A single sample reads Y∼𝒩(0,1)Y \sim {\mathcal N}(0, 1) with noise alone (θ=0\theta = 0) and Y∼𝒩(0,4)Y \sim {\mathcal N}(0, 4) when the signal is present (θ=1\theta = 1), the signal contributing independent variance 33. The priors are equal.

The tempting answer: “the signal adds energy, so large readings are suspicious; declare a target iff y≥γy \ge \gamma.” This borrows the conclusion of the monotone-likelihood-ratio proposition without checking its hypothesis. Build the likelihood ratio instead, in log form: log⁡L(y)=log⁡122πe−y2/812πe−y2/2=y22−y28−ln⁡2=38y2−ln⁡2.\begin{equation} \log L(y) = \log \frac{\frac{1}{2\sqrt{2\pi}}\, e^{-y^2/8}}{\frac{1}{\sqrt{2\pi}}\, e^{-y^2/2}} = \frac{y^2}{2} - \frac{y^2}{8} - \ln 2 = \frac{3}{8} y^2 - \ln 2 . \end{equation} LL depends on yy only through y2y^2. It is not monotone in yy: it decreases for y<0y < 0 and increases for y>0y > 0, so the proposition does not apply to yy, and a reading of −2-2 is exactly as much evidence for the signal as a reading of +2+2. It does apply to |y|\left\lvert y \right\rvert, in which LL is increasing. The ML rule is 38y2≥ln⁡2⇔|y|≥γ=8ln⁡23≈1.36,\begin{equation} \frac{3}{8} y^2 \ge \ln 2 \iff \left\lvert y \right\rvert \ge \gamma = \sqrt{\frac{8 \ln 2}{3}} \approx 1.36 , \end{equation} a threshold on the magnitude (equivalently on the energy y2y^2), which is why this is called an energy detector. Standardizing with σ=1\sigma = 1 and σ=2\sigma = 2, its errors are PFA=ℙ(|𝒩(0,1)|≥γ)=2Q(γ)≈0.174,PMD=ℙ(|𝒩(0,4)|<γ)=1−2Q(γ/2)≈0.503,\begin{equation} \begin{split} P_{FA} &= \mathbb{P}\left(\left\lvert {\mathcal N}(0,1) \right\rvert \ge \gamma\right) = 2Q(\gamma) \approx 0.174, \\ P_{MD} &= \mathbb{P}\left(\left\lvert {\mathcal N}(0,4) \right\rvert < \gamma\right) = 1 - 2Q(\gamma/2) \approx 0.503, \end{split} \end{equation} for a total error of 12(0.174+0.503)≈0.339\tfrac12(0.174 + 0.503) \approx 0.339.

The best rule of the tempting one-sided form y≥ty \ge t happens to use the same cut, t=γt = \gamma (where the two densities cross, L=1L = 1), but it ignores the negative half of the line: PFA=Q(γ)≈0.087P_{FA} = Q(\gamma) \approx 0.087, PMD=Φ(γ/2)≈0.752P_{MD} = \Phi(\gamma/2) \approx 0.752, total ≈0.419\approx 0.419. MAP optimality guaranteed the two-sided rule would win; the numbers show by how much. Two lessons. First, a threshold on the raw reading needs a monotone LL, so check monotonicity before reaching for the shortcut, and when it fails, look for the statistic (here |y|\left\lvert y \right\rvert) in which LL is monotone. Second, equal priors do not make the two errors equal: here PMDP_{MD} is nearly three times PFAP_{FA}, because the two likelihoods differ in shape, not just in location.

Consolidation

  1. (Mechanical.) Let Y∼𝒩(0,4)Y \sim {\mathcal N}(0, 4) under θ=0\theta = 0 and Y∼𝒩(3,4)Y \sim {\mathcal N}(3, 4) under θ=1\theta = 1 (σ=2\sigma = 2), with equal priors. Show that log⁡L(y)=(6y−9)/8\log L(y) = (6y - 9)/8, find the ML threshold, and give both error probabilities. (Answers: threshold y≥1.5y \ge 1.5, the midpoint; both errors Q(1.5/2)=Q(0.75)≈0.227Q(1.5/2) = Q(0.75) \approx 0.227.)

  2. (Conceptual.) In the photon example, targets become more common, say π1=0.8\pi_1 = 0.8. Without computing any tails, use the total-error formula [eq:toterr] to argue whether the MAP rule’s PFAP_{FA} and PMDP_{MD} should be larger or smaller than the ML rule’s, and explain in one sentence why a detector that is told targets are common should tolerate more false alarms. (Answer: PMDP_{MD} now carries weight 0.80.8 in the total error and PFAP_{FA} only 0.20.2, so the MAP rule buys a smaller PMDP_{MD} at the price of a larger PFAP_{FA}.)

  3. (Conceptual.) A colleague reports a detector’s “error rate” as a single number. Why is that report incomplete, and what two numbers, plus what third ingredient, would you ask for before trusting it? (Point to PFAP_{FA}, PMDP_{MD}, and the prior weighting of [eq:toterr].)

Synthesis

A probability model answers three questions: what is uncertain, what is observed, and how should observation change belief and action? Detection is the tightest possible instance of all three at once. The uncertain thing is a single bit θ\theta; the observation is one reading YY; and belief becomes action through a posterior comparison that, for every standard sensor, reduces to a threshold on a single statistic: the raw reading when LL is monotone in it, and otherwise the quantity in which LL is monotone, as the energy detector’s |y|\left\lvert y \right\rvert showed. The likelihood ratio promised in Session 2 turned out to be the whole story, carrying all the evidence and meeting a threshold set by the prior (and, silently, by costs). Nothing here was new probability; it was Bayes’ rule plus a tie-breaker, organized so that a machine can execute it.

Self-check questions

  1. Write the MAP rule as a comparison of L(y)L(y) to a number. Which number, and what happens to it as the prior π1\pi_1 grows?

  2. A detector compares L(y)L(y) to π1/π0\pi_1/\pi_0 instead of π0/π1\pi_0/\pi_1. Using the direction-of-prior sanity check, explain how you would catch the error without redoing the algebra.

  3. Why does the “monotone likelihood ratio” property matter in practice, and what does it let you avoid computing?

Pitfall. Three errors recur, and each has a cheap sanity check. (i) Inverting the likelihood ratio. L(y)=f(y|1)/f(y|0)L(y) = f(y \,|\,1)/f(y \,|\,0), signal over noise; writing it upside down flips every declaration. Check that LL is large where the target hypothesis fits the data better. (ii) Comparing L(y)L(y) to π1/π0\pi_1/\pi_0 instead of π0/π1\pi_0/\pi_1. The threshold is the prior odds against a target. Sanity check by direction: a prior that leans toward θ=0\theta = 0 should raise the bar on LL, so the skeptical prior must sit in the numerator of the threshold, not the denominator. (iii) Computing PFAP_{FA} under the wrong hypothesis. A false alarm is an event of the noise world, so PFAP_{FA} is a probability under θ=0\theta = 0; if you find yourself integrating the target likelihood to get a false-alarm rate, you have swapped the hypotheses.