\DocumentMetadata{
  lang = en-US,
  pdfstandard = ua-2,
  pdfversion = 2.0,
  testphase = {latest}
}

\documentclass[12pt]{article}

\tagpdfsetup{math/alt/use=true}

% -------------------------
% Course / assignment metadata
% Edit these once per assignment
% -------------------------
\newcommand{\coursecode}{EE 520}
\newcommand{\coursetitle}{Random Processes}
\newcommand{\quartername}{Fall 2026}
\newcommand{\assignmenttype}{Homework}
\newcommand{\assignmentnumber}{4}
\newcommand{\assignmenttitle}{Two random variables}
\newcommand{\duedate}{November 6, 2026}
\newcommand{\studentname}{}
\newcommand{\instructorname}{John Lipor}

% Derived metadata strings
\newcommand{\fullcoursename}{\coursecode: \coursetitle}
\newcommand{\assignmentname}{\assignmenttype\ \assignmentnumber}
\newcommand{\fullassignmentname}{\assignmentname\ifx\assignmenttitle\empty\else: \assignmenttitle\fi}

% -------------------------
% Packages
% -------------------------
\usepackage[english]{babel}
\usepackage[margin=1in]{geometry}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{microtype}
\usepackage{xcolor}
\usepackage{xparse}
\usepackage{etoolbox}
\usepackage{amsmath,amssymb,amsthm,amsfonts}
\usepackage{bbm}
\usepackage{graphicx}
\usepackage{algorithm}
\usepackage{algorithmic}
% \usepackage{enumitem}
\usepackage{titlesec}

% Links and PDF metadata
\usepackage[colorlinks=true,linkcolor=blue,urlcolor=blue,citecolor=blue]{hyperref}
\usepackage{bookmark}
\urlstyle{same}
\hypersetup{
  pdftitle={\coursecode\ \fullassignmentname},
  pdfauthor={\instructorname},
  pdfsubject={\fullcoursename\ assignment},
  pdfcreator={LaTeX},
  pdfproducer={LaTeX with hyperref},
  pdfdisplaydoctitle=true
}

% Improve math environment tagging
\usepackage{tagpdf}
\tagpdfsetup{activate-all,uncompress}

% Header command
\newcommand{\makehomeworkheader}{%
  \thispagestyle{plain}
  \begingroup
  \setlength{\fboxsep}{8pt}
  \noindent\fbox{%
    \begin{minipage}{\dimexpr\textwidth-2\fboxsep-2\fboxrule\relax}

      \noindent\textbf{\fullcoursename}\hfill \quartername\par

      \begin{center}
        {\LARGE \assignmentname\par}
        \ifx\assignmenttitle\empty\else
          {\large \assignmenttitle\par}
        \fi
        {\large Due: \duedate, 11:59 PM PT\par}
      \end{center}

      \noindent\textit{Student Name: \studentname}\hfill \textit{Instructor: \instructorname}\par
    \end{minipage}%
  }
  \endgroup
  \vspace{4mm}
}

% Section heading format used by \problem
\titleformat{\section}
  {\normalfont\normalsize\bfseries}
  {}
  {0pt}
  {}

