-
Notifications
You must be signed in to change notification settings - Fork 230
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
Error on covariance initialization when there are linearly dependent dimensions #276
Comments
Thanks for the detailed report! I agree that we should handle this more gracefully, and I'm surprised we don't catch it earlier in the initialization code. It seems like we need to insert a NaN check after computing the covariance matrix. |
I thought of fixing this by using the pseudo-inverse but I am not sure what are the theoretical implications in this context of using the pseudo-inverse when the inverse doesn't exist. |
Using the pseudo-inverse would be fine as long as the algorithm does not require the matrix to be strictly PD. The pseudo inverse of a PSD matrix is only guaranteed to be PSD, and will be non-singular when the original matrix is non-singular |
Good catch @grudloff !
Yes, I agree, the check was done in metric-learn/metric_learn/rca.py Lines 99 to 104 in 1b40c3b
_initialize_metric_mahalanobis
|
Also, we had a similar problem on metric-learn/test/test_mahalanobis_mixin.py Line 572 in 1e42acb
strict_pd=False and the cov matrix is singular.
|
Description
While fitting on MMC_Supervised with init="covariance" on the MNIST dataset, a warning is raised and an error is thrown. I tracked down the problem to the initialization which is done with the inverse of the covariance matrix, which isn't invertible in this case because there are some LD dimensions.
This can be easily fixed by replacing by the (Moore-Penrose) pseudo-inverse as it is done for the random initialization. I am not sure this would be necessarily the desired behavior, but in any case, this issue should be addressed at least whit a more user-friendly error stating that there are some linearly dependent dimensions and that the input should be reduced to eliminate this redundancy.
Haven't checked but this issue should arise on any algorithm using the covariance initialization that doesn't require an SDP matrix.
Steps/Code to Reproduce
Expected Results
No error or a more user-friendly error.
Actual Results
The following warnings are thrown during runtime.
And this is the error thrown, which states that the matrix is not symetric. The computed matrix is full of nan/inf.
Versions
Linux-5.3.0-26-generic-x86_64-with-debian-buster-sid
Python 3.7.4 (default, Aug 13 2019, 20:35:49)
[GCC 7.3.0]
NumPy 1.17.2
SciPy 1.3.1
Scikit-Learn 0.21.3
Metric-Learn 0.5.0
The text was updated successfully, but these errors were encountered: