MLE for Multivariate Gaussian Parameters
Xem dạng PDF
Gửi bài giải
Điểm:
100,00
Giới hạn thời gian:
2.0s
Giới hạn bộ nhớ:
256M
Tác giả:
Dạng bài
Ngôn ngữ cho phép
Python
Problem Statement
Given n observations of a d-dimensional multivariate Gaussian, compute the Maximum Likelihood Estimates (MLE) for the mean vector and covariance matrix.
Formulas (biased MLE, divide by n):
μ_MLE = (1/n) Σ x_i
Σ_MLE = (1/n) Σ (x_i - μ)(x_i - μ)ᵀ = (X_c)ᵀ X_c / n
where X_c = X - μ is the mean-centered data matrix.
Function signature:
def mle_mvg(X: np.ndarray) -> tuple:
# returns (mean, cov)
# mean: shape (d,), cov: shape (d, d)
Input Format
Line 1: n d — number of observations and dimensions
Lines 2..n+1: d space-separated floats per row
Output Format
Line 1: d space-separated mean values (8 decimal places)
Lines 2..d+1: d × d covariance matrix rows (8 decimal places each)
Example
Input:
4 2
1.0 2.0
3.0 4.0
5.0 6.0
7.0 8.0
Output:
4.00000000 5.00000000
5.00000000 5.00000000
5.00000000 5.00000000
Derivation
The MLE for the multivariate Gaussian is obtained by maximizing the log-likelihood:
log L(μ, Σ) = -n/2 log|Σ| - 1/2 Σ_i (x_i - μ)ᵀ Σ⁻¹ (x_i - μ) + const
Setting the derivative w.r.t. μ to zero gives μ_MLE = sample mean. Substituting back and differentiating w.r.t. Σ gives the biased covariance (divide by n).
Notes
- The MLE covariance is biased (divides by
n). The unbiased sample covariance divides byn-1. - Use
X_c.T @ X_c / nrather thannumpy.cov(which usesddof=1by default). - The result is always symmetric positive semi-definite.
Bình luận