Fix to ensure consistency between insupport() and logpdf() for Inverse/Wishart #269
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request is meant to fix inconsistencies that can occur between
insupport()
results andlogpdf()
calculations for Wishart and InverseWishart distributions.The issue:
D
denote a Wishart or InverseWishart distribution object, andX
a real matrix to evaluate.logpdf(D, X)
is intended to return-Inf
ifX
is not in the support ofD
, and a numeric value otherwise.insupport(D, X)
.insupport()
uses the Cholesky factorization ofX
, andlogpdf()
calculations involvingX
are non-Cholesky based.X
is close to being singular, Cholesky-based calculations of determinants, inverses, etc. can differ from non-Cholesky-based ones.insupport()
returns true, butlogpdf()
calculations throw errors (e.g. the non-Cholesky-based inverse cannot be calculated, even though the Cholesky factorization can).logpdf()
can result in a terminal error instead of a numeric value or-Inf
, as intended.The solution proposed in this pull:
X
inlogpdf()
-logdet(cholfact(X))
andinv(cholfact(X))
are the log-determinant and inverse ofX
, respectively.trycholfact()
is added andhasCholesky()
modified a bit to allow the Cholesky factorization to be computed only once in a call tologpdf()
. Determinants and inverses are then computed from that one factorization.logpdf()
can result in unrelated Cholesky factorization, determinant, and inverse calculations.Feel free to let me know if there are any questions about or suggestions for the pull.