-
-
Save spillai/6101589 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np, numpy.linalg as linalg | |
def fast_svd(M, k): | |
p = k+5 | |
Y = np.dot(M, np.random.normal(size=(M.shape[1],p))) | |
Q,r = linalg.qr(Y) | |
B = np.dot(Q.T,M) | |
Uhat, s, v = linalg.svd(B, full_matrices=False) | |
U = np.dot(Q, Uhat) | |
return U.T[:k].T, s[:k], v[:k] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment