LeVanLoi miscellaneous articles

  1. Trang chủ
  2. Lưu
  3. Thẻ
  4. Hỏi - Đáp

 
 
LeVanLoi'log, ⌚ 2024-11-15
***
What is log likelihood?
Tác giả: Lê Văn Lợi tổng hợp

English:

The log likelihood is a key concept in statistics and machine learning that quantifies how well a statistical model explains observed data. It is the natural logarithm of the likelihood function, which measures the probability of the observed data given the model parameters.


Key Concepts

  1. Likelihood Function:

    • Given a set of observed data x={x1,x2,,xn}mathbf{x} = {x_1, x_2, dots, x_n} and a model parameterized by θtheta, the likelihood function is: L(θ;x)=P(xθ),L(theta; mathbf{x}) = P(mathbf{x} | theta),where P(xθ)P(mathbf{x} | theta) represents the probability of the data xmathbf{x} under the model with parameters θtheta.
  2. Log Likelihood:

    • The log likelihood is the logarithm of the likelihood function: logL(θ;x)=logP(xθ).log L(theta; mathbf{x}) = log P(mathbf{x} | theta).
    • For independent and identically distributed (i.i.d.) data, the likelihood function for nn samples can be written as: L(θ;x)=i=1nP(xiθ).L(theta; mathbf{x}) = prod_{i=1}^n P(x_i | theta).Taking the logarithm transforms the product into a sum: logL(θ;x)=i=1nlogP(xiθ).log L(theta; mathbf{x}) = sum_{i=1}^n log P(x_i | theta).
  3. Why Use the Log Likelihood?

    • Numerical Stability: Products of probabilities can become extremely small, leading to underflow. Taking the logarithm mitigates this issue by transforming products into sums.
    • Simplified Calculations: The log likelihood simplifies optimization problems because it is easier to differentiate sums than products.
    • Interpretability: Logarithms are monotonic, meaning the log likelihood and the likelihood function achieve their maximum at the same parameter values.

Applications

  1. Maximum Likelihood Estimation (MLE):

    • In MLE, the goal is to find the parameters θtheta that maximize the likelihood of the observed data. Since maximizing the likelihood L(θ;x)L(theta; mathbf{x}) is equivalent to maximizing the log likelihood logL(θ;x)log L(theta; mathbf{x}), the optimization problem becomes: θ^=argmaxθlogL(θ;x).hat{theta} = arg max_theta log L(theta; mathbf{x}).
  2. Model Comparison:

    • The log likelihood can be used to compare different models. A higher log likelihood indicates that a model better explains the observed data.
  3. Bayesian Inference:

    • In Bayesian methods, the log likelihood is combined with the prior distribution to compute the posterior distribution: logP(θx)logL(θ;x)+logP(θ),log P(theta | mathbf{x}) propto log L(theta; mathbf{x}) + log P(theta), where P(θ)P(theta) is the prior.

Example

Suppose we observe n=3n = 3 data points x={2,3,4}mathbf{x} = {2, 3, 4}, and we assume they come from a Poisson distribution with parameter λlambda. The likelihood function is:

L(λ;x)=P(2λ)P(3λ)P(4λ).L(lambda; mathbf{x}) = P(2 | lambda) cdot P(3 | lambda) cdot P(4 | lambda).

For a Poisson distribution, P(xλ)=λxeλx!P(x | lambda) = frac{lambda^x e^{-lambda}}{x!}. Thus:

L(λ;x)=λ2eλ2!λ3eλ3!λ4eλ4!.L(lambda; mathbf{x}) = frac{lambda^2 e^{-lambda}}{2!} cdot frac{lambda^3 e^{-lambda}}{3!} cdot frac{lambda^4 e^{-lambda}}{4!}.

Taking the logarithm:

logL(λ;x)=i=13(xilogλλlog(xi!)).log L(lambda; mathbf{x}) = sum_{i=1}^3 left(x_i log lambda - lambda - log(x_i!) right).

Maximizing this log likelihood with respect to λlambda gives the maximum likelihood estimate (MLE) for λlambda.


Key Intuition

The log likelihood provides a measure of how plausible the observed data is under a given model. By maximizing the log likelihood, we find the parameters that make the data most probable, thus "fitting" the model to the data.

--- 

Vietnamese:

Log likelihood (logarit của hàm khả năng) là một khái niệm quan trọng trong thống kê và học máy, dùng để định lượng mức độ phù hợp của một mô hình thống kê với dữ liệu quan sát. Đây là logarit tự nhiên của hàm khả năng, đo lường xác suất của dữ liệu quan sát được với các tham số của mô hình.


