-
Notifications
You must be signed in to change notification settings - Fork 0
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
update PCA (randomized SVD) #63
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.
Thanks @lucys0, I've added some minor requests. The more important one is that torch.svd is deprecated.
tests/unit/pca/pca_test.py
Outdated
except AssertionError: | ||
import ipdb | ||
|
||
ipdb.set_trace() |
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.
Remove?
torchml/decomposition/pca.py
Outdated
self, | ||
*, | ||
n_components=None, | ||
svd_solver="full", |
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.
svd_solver should be "auto" by default, raise exceptions for the ones we don't support.
tests/unit/pca/pca_test.py
Outdated
) | ||
ref_transformed = ref.fit_transform(X) | ||
|
||
model = ml.decomposition.PCA(n_components=N_COMPONENTS) |
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.
Add svd_solver="full" as argument.
torchml/decomposition/pca.py
Outdated
* n_components (int), default=None | ||
* svd_solver (string), default="full" |
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.
Formatting of arguments, follow this: https://github.com/learnables/torchml/blob/master/torchml/naive_bayes/gaussian_naive_bayes.py#L8
torchml/decomposition/pca.py
Outdated
~~~python | ||
>>> import torch | ||
>>> from torchml.decomposition import PCA | ||
>>> X = torch.tensor([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]]) | ||
>>> pca = PCA(n_components=2) | ||
>>> pca.fit(X) |
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.
Remove leading >>>
self.S = S | ||
return self | ||
|
||
def fit_transform(self, X): |
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.
This is good. Could we add a .transform()
method to this class too? Because people usually fit on 1 dataset (eg, train) and apply the same transformation on another (eg, test exemplars).
torchml/decomposition/pca.py
Outdated
|
||
# Compute SVD | ||
randomized = True if self.svd_solver == "randomized" else False | ||
U, S, V = torch.svd(X, some=randomized) |
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.
torch.svd() is deprecated in favor for torch.linalg.svd(). Also, the arguments change from one to the next.
Fixes #30