-
Notifications
You must be signed in to change notification settings - Fork 229
[MRG] FIX: fix lsml inversion #203
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
[MRG] FIX: fix lsml inversion #203
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. It's possible that this will mask some issues from users that provide a garbage matrix as the prior, but that's probably okay.
@@ -79,9 +79,12 @@ def test_singular_covariance_does_not_diverge(self): | |||
# when this covariance has null eigenvalues (See | |||
# https://github.com/metric-learn/metric-learn/issues/202) | |||
# TODO: remove when # 195 is merged | |||
X, Y = make_classification(n_redundant=2, random_state=42) | |||
rng = np.random.RandomState(42) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
somehow the covariance matrix in the previous example was not exactly singular so I built the example by hand, and it is indeed truly singular and exhibited another place where we should use the pseudo inverse
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure that this is a good fix, because logdet divergence is finite only if the matrix is (strictly) positive definite. Hence working the whole time with singular matrices and pseudo-inverses looks like deviating quite a bit from the algorithm.
I think a better fix may be simply to return an error when the prior is not positive definite. When this happens with the covariance, the identity can be used (this could be done in #180)
That's right, I didn't think of that... EDIT: I got confused with PD and PSD: I guess this was the question |
Since in the end we will use init='identity' for the examples, I guess we don't need to merge this PR quicker, and the work will be done in PR #195 , so I'm closing the PR |
Let me correct my own claim. While the LogDet divergence is indeed finite only for pairs of PD matrices, in LSML and other algorithms using LogDet (ITML, SDML) having a PSD (not strictly PD) prior is probably fine in most cases because the logdet term on the prior is ignored since it is constant. So this PR could be merged if you use pseudo-inverse only for the prior (but not for the gradient!). Yet, I think it is probably safer to rule out non-PD priors for these algorithms (see my other comment in #195) |
Fixes #202