JuliaStats/Distributions.jl — pull request #269 by brian-j-smith (2014-07-27 21:03:05+00:00)
Title: Fix to ensure consistency between insupport() and logpdf() for Inverse/Wishart

This pull request is meant to fix inconsistencies that can occur between `insupport()` results and `logpdf()` calculations for Wishart and InverseWishart distributions.

The issue:
* Let `D` denote a Wishart or InverseWishart distribution object, and `X` a real matrix to evaluate.
* `logpdf(D, X)` is intended to return `-Inf` if `X` is not in the support of `D`, and a numeric value otherwise.
* Support is tested with `insupport(D, X)`.
* `insupport()` uses the Cholesky factorization of `X`, and `logpdf()` calculations involving `X` are non-Cholesky based.
* If `X` is close to being singular, Cholesky-based calculations of determinants, inverses, etc. can differ from non-Cholesky-based ones.
* This can lead to situations where `insupport()` returns true, but `logpdf()` calculations throw errors (e.g. the non-Cholesky-based inverse cannot be calculated, even though the Cholesky factorization can).
* In a nutshell, `logpdf()` can result in a terminal error instead of a numeric value or `-Inf`, as intended.

The solution proposed in this pull:
* Use Cholesky-based methods to compute the determinant and inverse of `X` in `logpdf()` - `logdet(cholfact(X))` and `inv(cholfact(X))` are the log-determinant and inverse of `X`, respectively.
* Note that `trycholfact()` is added and `hasCholesky()` modified a bit to allow the Cholesky factorization to be computed only once in a call to `logpdf()`. Determinants and inverses are then computed from that one factorization.
* Currently, a call to `logpdf()` can result in unrelated Cholesky factorization, determinant, and inverse calculations.
* Having them all be based on the factorization should make calculations consistent, faster, and more precise.

Feel free to let me know if there are any questions about or suggestions for the pull.