Skip to content

Commit 4390ef3

Browse files
committed
fixing docs
1 parent e77af92 commit 4390ef3

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

diffusion_models/losses/kl_divergence.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ def gaussian_kl(
1111
"""Calculate KL Divergence of 2 Gaussian distributions.
1212
1313
KL divergence between two univariate Gaussians, as derived in [1], with k=1 (dimensionality).
14+
.. math::
15+
D_{KL}(p||q) = \frac{1}{2}\left[\log\frac{|\Sigma_q|}{|\Sigma_p|} - k + (\boldsymbol{\mu_p}-\boldsymbol{\mu_q})^T\Sigma_q^{-1}(\boldsymbol{\mu_p}-\boldsymbol{\mu_q}) + tr\left\{\Sigma_q^{-1}\Sigma_p\right\}\right]
1416
1517
Parameters
1618
----------
@@ -30,11 +32,7 @@ def gaussian_kl(
3032
3133
References
3234
----------
33-
.. math::
34-
D_{KL}(p||q) = \frac{1}{2}\left[\log\frac{|\Sigma_q|}{|\Sigma_p|} - k + (\boldsymbol{\mu_p}-\boldsymbol{\mu_q})^T\Sigma_q^{-1}(\boldsymbol{\mu_p}-\boldsymbol{\mu_q}) + tr\left\{\Sigma_q^{-1}\Sigma_p\right\}\right]
35-
3635
.. [1] https://mr-easy.github.io/2020-04-16-kl-divergence-between-2-gaussian-distributions/
37-
3836
"""
3937
return 0.5 * (torch.log(torch.abs(q_var) / torch.abs(p_var)) - 1.0 + ((p_mean-q_mean)**2)/q_var + p_var/q_var)
4038

@@ -47,6 +45,8 @@ def log_gaussian_kl(
4745
"""Calculate KL Divergence of 2 Gaussian distributions.
4846
4947
KL divergence between two univariate Gaussians, as derived in [1], with k=1 (dimensionality) and log variances.
48+
.. math::
49+
D_{KL}(p||q) = \frac{1}{2}\left[\log\frac{|\Sigma_q|}{|\Sigma_p|} - k + (\boldsymbol{\mu_p}-\boldsymbol{\mu_q})^T\Sigma_q^{-1}(\boldsymbol{\mu_p}-\boldsymbol{\mu_q}) + tr\left\{\Sigma_q^{-1}\Sigma_p\right\}\right]
5050
5151
Parameters
5252
----------
@@ -66,10 +66,6 @@ def log_gaussian_kl(
6666
6767
References
6868
----------
69-
.. math::
70-
D_{KL}(p||q) = \frac{1}{2}\left[\log\frac{|\Sigma_q|}{|\Sigma_p|} - k + (\boldsymbol{\mu_p}-\boldsymbol{\mu_q})^T\Sigma_q^{-1}(\boldsymbol{\mu_p}-\boldsymbol{\mu_q}) + tr\left\{\Sigma_q^{-1}\Sigma_p\right\}\right]
71-
7269
.. [1] https://mr-easy.github.io/2020-04-16-kl-divergence-between-2-gaussian-distributions/
73-
7470
"""
7571
return 0.5 * (q_logvar - p_logvar - 1.0 + torch.exp(p_logvar - q_logvar) + ((p_mean - q_mean)**2)*torch.exp(-q_logvar))

0 commit comments

Comments
 (0)