Random Variables · Likelihood and Parameter Fitting

Lesson 7

Nikolai Chukhin · Alexander S. Kulikov

Programming problem. Suppose \(y_{1},\dotsc,y_{n}\) are independent observations from the exponential distribution with parameter \(\lambda>0\): \[p(y \mid \lambda)=\lambda e^{-\lambda y}, \qquad y\ge 0.\] This distribution is often used for waiting times: time until the next request, time until a component fails, time until a random event happens.

To solve the problem, write the likelihood of the observations, pass to the log-likelihood, and find which value of \(\lambda\) maximizes it. In the input, all observations are positive integers. Output the maximum likelihood estimate as a decimal number.

The first line of the input contains an integer \(n\). The second line contains \(n\) positive integers \(y_{1},\dotsc,y_{n}\). You may assume that \(1 \le n \le 10^{5}\) and \(1 \le y_{i} \le 10^{9}\).

Output one real number: the value of \(\widehat{\lambda}_{\mathrm{MLE}}\). Your answer will be accepted if its absolute error is at most \(10^{-12}\) or its relative error is at most \(10^{-6}\).

5 points
Public samples
Public sample 1
Input
1
1
Expected output
1