KatInterview

Maximum Likelihood Estimation for Uniform Distribution Bounds

Arrays & HashingAuto-graded · 18 test cases
HardAuto-gradedArrays & Hashingstatisticsestimationprobability

Last updated

Tests understanding of MLE derivation for bounded distributions and bias correction in parameter estimation.

You are given a sample of observations drawn independently from a continuous uniform distribution over the interval [0, θ], where θ is an unknown positive parameter that you need to estimate.

Your task is to compute two estimators for θ:

  1. Maximum Likelihood Estimator (MLE): Find the value of θ that maximizes the likelihood of observing the given sample.

  2. Unbiased Estimator: Construct an estimator that corrects for the systematic bias present in the MLE.

Given a list of sample observations, return both estimates as a list of two floats: [mle_estimate, unbiased_estimate].

Background: For a uniform distribution U(0, θ), the likelihood function is positive only when θ is at least as large as the maximum observed value. Among all such valid values, smaller θ values yield higher likelihood. The MLE is therefore the smallest θ that makes all observations possible.

However, the MLE systematically underestimates the true θ because the sample maximum can never exceed θ. The expected value of the sample maximum from U(0, θ) with n observations is nθ/(n+1), which is less than θ. An unbiased estimator can be constructed by scaling the MLE appropriately.

Constraints

  • 1 ≤ len(sample) ≤ 10^5
  • All sample values are non-negative floats
  • 0 ≤ sample[i] ≤ 10^6
  • The sample is drawn from U(0, θ) for some unknown θ > 0 (or θ = 0 in degenerate cases)
  • Return estimates rounded or exact to reasonable floating-point precision

Examples

Example 1

Input: estimate_uniform_parameter([0.2, 0.5, 0.8, 0.3])

Output: [0.8, 1]

Example 2

Input: estimate_uniform_parameter([1, 2.5, 1.7, 0.4, 2])

Output: [2.5, 3]

Example 3

Input: estimate_uniform_parameter([0, 0, 0])

Output: [0, 0]

Hints

Hint 1

The likelihood function for U(0, θ) is zero when θ is smaller than any observed value, and decreases as θ increases beyond that point

Hint 2

The MLE for θ must be the minimum value that keeps the likelihood positive, which relates directly to the sample's extreme values

Hint 3

To correct bias, consider that E[max(X₁,...,Xₙ)] = nθ/(n+1) for uniform samples, so scale the MLE by (n+1)/n