Skip to content
Glacius
StatisticsConcept reference

Log-likelihood

For positive independent-sample factors, log likelihood is the sum of their natural logarithms.

On this page 9 sections
  1. Overview
  2. Understand the idea
  3. For L=ab, use log L=log a+log b
  4. An iid Bernoulli sample (1,0,1) has L(p)=p^2(1-p)
  5. Model training often adds a negative log-likelihood over examples
  6. Key takeaway
  7. Further questions
  8. Sources & further reading
  9. Concept connections
Log likelihood converts a product to a sum while retaining repeated factors. The product ab² corresponds to log a plus two copies of log b. Blocks show factors, not magnitudes.Log likelihood converts a product to a sum while retaining repeated factors. The product ab² corresponds to log a plus two copies of log b. Blocks show factors, not magnitudes.
Figure 1Log likelihood converts a product to a sum while retaining repeated factors. The product ab² corresponds to log a plus two copies of log b. Blocks show factors, not magnitudes.
Link to this figure ↗Download SVGDownload PNG

01Understand the idea#

Multiplying many small likelihood factors can make a number too small for a computer to represent accurately. Taking logarithms turns the product into a sum. Because the logarithm increases with its input, maximizing a positive likelihood and maximizing its log give the same candidate.

For positive factors, L=ab2L=ab^2 has one aa factor and two bb factors. Its log is loga+2logb\log a+2\log b: every factor is retained.

log(ab2)=loga+2logb\begin{aligned}\log(ab^2)&=\log a\\&\quad+2\log b\end{aligned}

Natural log turns an independent-sample product into a sum. Each factor must be positive for its log to be finite.

L(θ)=ipθ(xi)(θ)=ilogpθ(xi)\begin{gathered}L(\theta)=\prod_i p_\theta(x_i)\\\ell(\theta)=\sum_i\log p_\theta(x_i)\end{gathered}

For likelihood factors (1/2,1/4,1/2)(1/2,1/4,1/2), their product is 1/161/16. In base 2 the log-likelihood is 121=4-1-2-1=-4, which is also log2(1/16)\log_2(1/16). A negative log-likelihood changes the sign so that minimizing it corresponds to maximizing the original likelihood.

Check your reasoning

Positive factors a,b,ca,b,c. L=a3bL=a^3b. Give =logL\ell=\log L.

  1. A2loga+logb2\log a+\log b
  2. B3loga+logb3\log a+\log b
  3. C4loga+logb4\log a+\log b
Show answer and explanation
3loga+logb3\log a+\log b

Log-term counts (a,b,c)=(3,1,0)(a,b,c)=(3,1,0).

02For L=ab, use log L=log a+log b#

For L=abL=ab, use logL=loga+logb\log L=\log a+\log b. Multiplying the logs applies the wrong rule. If a factor appears three times, its log appears three times too.

Check your reasoning

Positive factors a,b,ca,b,c. L=a2cL=a^2c. Reported =2logalogc\ell=2\log a\log c. Repair.

  1. A2loga+logc2\log a+\log c
  2. B2logalogc2\log a\log c
  3. C2loga+2logc2\log a+2\log c
Show answer and explanation
2loga+logc2\log a+\log c

Log-term counts (a,b,c)=(2,0,1)(a,b,c)=(2,0,1).

03An iid Bernoulli sample (1,0,1) has L(p)=p^2(1-p)#

An iid Bernoulli sample (1,0,1)(1,0,1) has L(p)=p2(1p)L(p)=p^2(1-p). For 0<p<10<p<1, its log is 2logp+log(1p)2\log p+\log(1-p). Natural log is increasing, so it preserves which positive likelihood is largest.

Check your reasoning

Ordered iid Bernoulli sample (0,1,0,0)(0,1,0,0), P(1)=pP(1)=p, 0<p<10<p<1. Give (p)\ell(p).

  1. A3logp+log(1p)3\log p+\log(1-p)
  2. Blogp+2log(1p)\log p+2\log(1-p)
  3. Clogp+3log(1p)\log p+3\log(1-p)
Show answer and explanation
logp+3log(1p)\log p+3\log(1-p)

1 one, 3 zeros: use those log-term counts.

04Model training often adds a negative log-likelihood over examples#

Model training often adds a negative log-likelihood over examples. Keep the log base and sign clear when comparing reported losses. Logging a sum of probabilities is not a replacement for summing the logs of the independent likelihood factors.

Key takeaway

Take one log term per positive factor. Keep multiplicities and every parameter-dependent term.

  • Express an independent-sample likelihood as a sum of log terms.

Further questions

Does a log likelihood supply a prior over parameters?
No. It rewrites the likelihood of fixed data. A prior is additional information used in a posterior update.

Sources & further reading

  1. [1]

Reference this concept

Link to this page, a section, or an individual figure.

Glacius. “Log-likelihood.” Math behind ML. /learn/s-log-likelihood