-
-
Notifications
You must be signed in to change notification settings - Fork 26.5k
ENH Add dtype preservation to LocallyLinearEmbedding #24337
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
base: main
Are you sure you want to change the base?
ENH Add dtype preservation to LocallyLinearEmbedding #24337
Conversation
|
Thanks for the PR @MisaOgura ! Looking quite good. Please add an entry in the |
|
I've looked into the failing tests on CI It seems that there is some instability with this test, as; 1. Different random seeds lead to different parameterised cases failinge.g. running tests locally on M1 2. Same random seeds lead to different parameterised cases failing on different platforme.g. comparing tests on CI & locally, with the same default seed In both cases above, it is Cf. A similar phenomenon is flagged in another test within the same file e.g. running tests locally on M1 |
417a0e2 to
cac4a3d
Compare
|
I just resolve the conflict. I will give a go to this PR. |
glemaitre
left a comment
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 made a pass on the algorithm to check which structures are not yet preserved in np.float32.
Regarding the failure, I only think that we will have to define a more lenient tolerance for the 32-bit case.
I would like first to impose the bitness in the algorithm and then focus more specifically on the tests.
@MisaOgura Would you have time to carry on the changes?
| "n_jobs": [None, Integral], | ||
| } | ||
|
|
||
| def _more_tags(self): |
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.
Could you move this method at the end of the class
| return csr_matrix( | ||
| (data.ravel(), ind.ravel(), indptr), | ||
| shape=(n_samples, n_samples), | ||
| dtype=X.dtype, |
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.
There is no need to force the dtype here because data returned by barycenter_weights is preserving the dtype.
| evals = np.zeros([N, nev], dtype=X.dtype) | ||
|
|
||
| # choose the most efficient way to find the eigenvectors | ||
| use_svd = n_neighbors > d_in |
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.
We should modify the creation of tmp to avoid some later casting:
tmp = np.dot(V.transpose(0, 2, 1), np.ones(n_neighbors, dtype=X.dtype))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.
The same with the initialization of w_reg:
w_reg = np.zeros((N, n_neighbors), dtype=X.dtype)| M = np.zeros((N, N), dtype=X.dtype) | ||
| for i in range(N): | ||
| s_i = s_range[i] | ||
|
|
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.
The same for h in the loop below:
h = np.full(s_i, alpha_i, dtype=X.dtype) - np.dot(Vi.T, np.ones(n_neighbors, dtype=X.dtype))| M = np.zeros((N, N), dtype=X.dtype) | ||
|
|
||
| use_svd = n_neighbors > d_in | ||
|
|
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.
Below, we should initialize Gi:
Gi = np.zeros((n_neighbors, n_components + 1), dtype=X.dtype)
Reference Issues/PRs
In scope of #11000
What does this implement/fix? Explain your changes.
Implement
dtypepreservation toLocallyLinearEmbeddingand relevant tests for various methods and solvers.Any other comments?