% Problem headings
\newcounter{problem}
\NewDocumentCommand{\problem}{O{} O{}}{%
  \refstepcounter{problem}%
  \par\medskip
  \section*{\normalfont\normalsize\bfseries
    Problem \theproblem%
    \ifstrempty{#1}{}{\,: #1}%
    \ifstrempty{#2}{}{\normalfont\; [#2]}%
  }%
  \addcontentsline{toc}{section}{Problem \theproblem}%
}

% Use alpha labels for enumerate subproblems
\renewcommand{\labelenumi}{(\alph{enumi})}
\renewcommand{\theenumi}{\alph{enumi}}

% Solution command
\newcommand{\solution}{%
  \par\smallskip
  \noindent\textbf{Solution.}\enspace
}

% My math macros
% theorem type environments
\newtheorem{thm}{Theorem}
\newtheorem{prop}{Proposition}
\newtheorem{lemma}{Lemma}
\newtheorem{cor}{Corollary}
\newtheorem{defn}{Definition}
\newtheorem{assump}{Assumption}
\newtheorem{example}{Example}
\newtheorem{conjecture}{Conjecture}

% frequently used symbols
\newcommand{\bE}{\mathbb{E}}
\newcommand{\bP}{\mathbb{P}}
\newcommand{\bQ}{\mathbb{Q}}
\newcommand{\bR}{\mathbb{R}}
\newcommand{\bS}{\mathbb{S}}
\newcommand{\bN}{\mathbb{N}}
\newcommand{\bZ}{\mathbb{Z}}
\newcommand{\sC}{{\mathcal C}}
\newcommand{\sD}{{\mathcal D}}
\newcommand{\sE}{{\mathcal E}}
\newcommand{\sF}{{\mathcal F}}
\newcommand{\sL}{{\mathcal L}}
\newcommand{\sH}{{\mathcal H}}
\newcommand{\sN}{{\mathcal N}}
\newcommand{\sO}{{\mathcal O}}
\newcommand{\sP}{{\mathcal P}}
\newcommand{\sR}{{\mathcal R}}
\newcommand{\sS}{{\mathcal S}}
\newcommand{\sU}{{\mathcal U}}
\newcommand{\sX}{{\mathcal X}}
\newcommand{\sY}{{\mathcal Y}}
\newcommand{\sZ}{{\mathcal Z}}

% operators
\newcommand{\sign}{\mathop{\mathrm{sign}}}
\newcommand{\supp}{\mathop{\mathrm{supp}}}
\newcommand{\argmin}{\operatornamewithlimits{arg\,min}}
\newcommand{\argmax}{\operatornamewithlimits{arg\,max}}
\newcommand{\dist}{\operatorname{dist}}
\newcommand{\tr}{\operatorname{tr}}
\newcommand{\vecop}{\operatorname{vec}}
\newcommand{\st}{\operatorname{s.t.}}
\newcommand{\cut}{\setminus}
\newcommand{\ind}[1]{\mathbbm{1}\left\{#1\right\}}
\newcommand{\given}{\,|\,}

% grouping operators
\newcommand{\brac}[1]{\left[#1\right]}
\newcommand{\set}[1]{\left\{#1\right\}}
\newcommand{\abs}[1]{\left\lvert #1 \right\rvert}
\newcommand{\paren}[1]{\left(#1\right)}
\newcommand{\norm}[1]{\left\|#1\right\|}
\newcommand{\ip}[2]{\left\langle #1,#2 \right\rangle}

% code commands
\newcommand{\matlab}{\textsc{Matlab}}
\newcommand{\python}{\textsc{Python}}


\begin{document}

\makehomeworkheader

\section*{Instructions}
Submit your work as a PDF through the course submission system. If you need an accommodation or an alternate format, contact the instructor.

\noindent \textbf{Note:} For all questions asked in this course, unless the question is simply asking about definitions, please justify all answers. Stating the correct answer without justification will earn no credit. For example, if you write down a string of equations, each successive equation should be accompanied by some justification such as ``by the additivity axiom'' or ``because the outcomes are equally likely'' or ``by the distributive property of set operations.'' You do not need to justify algebra.

\problem[Two packets][5 pts each]

Two packets arrive at a router at times $(X, Y)$ distributed \emph{uniformly} over the triangle $0 \leq x \leq y \leq 1$ (packet~1 always arrives first).
\begin{enumerate}
  \item Find the joint PDF (careful with the normalizing constant), both marginals, and sketch the support.
  \item Find $f_{Y \given X}(y \given x)$ and $\bE[Y \given X = x]$. Interpret: given the first arrival time, what is the best prediction of the second?
  \item Are $X$ and $Y$ independent? Prove your answer two ways: via the support, and via the factorization test.
  \item Compute $\operatorname{Cov}(X, Y)$ and the correlation coefficient $\rho_{XY}$. One sentence: explain the sign using your answer to part~(b).
\end{enumerate}

\problem[Where is it, roughly?][5 pts each]

\emph{(Callback to Homework~2 Problem~3: the lying oracle, now with a continuous target and a continuous belief.)}

\noindent A target's position is $\theta \sim \text{Unif}[0, 1]$. You query a point $x \in (0, 1)$; the sensor returns $Z = \ind{\theta > x}$, but the bit is flipped with probability $p = 0.2$.
\begin{enumerate}
  \item You query $x = 0.5$ and observe $Z = 1$. Derive the posterior density of $\theta$ (it is piecewise constant; sketch it).
  \item Compute the posterior mean and the posterior median.
  \item For your second query, you will bisect the posterior \emph{mass}. Find the query point $x_2$ and explain in one sentence why mass-bisection, not interval-bisection, is the right generalization of binary search. \emph{(This is the continuous lying oracle, and the core update inside probabilistic binary search.)}
\end{enumerate}

\problem[Random number of targets][5 pts each]

A surveillance region contains $N \sim \text{Poisson}(\lambda)$ targets; each is independently detected with probability $q$.
\begin{enumerate}
  \item Let $D$ be the number detected. Using the tower property (condition on $N$), find $\bE[D]$ and $\operatorname{Var}(D)$.
  \item Find the PMF of $D$. (You will discover it is $\text{Poisson}(\lambda q)$, i.e.\ \emph{thinning}. One sentence on why this is remarkable.)
\end{enumerate}

\problem[Simulate the posterior][10 pts]

Implement the noisy-comparison localizer of Problem~2 on a $1000$-point grid: $\theta^\ast$ drawn uniformly, $20$ queries, each query placed at the posterior-mass median, with flip probability $p$. The posterior update is the rule you derived in Homework~2 Problem~3(c), with $0.8$ and $0.2$ replaced by $1 - p$ and $p$: after $k$ answers, grid point $\theta_j$ has posterior weight proportional to $(1-p)^{c_j}\,p^{\,k - c_j}$, where $c_j$ is the number of answers consistent with $\theta = \theta_j$.

\noindent\textbf{Before running:} predict how the posterior width after $20$ queries compares between $p = 0$ and $p = 0.2$ (a rough factor is fine).

\noindent\textbf{Turn in:} posterior plots after $1$, $5$, and $20$ queries for both values of $p$, your prediction versus the outcome, and your code.

\problem[Ranking by race][5 pts each]

\emph{(Builds on Session~9's Gumbel-max theorem, which tells you who comes first. This problem asks about everyone else.)}

\noindent Systems that learn from human feedback often show a labeler several responses to the same prompt and ask for a ranking from best to worst. A standard probability model for such rankings is the \emph{Plackett--Luce} model. Give response~$k$ a strength $w_k > 0$ and an independent clock $T_k \sim \text{Exp}(w_k)$ (rate $w_k$). The ranking lists the responses in the order in which their clocks ring, so the first clock to ring is ranked best. Write $W = \sum_k w_k$. For the numerical parts, there are four responses $A, B, C, D$ with strengths $(w_A, w_B, w_C, w_D) = (4, 2, 1, 1)$.

\begin{enumerate}
  \item \emph{Who comes first.} Show that clock~$k$ rings first with probability $w_k / W$. \emph{Hint:} the earliest of the other clocks is itself a single exponential clock (Session~6); then condition on $T_k$. What is the probability that $A$ is ranked first? One sentence: how does this match Session~9's softmax?
  \item \emph{Everyone else.} For a fixed $k$, $t \geq 0$, and $s_j \geq 0$ for every $j \neq k$, show that
  \[
    \bP\big(T_k \leq t \text{ and } T_j - T_k > s_j \text{ for all } j \neq k\big)
    = \frac{w_k}{W}\paren{1 - e^{-W t}} \prod_{j \neq k} e^{-w_j s_j} .
  \]
  Explain why this product form means that, once the first clock rings, the leftover times $T_j - T_k$ are independent $\text{Exp}(w_j)$ clocks, independent of which clock rang first and when. Conclude that the rest of the ranking is a fresh race among the remaining responses, and deduce that a ranking $\sigma_1, \sigma_2, \dots, \sigma_K$ (best first) has probability
  \[
    \prod_{i=1}^{K} \frac{w_{\sigma_i}}{w_{\sigma_i} + w_{\sigma_{i+1}} + \dots + w_{\sigma_K}} .
  \]
  Compute the probability of the ranking $A, B, C, D$, and the probability that the weakest-looking response $D$ lands in the top two.
  \item \emph{Ignoring the winner.} Show that
  \[
    \bP(B \text{ ranked above } C \given A \text{ ranked first}) = \bP(B \text{ ranked above } C) = \frac{w_B}{w_B + w_C} .
  \]
  Now add a fifth response $E$ that is a near-copy of $B$, with $w_E = w_B = 2$. Under the model, what is the probability that $A$ is ranked first now? In one or two sentences, explain why a real labeler might disagree, and what assumption of the model this exposes.
  \item \emph{Sampling rankings with Gumbels.} Let $\mu_k = \ln w_k$ and let $G_k$ be independent standard Gumbels. Using $G = -\ln E$ (Session~7), show that sorting the scores $\mu_k + G_k$ from largest to smallest produces a Plackett--Luce ranking. Keeping only the top $m$ of the sorted list therefore draws $m$ distinct items without replacement in one pass, with no renormalizing between draws; this is the \emph{Gumbel-top-$k$} trick, used to draw several distinct candidate responses from a language model at once.

  \textbf{Before running:} use part~(b) to predict how often, out of $10^5$ sampled rankings of $A, B, C, D$, you will see the ranking $A, B, C, D$, and how often $D$ lands in the top two.

  Implement the sampler using uniform draws only and draw $10^5$ rankings.

  \textbf{Turn in:} your predictions versus the observed frequencies, a plot of the observed frequency of each of the $24$ possible rankings against the Plackett--Luce formula, and your code.
\end{enumerate}

\problem[Reflection][5 pts]

Read \href{https://mathwithbaddrawings.com/2017/09/20/the-state-of-being-stuck/}{this article by Ben Orlin} on getting stuck on difficult problems. Share something that resonated with you, that you might try going forward, or that you disagree with, in the discussion thread on Canvas.

\problem[Audit the TA-bot][5 pts]

The assistant was asked: \emph{``$(X, Y)$ is uniform on the triangle with vertices $(0,0)$, $(1,0)$, $(0,1)$. Find the marginal density of $X$ and $\bE[Y \given X = x]$.''} It answered:

\begingroup
\setlength{\fboxsep}{8pt}
\noindent\fbox{%
  \begin{minipage}{\dimexpr\textwidth-2\fboxsep-2\fboxrule\relax}
    \noindent\textbf{TA-bot writes:} The triangle has area $1/2$, so $f_{XY}(x, y) = 2$ on the support. Marginalizing, $f_X(x) = \int_0^1 2\,dy = 2$ for $0 \leq x \leq 1$. Then $f_{Y \given X}(y \given x) = f_{XY}(x, y)/f_X(x) = 2/2 = 1$ on $[0, 1]$, so $Y \given X = x \sim \text{Unif}[0, 1]$ and $\bE[Y \given X = x] = 1/2$. In particular, $X$ and $Y$ are independent, each coordinate carrying no information about the other.
  \end{minipage}%
}
\endgroup

\medskip
\noindent This solution contains \textbf{zero, one, or two errors}; a single wrong step and everything it drags down counts as one error.
\begin{enumerate}
  \item Identify the first line that goes wrong, or certify the solution correct.
  \item Name the violated result or modeling rule in one sentence, citing the session. (Apply to each error you find.)
  \item Fix it: give the corrected marginal, conditional density, and conditional mean, and settle the independence claim with a zero-computation argument. (Apply to each error you find.)
  \item One sentence: why is this a mistake a language model plausibly makes?
\end{enumerate}

\end{document}
