Skip to content

WIP: Update LKJ notebook to not refer to Wishart #2184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions docs/source/notebooks/LKJ.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Outside of the [beta](https://en.wikipedia.org/wiki/Beta_distribution)-[binomial](https://en.wikipedia.org/wiki/Binomial_distribution) model, the multivariate normal model is likely the most studied Bayesian model in history. Unfortunately, as this [issue](https://github.com/pymc-devs/pymc3/issues/538) shows, `pymc3` cannot (yet) sample from the standard conjugate [normal-Wishart](https://en.wikipedia.org/wiki/Normal-Wishart_distribution) model. Fortunately, `pymc3` *does* support sampling from the [LKJ distribution](http://www.sciencedirect.com/science/article/pii/S0047259X09000876). This post will show how to fit a simple multivariate normal model using `pymc3` with an normal-LKJ prior.\n",
"\n",
"The normal-Wishart prior is conjugate for the multivariate normal model, so we can find the posterior distribution in closed form. Even with this closed form solution, sampling from a multivariate normal model in `pymc3` is important as a building block for more complex models.\n",
"Outside of the [beta](https://en.wikipedia.org/wiki/Beta_distribution)-[binomial](https://en.wikipedia.org/wiki/Binomial_distribution) model, the multivariate normal model is likely the most studied Bayesian model in history. `PyMC3` supports sampling from the [LKJ distribution](http://www.sciencedirect.com/science/article/pii/S0047259X09000876). The LKJ distribution represents the distribution on correlation matrices and is conjugate to the multivariate normal distribution. This post will show how to fit a simple multivariate normal model using `pymc3` with a normal-LKJ prior.\n",
"\n",
"First, we generate some two-dimensional sample data."
]
Expand Down
11 changes: 7 additions & 4 deletions pymc3/distributions/multivariate.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,17 +542,17 @@ class Wishart(Continuous):
Note
----
This distribution is unusable in a PyMC3 model. You should instead
use WishartBartlett or LKJCholeskyCov, LKJCorr.
use LKJCholeskyCov or LKJCorr.
"""

def __init__(self, nu, V, *args, **kwargs):
super(Wishart, self).__init__(*args, **kwargs)
warnings.warn('The Wishart distribution can currently not be used '
'for MCMC sampling. The probability of sampling a '
'symmetric matrix is basically zero. Instead, please '
'use WishartBartlett or better yet, LKJCholeskyCov/LKJCorr.'
'For more information on the issues surrounding the '
'Wishart see here: https://github.com/pymc-devs/pymc3/issues/538.',
'use LKJCholeskyCov or LKJCorr. For more information '
'on the issues surrounding the Wishart see here: '
'https://github.com/pymc-devs/pymc3/issues/538.',
UserWarning)
self.nu = nu
self.p = p = V.shape[0]
Expand Down Expand Up @@ -624,6 +624,9 @@ def WishartBartlett(name, S, nu, is_cholesky=False, return_cholesky=False, testv
This is not a standard Distribution class but follows a similar
interface. Besides the Wishart distribution, it will add RVs
c and z to your model which make up the matrix.

This distribution is usually a bad idea to use as a prior for multivariate
normal. You should instead use LKJCholeskyCov or LKJCorr.
"""

L = S if is_cholesky else scipy.linalg.cholesky(S)
Expand Down