Divergência de Kullback-Leibler entre duas distribuições gama


15

Optando por parametrizar a distribuição gama Γ(b,c) pelo pdf g(x;b,c)=1Γ(c)xc1bcex/b A divergência de Kullback-Leibler entreΓ(bq,cq)eΓ(bp,cp)é dada por [1] como

KLGa(bq,cq;bp,cp)=(cq1)Ψ(cq)logbqcqlogΓ(cq)+logΓ(cp)+cplogbp(cp1)(Ψ(cq)+logbq)+bqcqbp

Estou supondo que Ψ(x):=Γ(x)/Γ(x) é a função digamma .

Isso é dado sem derivação. Não consigo encontrar nenhuma referência que derive isso. Qualquer ajuda? Uma boa referência seria suficiente. A parte difícil é integrar o em um pdf gama.logx

[1] WD Penny, KL-Divergences of Densities Normal, Gamma, Dirichlet e Wishart , disponível em: www.fil.ion.ucl.ac.uk/~wpenny/publications/densities.ps


2
Tomar a derivada do pdf em relação a introduz o fator de l o g ( x ) que você está procurando: é por isso que o digamma aparece. clog(x)
whuber

Se você se deparar com Pierre Baldi e Laurent Itti (2010) “De bits e surpresa: uma teoria bayesiana da surpresa com aplicações em atenção” Neural Networks 23: 649-666, você encontrará a Equação 73 que fornece uma divergência de KL entre dois PDFs gama. Tome cuidado, porém, parece que a fórmula foi impressa incorretamente.
Clarinet

Estou à procura de uma solução para o mesmo problema e encontrar este um é útil.
Yi Yang

Respostas:


15

A divergência KL é uma diferença de integrais da forma

$$ \ eqalign {I (a, b, c, d) & = \ int_0 ^ {\ infty} \ log \ left (\ frac {e ^ {- x / a} x ^ {b-1}} {a ^ b \ Gamma (b)} \ right) \ frac {e ^ {- x / c} x ^ {d-1}} {c ^ d \ Gamma (d)} dx \

& = - \ frac {1} {a} \ int_0 ^ \ infty \ frac {x ^ de ^ {- x / c}} {c ^ d \ Gamma (d)} \, dx - \ log (a ^ b \ Gamma (b)) \ ​​int_0 ^ \ infty \ frac {e ^ {- x / c} x ^ {d-1}} {c ^ d \ Gamma (d)} \, dx \ & \ quad + (b- 1) \ int_0 ^ \ infty \ log (x) \ frac {e ^ {- x / c} x ^ {d-1}} {c ^ d \ Gamma (d)} \, dx \

&=-\frac{cd}{a} - \log(a^b\Gamma(b)) + (b-1)\int_0^\infty \log(x) \frac{e^{-x/c}x^{d-1}}{c^d\Gamma(d)}\,dx }$$

We just have to deal with the right hand integral, which is obtained by observing

dΓ(d)=d0ex/cxd1cddx=d0ex/c(x/c)d1cdx=0ex/cxd1cdlogxcdx=0log(x)ex/cxd1cddxlog(c)Γ(d).

Whence

b1Γ(d)0log(x)ex/c(x/c)d1dx=(b1)Γ(d)Γ(d)+(b1)log(c).

Plugging into the preceding yields

I(a,b,c,d)=cdalog(abΓ(b))+(b1)Γ(d)Γ(d)+(b1)log(c).

The KL divergence between Γ(c,d) and Γ(a,b) equals I(c,d,c,d)I(a,b,c,d), which is straightforward to assemble.


Implementation Details

Gamma functions grow rapidly, so to avoid overflow don't compute Gamma and take its logarithm: instead use the log-Gamma function that will be found in any statistical computing platform (including Excel, for that matter).

The ratio Γ(d)/Γ(d) is the logarithmic derivative of Γ, generally called ψ, the digamma function. If it's not available to you, there are relatively simple ways to approximate it, as described in the Wikipedia article.

Here, to illustrate, is a direct R implementation of the formula in terms of I. This does not exploit an opportunity to simplify the result algebraically, which would make it a little more efficient (by eliminating a redundant calculation of ψ).

#
# `b` and `d` are Gamma shape parameters and
# `a` and `c` are scale parameters.
# (All, therefore, must be positive.)
#
KL.gamma <- function(a,b,c,d) {
  i <- function(a,b,c,d)
    - c * d / a - b * log(a) - lgamma(b) + (b-1)*(psigamma(d) + log(c))
  i(c,d,c,d) - i(a,b,c,d)
}
print(KL.gamma(1/114186.3, 202, 1/119237.3, 195), digits=12)

2
Good answer. Thanks! I believe that there is a sign error however in the fourth equality. Also, your gamma pdf should have an extra factor of 'c' in the denominator. Would you like me to edit it?
Ian Langmore

@Ian You're right; I usually write the measure as dx/x and by not doing that I omitted that extra factor of c. Good catch on the sign mistake. If you would like to make the edits, feel free!
whuber

2
I made the corrections.
Ian Langmore

10

The Gamma distribution is in the exponential family because its density can be expressed as:

f(xθ)=exp(η(θ)T(x)g(θ)+h(x))

Looking at the Gamma density function, its log-normalizer is

g(θ)=log(Γ(c))+clog(b)
with natural parameters
θ=[c11b]

All distributions in the exponential family have KL divergence:

KL(q;p)=g(θp)g(θq)(θpθq)g(θq).

There's a really nice proof of that in:

Frank Nielsen, École Polytechnique, and Richard Nock, Entropies and cross-entropies of exponential families.


Didn't know this. Just a quick question - the g(.) function, does it have to be the same for θp as for θq? So for example, would the above formula be valid for KL divergence of normal pdf from gamma pdf?
probabilityislogic

1
Yes, this formula is for two distributions in the same exponential family.
Neil G
Ao utilizar nosso site, você reconhece que leu e compreendeu nossa Política de Cookies e nossa Política de Privacidade.
Licensed under cc by-sa 3.0 with attribution required.