<jupyter_start><jupyter_text>(a) Let the random variable $x$ be the lifetime of a light bulb in days. We assume that the lifetime is exponential with density:$$p(x) = \lambda^{-1} e^{-x/\lambda}$$Then given $\lambda$ (the mean time to failure):$$ P (x \ge 30) = 1 - cdf(p(x)) = e^{-x/\lambda}$$ (b) Let $x_1,...,x_n \sim Exp(\lambda)$. The contribution of $x_i$ to the likelihood is:$$L_i(\lambda) = \lambda^{-1} e^{-x/\lambda}$$and the total log-likelihood is:\begin{align}\log L(\lambda) & = \sum_{i=1}^n \log L_i(\lambda) \\& = -n \log \lambda - \frac{1}{\lambda} \sum_{i=1}^n x_i \\& = -n (\log \lambda + \bar{x}/\lambda)\end{align}<jupyter_code>data = np.array([6, 28]) # only the first two order statistics are reported
n = data.shape[0]
x_bar = np.mean(data)
lambda_ = np.linspace(1, 30, 100)
log_like = -n * (np.log(lambda_) + x_bar / lambda_)
likelihood = np.exp(log_like)
likelihood /= np.max(likelihood)
plt.plot(lambda_, likelihood)
plt.title('Light bulb failure likelihood')
plt.xlabel(r'$\lambda$')
plt.ylabel('Likelihood');<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.20318352059925093, 'fraction_numerical': 0.017790262172284643, 'mean_word_length': 4.454081632653061, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '196634', 'license': 'MIT', 'n_tokens_mistral': 417, 'n_tokens_neox': 394, 'n_words': 108, 'path': 'python/chapter-2/exercises/EX2-11.ipynb', 'repo_name': 'covuworie/in-all-likelihood', 'size': '1068'}