From e7804abdf38fc4ed26a52b4e1c16da26cce811c8 Mon Sep 17 00:00:00 2001 From: Patrick Simianer
Date: Fri, 4 Aug 2017 12:54:33 +0200 Subject: algorithms/matrix-factorization --- algorithms/matrix-factorization.py | 56 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100755 algorithms/matrix-factorization.py (limited to 'algorithms') diff --git a/algorithms/matrix-factorization.py b/algorithms/matrix-factorization.py new file mode 100755 index 0000000..ffffc59 --- /dev/null +++ b/algorithms/matrix-factorization.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python + +import numpy as np +import scipy +from scipy.sparse.linalg import svds + +m = 512 +n = 1024 +M = np.random.rand(m,n) +print "original "+str(m*n) + + +# svds +if False: + print "svds" + U, sigma, V = svds(M, k = 42) + S = np.diag(sigma) + M_ = np.dot(U, np.dot(S, V)) + shapes = U.shape, S.shape, V.shape + sum = 0 + for sh in shapes: + sum = sum + sh[0]*sh[1] + print "params "+str(sum) + print np.absolute(np.sum(M - M_)) + + print + +# qr +if False: + print "qr" + q, r = np.linalg.qr(M,mode='reduced') + sum = 0 + for sh in (q.shape, r.shape): + sum = sum + sh[0]*sh[1] + print "params "+str(sum) + +# eig +#print "eig (just square, also: Cholesky)" +#la, v = scipy.linalg.eig(M) + +#print "M" +#print M +#print "U" +#print U +#print "V" +#print V +#print "shapes" +#print "U*diag(S)*V^T" +#print(M_) +#print "M_ - M" +#print M.shape, M_.shape +#print M - M_ +#print "sum" +#print "shapes" +#print U.shape, S.shape, V.shape + -- cgit v1.2.3