Các khái niệm chính

  1. Hàm khả năng (Likelihood Function):

    • Với một tập dữ liệu quan sát x={x1,x2,,xn}mathbf{x} = {x_1, x_2, dots, x_n} và một mô hình tham số hóa bởi θtheta, hàm khả năng được định nghĩa là: L(θ;x)=P(xθ),L(theta; mathbf{x}) = P(mathbf{x} | theta), trong đó P(xθ)P(mathbf{x} | theta) là xác suất của dữ liệu xmathbf{x} theo mô hình với tham số θtheta.
  2. Log Likelihood:

    • Log likelihood là logarit của hàm khả năng: logL(θ;x)=logP(xθ).log L(theta; mathbf{x}) = log P(mathbf{x} | theta).
    • Nếu dữ liệu được giả định là độc lập và phân phối giống nhau (i.i.d.), hàm khả năng cho nn mẫu có thể viết là: L(θ;x)=i=1nP(xiθ).L(theta; mathbf{x}) = prod_{i=1}^n P(x_i | theta). Lấy logarit sẽ chuyển tích thành tổng: logL(θ;x)=i=1nlogP(xiθ).log L(theta; mathbf{x}) = sum_{i=1}^n log P(x_i | theta).
  3. Tại sao sử dụng Log Likelihood?

    • Ổn định số học (Numerical Stability): Tích của các xác suất có thể trở nên rất nhỏ, dẫn đến vấn đề underflow. Việc lấy logarit giúp giảm thiểu vấn đề này bằng cách chuyển tích thành tổng.
    • Đơn giản hóa tính toán (Simplified Calculations): Log likelihood làm cho các bài toán tối ưu hóa dễ dàng hơn, vì tính tổng đơn giản hơn tính tích trong đạo hàm.
    • Dễ diễn giải (Interpretability): Vì logarit là đơn điệu, log likelihood và likelihood đạt cực đại tại cùng một giá trị tham số.

Ứng dụng

  1. Ước lượng hợp lý cực đại (Maximum Likelihood Estimation - MLE):

    • Trong MLE, mục tiêu là tìm tham số θtheta tối đa hóa khả năng của dữ liệu quan sát. Vì tối đa hóa L(θ;x)L(theta; mathbf{x}) tương đương với tối đa hóa logL(θ;x)log L(theta; mathbf{x}), bài toán tối ưu trở thành: θ^=argmaxθlogL(θ;x).hat{theta} = arg max_theta log L(theta; mathbf{x}).
  2. So sánh mô hình:

    • Log likelihood được sử dụng để so sánh các mô hình khác nhau. Một log likelihood cao hơn chỉ ra rằng mô hình giải thích dữ liệu tốt hơn.
  3. Suy diễn Bayes:

    • Trong phương pháp Bayes, log likelihood được kết hợp với phân phối tiên nghiệm để tính phân phối hậu nghiệm: logP(θx)logL(θ;x)+logP(θ),log P(theta | mathbf{x}) propto log L(theta; mathbf{x}) + log P(theta), trong đó P(θ)P(theta) là phân phối tiên nghiệm.

Ví dụ

Giả sử chúng ta quan sát n=3n = 3 dữ liệu x={2,3,4}mathbf{x} = {2, 3, 4}, và giả định chúng được sinh ra từ một phân phối Poisson với tham số λlambda. Hàm khả năng là:

L(λ;x)=P(2λ)P(3λ)P(4λ).L(lambda; mathbf{x}) = P(2 | lambda) cdot P(3 | lambda) cdot P(4 | lambda).

Với phân phối Poisson, P(xλ)=λxeλx!P(x | lambda) = frac{lambda^x e^{-lambda}}{x!}. Do đó:

L(λ;x)=λ2eλ2!λ3eλ3!λ4eλ4!.L(lambda; mathbf{x}) = frac{lambda^2 e^{-lambda}}{2!} cdot frac{lambda^3 e^{-lambda}}{3!} cdot frac{lambda^4 e^{-lambda}}{4!}.

Lấy logarit:

logL(λ;x)=i=13(xilogλλlog(xi!)).log L(lambda; mathbf{x}) = sum_{i=1}^3 left(x_i log lambda - lambda - log(x_i!) right).

Tối đa hóa log likelihood theo λlambda sẽ cho ước lượng hợp lý cực đại (MLE) của λlambda.


Trực giác chính

Log likelihood cung cấp một thước đo về mức độ "khả dĩ" của dữ liệu quan sát được dưới một mô hình cho trước. Bằng cách tối đa hóa log likelihood, chúng ta tìm ra các tham số giúp mô hình phù hợp nhất với dữ liệu.