Point light source on a line: sample hits, check the density, recover the source by MLE

Read the full interview experience this question came from →

Quick Overview

A point light source above a line emits photons in random directions. You simulate where photons land, compare the samples with the theoretical density, and recover the source position from landing points, finally by maximizing the log-likelihood. It tests probabilistic modeling, handling of heavy-tailed data and numerical optimization.

Point light source on a line: sample hits, check the density, recover the source by MLE

Company: OpenAI

Role: Machine Learning Engineer

Category: Machine Learning

Difficulty: hard

Interview Round: Technical Screen

A point light source sits at an unknown position $(p_x, p_y)$ above a one-dimensional screen: the horizontal line $y = 0$ in the plane, with $p_y > 0$. The source emits photons, and every photon that travels toward the line lands on it at some coordinate $x$. The task comes from an ML coding round that the interviewer framed as ML coding with math reasoning; it needs little physics and builds up in steps: simulate landing points, check the simulation against the theoretical density, and then work backwards from observed landing points to the source position. The report says the last two steps both recover the source position and that the final one calls for maximizing the log-likelihood, so Part 3 below asks for a first, simpler estimate and Part 4 for the likelihood-based one. Assume the following unless the interviewer says otherwise: - Photons are independent, and each leaves the source in a uniformly random direction. Only photons heading toward the line are observed, so for an observed photon the angle $\theta$ between its path and the straight-down direction is uniform on $(-\frac{\pi}{2}, \frac{\pi}{2})$. - The line is infinitely long, and landing positions are recorded exactly. - NumPy is available; SciPy's optimizers may be used if the interviewer allows them. ### Clarifying Questions - Is the emission direction uniform over all angles, or does the source have a beam pattern? - Should photons that head away from the line simply never be reported, or should the sampler also say how many were lost? - Is the screen infinitely long, or a detector that only records landings inside a finite window? - Is there a target sample size, and must the code be vectorized for millions of photons? ### Part 1 — Sample landing points Write `sample_hits(px, py, n, seed=None)`, which returns the landing coordinates of `n` photons from a source at $(p_x, p_y)$. ```hint From angle to landing point Draw the triangle formed by the source, the point on the line directly below it, and the landing point, and express the horizontal offset using the angle and the height. ``` #### What This Part Should Cover - The geometry that turns a random direction into a landing coordinate - Handling of photons that never reach the line, and of near-horizontal directions - A vectorized, seeded implementation with a quick sanity check against known parameters ### Part 2 — Compare with the theoretical density You are given the theoretical density of landing positions, $f(x) = \frac{p_y}{\pi\,(p_y^2 + (x - p_x)^2)}$. Show whether the curve produced by your sampler matches it. ```hint Look at the extremes first Before choosing histogram bins, look at the largest and smallest values your sampler produces, and decide how to treat them so the comparison is fair. ``` #### Clarifying Questions for this Part - Is a visual overlay enough, or is a numeric measure of agreement expected? #### What This Part Should Cover - An empirical density normalized so that it is directly comparable with $f$, or a comparison of distribution functions - The heavy tails: choice of plotting range and bins, and the normalization error they can cause - A quantitative goodness-of-fit check and how it should behave as the sample size grows ### Part 3 — Estimate the source position Now you see only the landing coordinates $x_1, \dots, x_n$ of photons from a source at an unknown position. Estimate $p_x$ and $p_y$, and explain why your estimates approach the true values as $n$ grows. ```hint Test before trusting Run your Part 1 sampler with a known source, apply your estimator for growing n, and watch whether the estimates settle down. ``` #### What This Part Should Cover - How the shape of the landing distribution affects simple moment-based estimates - Consistent estimators for both coordinates, with the reasoning behind them - Empirical validation on simulated data with a known source ### Part 4 — Recover the source by maximum likelihood Estimate $(p_x, p_y)$ by maximizing the log-likelihood of the observed landing points under the density from Part 2. Implement the optimization and report the estimate. ```hint Make the optimizer's job easy Write the log-likelihood as a sum over points, work out its gradient, and decide how to keep the height positive and where to start the search. ``` #### What This Part Should Cover - The log-likelihood and its gradient with respect to both parameters - A working optimizer with a positivity constraint on the height and a sensible starting point - Checking the estimate on simulated data, its uncertainty, and inputs for which the maximum misbehaves ### What a Strong Answer Covers - Translating the physical setup into a probability model with stated assumptions - Sampling and density code that is vectorized, seeded and checked against known parameters - Recognizing the heavy tails of the landing distribution and their consequences for plotting and estimation - A correct likelihood-based estimator, compared with the simpler estimator from Part 3 on accuracy and robustness - Sanity checks: parameter recovery on simulated data, behavior as n grows, and degenerate inputs ### Follow-up Questions - If the source hangs above a two-dimensional floor instead of a line, how do the sampler and the landing density change? - The detector records only photons that land inside a finite window $[a, b]$. How must the likelihood change, and what goes wrong if you ignore the window? - How many photons do you need to locate $p_x$ to a given tolerance, and how does that number depend on $p_y$? - Each landing position is measured with Gaussian noise. How would you adapt the estimation?

Overview: A point light source above a line emits photons in random directions. You simulate where photons land, compare the samples with the theoretical density, and recover the source position from landing points, finally by maximizing the log-likelihood. It tests probabilistic modeling, handling of heavy-tailed data and numerical optimization.

Read the full OpenAI Machine Learning Engineer interview experience this question came from

OpenAI logo
OpenAI
Oct 29, 2026
hardMachine Learning EngineerTechnical ScreenMachine Learning
1
0

A point light source sits at an unknown position (px,py)(p_x, p_y) above a one-dimensional screen: the horizontal line y=0y = 0 in the plane, with py>0p_y > 0. The source emits photons, and every photon that travels toward the line lands on it at some coordinate xx. The task comes from an ML coding round that the interviewer framed as ML coding with math reasoning; it needs little physics and builds up in steps: simulate landing points, check the simulation against the theoretical density, and then work backwards from observed landing points to the source position. The report says the last two steps both recover the source position and that the final one calls for maximizing the log-likelihood, so Part 3 below asks for a first, simpler estimate and Part 4 for the likelihood-based one.

Assume the following unless the interviewer says otherwise:

  • Photons are independent, and each leaves the source in a uniformly random direction. Only photons heading toward the line are observed, so for an observed photon the angle θ\theta between its path and the straight-down direction is uniform on (−π2,π2)(-\frac{\pi}{2}, \frac{\pi}{2}) .
  • The line is infinitely long, and landing positions are recorded exactly.
  • NumPy is available; SciPy's optimizers may be used if the interviewer allows them.

Clarifying Questions Guidance

  • Is the emission direction uniform over all angles, or does the source have a beam pattern?
  • Should photons that head away from the line simply never be reported, or should the sampler also say how many were lost?
  • Is the screen infinitely long, or a detector that only records landings inside a finite window?
  • Is there a target sample size, and must the code be vectorized for millions of photons?

Part 1 — Sample landing points

Write sample_hits(px, py, n, seed=None), which returns the landing coordinates of n photons from a source at (px,py)(p_x, p_y).

What This Part Should Cover Guidance

  • The geometry that turns a random direction into a landing coordinate
  • Handling of photons that never reach the line, and of near-horizontal directions
  • A vectorized, seeded implementation with a quick sanity check against known parameters

Part 2 — Compare with the theoretical density

You are given the theoretical density of landing positions, f(x)=pyπ (py2+(x−px)2)f(x) = \frac{p_y}{\pi\,(p_y^2 + (x - p_x)^2)}. Show whether the curve produced by your sampler matches it.

Clarifying Questions for this Part Guidance

  • Is a visual overlay enough, or is a numeric measure of agreement expected?

What This Part Should Cover Guidance

  • An empirical density normalized so that it is directly comparable with ff , or a comparison of distribution functions
  • The heavy tails: choice of plotting range and bins, and the normalization error they can cause
  • A quantitative goodness-of-fit check and how it should behave as the sample size grows

Part 3 — Estimate the source position

Now you see only the landing coordinates x1,…,xnx_1, \dots, x_n of photons from a source at an unknown position. Estimate pxp_x and pyp_y, and explain why your estimates approach the true values as nn grows.

What This Part Should Cover Guidance

  • How the shape of the landing distribution affects simple moment-based estimates
  • Consistent estimators for both coordinates, with the reasoning behind them
  • Empirical validation on simulated data with a known source

Part 4 — Recover the source by maximum likelihood

Estimate (px,py)(p_x, p_y) by maximizing the log-likelihood of the observed landing points under the density from Part 2. Implement the optimization and report the estimate.

What This Part Should Cover Guidance

  • The log-likelihood and its gradient with respect to both parameters
  • A working optimizer with a positivity constraint on the height and a sensible starting point
  • Checking the estimate on simulated data, its uncertainty, and inputs for which the maximum misbehaves

What a Strong Answer Covers Guidance

  • Translating the physical setup into a probability model with stated assumptions
  • Sampling and density code that is vectorized, seeded and checked against known parameters
  • Recognizing the heavy tails of the landing distribution and their consequences for plotting and estimation
  • A correct likelihood-based estimator, compared with the simpler estimator from Part 3 on accuracy and robustness
  • Sanity checks: parameter recovery on simulated data, behavior as n grows, and degenerate inputs

Follow-up Questions Guidance

  • If the source hangs above a two-dimensional floor instead of a line, how do the sampler and the landing density change?
  • The detector records only photons that land inside a finite window [a,b][a, b] . How must the likelihood change, and what goes wrong if you ignore the window?
  • How many photons do you need to locate pxp_x to a given tolerance, and how does that number depend on pyp_y ?
  • Each landing position is measured with Gaussian noise. How would you adapt the estimation?