Last updated: 2020-10-27

Checks: 2 0

Knit directory: misc/

This reproducible R Markdown analysis was created with workflowr (version 1.6.2). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version 5a6cc2a. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/

Untracked files:
    Untracked:  analysis/bayeslogit.md
    Untracked:  analysis/polya_gamma.md
    Untracked:  code/kowal2019code/
    Untracked:  code/logistic.R

Unstaged changes:
    Modified:   analysis/test_typora.md

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


These are the previous versions of the repository in which changes were made to the R Markdown (analysis/kl.Rmd) and HTML (docs/kl.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
Rmd 5a6cc2a DongyueXie 2020-10-27 wflow_publish(c(“analysis/index.Rmd”, “analysis/kl.Rmd”, “analysis/polya_gamma.Rmd”,
html 6e31071 DongyueXie 2020-04-15 Build site.
Rmd a7b43a8 DongyueXie 2020-04-15 wflow_publish(“analysis/kl.Rmd”)

KL divergence direction

Assume \(p\) is true distribution and \(q\) is the approximated one. The forward KL is \(KL(p||q)\) and reverse KL is \(KL(q||p)\).

What’s the difference between them? The forward KL is a sum of \(log\frac{p}{q}\), weighted by \(p\). We want to choose \(q\) to minimize \(KL(p||q)\), so \(q\) will try to cover everywhere \(p>0\), otherwise \(KL(p||q)\) will be large. On the other hand, the reverse KL is weighted by \(q\), so whenever \(q>0\), \(q\) and \(p\) should be close.

Forward KL is called zero avoiding while reverse KL is called zero forcing. A classical example is from GAN tutorial page 24 figure 14, by Ian.

Forward KL is mean seeking, and reverse KL is mode-seeking

Forward KL:

\[\begin{equation} \begin{split} argmin_q KL(p||q) &= argmin_q E_p(\log p) - E_p(\log q) \\&= argmax_q E_p(\log q) \end{split} \end{equation}\]

Reverse KL:

\[\begin{equation} \begin{split} argmin_q KL(q||p) &= argmin_q E_q(\log q) - E_q(\log p) \\&= argmax_q E_q(\log p) + H(q) \end{split} \end{equation}\]

Why variational inference uses reverse KL?

Because forward KL is intractable. https://ermongroup.github.io/cs228-notes/inference/variational/