Skip to content

LKJ distribution: check if matrix is positive definite. #983

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 3 commits into from
Feb 22, 2016
Merged

LKJ distribution: check if matrix is positive definite. #983

merged 3 commits into from
Feb 22, 2016

Conversation

agoldin
Copy link
Contributor

@agoldin agoldin commented Feb 17, 2016

Without this check MCMC strays into neverland with negative eigenvalues for
covariance matrix. This is not good at all ( see
#873 ).

check MCMC strays into neverland with negative eigenvalues for
covariance matrix. This is not good at all ( see
#873 ).
@springcoil
Copy link
Contributor

Hey @agoldin this looks good to me - I think this is a good addition to PyMC3 especially since this kind of error has come up before - but is there any way you could add a quick test. Maybe deliberately trying a distribution with negative eigenvalues for this function and then proving that an exception is raised.

No disagreements about multivariate.py maybe @twiecki or @jsalvatier have some comments.

@agoldin
Copy link
Contributor Author

agoldin commented Feb 17, 2016

I'll look where I can add tests over weekend. I am not yet very comfortable with github way of doing things. Thx.

@twiecki
Copy link
Member

twiecki commented Feb 18, 2016

It's a bit surprising that T.all(eigh(X)[0] > 0) doesn't work. It raises a gradient error for you?

@agoldin
Copy link
Contributor Author

agoldin commented Feb 18, 2016

The derivative of Eigh is defined via class EighGrad, which does not have gradient defined. Even if eigh appears only as an argument of switch() , guess_scaling wants to take second derivative of all the functions that logp() is composed of, even if those derivatives are later multiplied by 0. I'd imagine to fix it one should play with then (at this point it is too much for me). Instead I just defined a new operation and explicitly expressed that derivative of PositiveDefiniteMatrix() is zero. Not being able to use NUTS sampler is a problem, because it is so much better.

Anyway cholesky() should be faster than eigh(). It would be great to be able to use it on GPU, but even matrix inversion in Theano seems to be CPU only.

May be in far future, when pymc4 is based on tensor flow or something similar.

@twiecki
Copy link
Member

twiecki commented Feb 18, 2016

@nouiz Do you think this makes sense from a theano perspective?

@agoldin
Copy link
Contributor Author

agoldin commented Feb 22, 2016

@springcoil , pls check if this is a test you have in mind. Thanks.

@twiecki
Copy link
Member

twiecki commented Feb 22, 2016

@agoldin This looks good to me.

@twiecki
Copy link
Member

twiecki commented Feb 22, 2016

@agoldin can you replace the check in Wishart with this one?

@agoldin
Copy link
Contributor Author

agoldin commented Feb 22, 2016

@twiecki , pls check.

@twiecki
Copy link
Member

twiecki commented Feb 22, 2016

LGTM, thanks @agoldin!

twiecki added a commit that referenced this pull request Feb 22, 2016
LKJ distribution: check if matrix is positive definite.
@twiecki twiecki merged commit dec8439 into pymc-devs:master Feb 22, 2016
x, = inp
return [x.zeros_like(theano.config.floatX)]

def __str__(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

It seem good overall. But personnaly, I don't like a str that don't return the class name. I think it make things more confusing when you search. So personally, I would remove that method.

Copy link
Member

Choose a reason for hiding this comment

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

Great, thanks for reviewing @nouiz!

@agoldin
Copy link
Contributor Author

agoldin commented Feb 22, 2016

@nouiz , did not think of str. Will fix tonight.

@springcoil
Copy link
Contributor

Sorry for missing this @agoldin - it looks good to me too. I'd fix the str though like @nouiz said.

@agoldin
Copy link
Contributor Author

agoldin commented Feb 22, 2016

Thanks, @springcoil . I will not bother then to reduce confusion.

@agoldin agoldin deleted the LKJcorr_check_positive_definite branch February 22, 2016 16:21
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