Can pm.Wishart be used as a likelihood for an observed sample covariance?

Hi PyMC community,

I’m building an inverse model to estimate parameters that control transport of multiple elements in a fluid system. My observations are summary statistics: (1) mean values and (2) covariance matrices between elements. Given a parameter set, my physical forward model can also generate the corresponding mean vector and covariance matrix.

I would like to use a Wishart likelihood for the observed covariance matrix.
However, the PyMC docs for pm.Wishart say it is “unusable in a PyMC model” and recommend LKJCholeskyCov / LKJCorr instead
(see the link below:
https://www.pymc.io/projects/docs/en/latest/api/distributions/generated/pymc.Wishart.html)

My understanding is that this warning mostly refers to using Wishart as a prior (because MCMC would have trouble proposing symmetric positive-definite matrices). In my case I use Wishart only as a likelihood with observed=Sigma_obs (so no sampling of matrices, only evaluation of the log-likelihood).

Question: Is it reasonable to use pm.Wishart as a likelihood for an observed covariance matrix in PyMC? If not recommended, what is the preferred alternative when the data I have are mean and covariance?

Really appreciate any idea or suggestion!

I don’t see why not. If you use cov_hat = pm.Wishart(..., observed=cov_data) does it raise an error?

After I used cov_hat = pm.Wishart(…, observed=cov_data), it raised a warning as follows:

UserWarning: The Wishart distribution can currently not be used for MCMC sampling. The probability of sampling a symmetric matrix is basically zero. Instead, please use LKJCholeskyCov or LKJCorr. For more information on the issues surrounding the Wishart see here: Wishart fails with valid arguments · Issue #538 · pymc-devs/pymc · GitHub.

Regardless the warning, the code kepet running and ended with a normal result as I expected.
So my confusion is why there is such a strong warning.

It seems the warning is too broad. Could you open an issue on github?

1 Like

Yeah we could ommit the warning if there’s an observed, or even remove it altogether. It’s a bit too opinionated about how it’s going to be used. Similar thing applies to pm.Censored, it isn’t good as a prior, and we just document that in the docstrings, we don’t issue a warning for it.

1 Like

Sure! Thanks for your suggestion. I just opened an issue
( DOC: Clarify the pm.Wishart warning (“unusable in a PyMC model”) · Issue #8196 · pymc-devs/pymc)

Yes, I agree with you.Such a warning is too opinionated and really creates confusion