Gaussian Log-Likelihood
~20 mincode completion
Implement gaussian_log_likelihood(x, mu, sigma) that returns the total (summed) log-likelihood over all observations in x.
Examples
Single point at the mean: maximum log-likelihood for sigma=1
- Input
- gaussian_log_likelihood([0], 0, 1)
- Output
- -0.91894
Two points equidistant from mean
- Input
- gaussian_log_likelihood([-1, 1], 0, 1)
- Output
- -2.83788
Larger sigma reduces log-likelihood at mean
- Input
- gaussian_log_likelihood([0], 0, 2)
- Output
- -1.61209
Hints
Hint 1
is the natural log, which is what this formula wants.
Hint 2
Do not forget to log sigma term. That step is easy to skip.
Requirements
x: Observations, 1D arraymu: Mean of the Gaussiansigma: Standard deviation of the Gaussian (> 0)Return Total log-likelihood (sum over all observations).
Constraints
Allowed library: NumPy only
Time limit: 200 ms, Memory: 64 MB
Where this shows up
~20 min
••••••••••••••••
8 employers weight this skill
4 quant funds, 2 health and bio companies, 1 enterprise vendor, 1 big tech firm. Top match scores 63.
Python
import numpy as np
def gaussian_log_likelihood(x: np.ndarray, mu: float, sigma: float) -> float:
"""
Compute the total log-likelihood of data under a Gaussian distribution.
Args:
x: Observations, 1D array
mu: Mean of the Gaussian
sigma: Standard deviation of the Gaussian (> 0)
Returns:
Total log-likelihood (sum over all observations).
"""
# YOUR CODE HERE
pass