Skip to content

Conversation

@johnczito
Copy link
Member

This PR adds the singular branch of the Wishart distribution. That is, for integer df < p, the Wishart is a distribution over rank-df positive semidefinite p x p matrices, defined in the usual way.

In this case the Wishart does not have a Lebesgue density, but it does have a density with respect to an appropriate dominating measure on rank-df positive semidefinite matrices, which is given in Theorem 6 here. The usual density in the full rank case is a special case of this "generalized" density.

I am currently implementing this by extending the behavior of Wishart instead of defining a separate distribution. I prefer this because it's what Matlab does, and because I think that a hard distinction between singular/nonsingular Wishart is ultimately artificial and could cause headache for the user. For example, there are certain time series models where the degrees of freedom of a Wishart are time-varying, and may or may not be singular from period to period. A user implementing this might prefer that we supply one Wishart that covers both cases instead of supplying two and forcing them to manually switch between them.

Let me know what you think!

@codecov-io
Copy link

codecov-io commented Apr 6, 2020

Codecov Report

Merging #1097 into master will increase coverage by 0.16%.
The diff coverage is 95.31%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1097      +/-   ##
==========================================
+ Coverage   79.54%   79.70%   +0.16%     
==========================================
  Files         113      113              
  Lines        5787     5834      +47     
==========================================
+ Hits         4603     4650      +47     
  Misses       1184     1184              
Impacted Files Coverage Δ
src/matrix/wishart.jl 85.56% <93.61%> (+6.46%) ⬆️
src/utils.jl 89.47% <100.00%> (+8.52%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2d7f203...c405a42. Read the comment docs.

@johnczito johnczito requested a review from mschauer May 11, 2020 19:48
# -----------------------------------------------------------------------------

function Wishart(df::T, S::AbstractPDMat{T}) where T<:Real
function Wishart(df::T, S::AbstractPDMat{T}, warn::Bool = true) where T<:Real
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a warning for expected functionality is not so nice

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair, and I'm happy to get rid of this.

I guess I had in mind that this functionality is more unexpected for most users, so I wanted to give them a heads up.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to remove the warning? I agree that it's probably not good to warn the users if Distributions supports this functionality, maybe it would be better to just mention it clearly in show(::Wishart)? Additionally, it is inconsistent with the behaviour of Normal(4.0, 0.0) and other special cases. An additional benefit of not printing warnings would be that the constructor would be compatible with Zygote, as noted in TuringLang/DistributionsAD.jl#84 (although probably that is not a good argument since Distributions does not try to support Zygote in the first place).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it would be better to just mention it clearly in show(::Wishart)?

Yes, great idea. Will do that soon. The warning was really intended more in the spirit of a deprecation: a temporary heads up about functionality people might not be expecting.

although probably that is not a good argument since Distributions does not try to support Zygote in the first place

Agreed, but I am in favor of thinking through reasonable changes that Distributions could make that would allow Turing to simply add methods to Distributions.Wishart and so on instead of reimplementing it. I'll maybe open an issue about that someplace.

johnczito and others added 3 commits May 12, 2020 14:50
Co-authored-by: Moritz Schauer <moritzschauer@web.de>
@johnczito
Copy link
Member Author

Thanks for the help @mschauer. I guess if there are no objections I'll merge this in 24 hours?

@johnczito johnczito merged commit 4cbeba8 into JuliaStats:master May 21, 2020
@johnczito johnczito deleted the add_singular_wishart branch May 21, 2020 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants