Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
SVD testing code for the netflix matrix, by David F. Gleich and Yangyang Hou.
%% Read Netflix dataset
A = readSMAT('/scratch/dgleich/netflix/netflix.smat');
k = [10 25 50 100 150 200];
l = size(k,2);
%% Matlab's SVDS
for i= 1:l
tic;
[U,S,V] = svds(A,k(i));
toc
file = strcat('test1_',int2str(k(i)), '.mat');
d = diag(S);
save(file, 'd');
end
%% Using eigs() on A*A'
m = size(A,1);
Cx = @(x) A*(A'*x);
for i= 1:l
tic;
[V D]=eigs(Cx,m,k(i),'LA',struct('issym',1,'disp',0));
toc
file = strcat('test2_',int2str(k(i)), '.mat');
d = diag(D);
save(file, 'd');
end
%% Using Propack.
addpath('/homes/hou13/fall2013/MR_SVD_test/PROPACK/matlab');
m = size(A,1); n = size(A,2);
Ax=@(x) A*x;
Atx=@(x) A'*x;
for i= 1:l
tic;
[UD D VD]=lansvd(Ax,Atx,m,n,k(i),'L');
toc
file = strcat('test3_',int2str(k(i)), '.mat');
d = diag(D);
save(file, 'd');
end
import numpy as np
from time import time
from scipy.sparse import csc_matrix
from scipy.linalg import svd
from pypropack import svdp
from scipy.sparse.linalg import svds
from sparsesvd import sparsesvd
import scipy.io
if __name__ == '__main__':
D = scipy.io.loadmat('/u/puma/hou13/fall2013/MR_SVD_test/netflix.mat')
M = D['A']
#M = '/scratch/dgleich/netflix/netflix.smat'
ks = [10, 25, 50, 100, 150, 200]
# PROPACK
times1 = []
for k in ks:
t0 = time()
res1 = svdp(M, k, kmax = 1000, compute_u=False, compute_v=False)
t1 = time()
t = t1 - t0
times1.append(t)
print k, t
scipy.io.savemat('test1.mat',{'d':res1})
# ARPACK
times2 = []
for k in ks:
t0 = time()
res2 = svds(M, k, return_singular_vectors = False)
t1 = time()
t = t1 - t0
times2.append(t)
print k, t
scipy.io.savemat('test2.mat',{'d':res2})
# SVDLIBC
times3 = []
for k in ks:
t0 = time()
u,res3,v = sparsesvd(M, k)
t1 = time()
t = t1 - t0
times1.append(t)
print k, t
scipy.io.savemat('test3.mat',{'d':res3})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment