Skip to content
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

Merged
merged 9 commits into from
May 27, 2023
Merged

update PCA (randomized SVD) #63

merged 9 commits into from
May 27, 2023

Conversation

lucys0
Copy link
Contributor

@lucys0 lucys0 commented Oct 28, 2022

Fixes #30

@lucys0 lucys0 requested a review from seba-1511 October 28, 2022 04:34
Copy link
Member

@seba-1511 seba-1511 left a 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.

Comment on lines 28 to 31
except AssertionError:
import ipdb

ipdb.set_trace()
Copy link
Member

Choose a reason for hiding this comment

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

Remove?

self,
*,
n_components=None,
svd_solver="full",
Copy link
Member

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.

)
ref_transformed = ref.fit_transform(X)

model = ml.decomposition.PCA(n_components=N_COMPONENTS)
Copy link
Member

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.

Comment on lines 22 to 23
* n_components (int), default=None
* svd_solver (string), default="full"
Copy link
Member

Choose a reason for hiding this comment

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

Comment on lines 27 to 32
~~~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)
Copy link
Member

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):
Copy link
Member

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).


# Compute SVD
randomized = True if self.svd_solver == "randomized" else False
U, S, V = torch.svd(X, some=randomized)
Copy link
Member

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.

@seba-1511 seba-1511 merged commit 2275f4e into master May 27, 2023
0 of 12 checks passed
@seba-1511 seba-1511 deleted the pca branch May 27, 2023 08:57
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.

PCA
2 participants