Created
December 11, 2017 19:10
-
-
Save ZacBlanco/b509a8c142c6cf5ffdca4dd0217059f5 to your computer and use it in GitHub Desktop.
Facebook fast SVD/PCA test
This file contains hidden or 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 unittest | |
| import numpy as np | |
| import fbpca | |
| from scipy.linalg import qr, lu | |
| class FBPCATest(unittest.TestCase): | |
| def test1(self): | |
| a = np.matrix([ | |
| [1, 5, 10, 1, 18], | |
| [2, 14, 11, 7, 25], | |
| [3, 17, 15, 6, 17], | |
| [4, 10, 27, 9, 25], | |
| [5, 11, 10, 12, 36] | |
| ]) | |
| u, s, v = fbpca.pca(a, k=2, raw=True) | |
| U, S, Va = np.linalg.svd(a) | |
| print("U from FBPCA") | |
| print(u) | |
| print("U from normal SVD") | |
| print(U) | |
| print("Singular Values from FBPCA") | |
| print(s) | |
| print("Singular values from normal SVD") | |
| print(S) | |
| print("Va from FBPCA") | |
| print(v) | |
| print("VA from normal SVD") | |
| print(Va) | |
| # k = fbpca.diffsnorm(a, u, s, v, n_iter=20) | |
| # print(k) | |
| print(a - u.dot(np.diag(s).dot(v))) | |
| print("Done") | |
| if __name__ == "__main__": | |
| unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment