Esempio n. 1
0
    def benchmark(self):
        numMatrices = 20
        matrixList = []

        print("Generating matrices")

        for i in range(numMatrices):
            print("Iteration: " + str(i))
            m = numpy.random.randint(5000, 20000)
            n = numpy.random.randint(5000, 20000)
            density = numpy.random.rand() * 0.1
            X = scipy.sparse.rand(m, n, density)

            r = numpy.random.randint(10, 50)
            U, s, V = SparseUtils.generateLowRank((m, n), r)

            print(m, n, density, r)
            matrixList.append((X, U, s, V))

        k = 10

        times = []
        print("Starting timings for ARPACK")
        start = time.time()

        for i, matrices in enumerate(matrixList):
            print("Iteration: " + str(i))
            X, U, s, V = matrices
            SVDUpdate.addSparseArpack(U, s, V, X, k)

        times.append(time.time() - start)

        #Compare versus PROPACK
        print("Starting timings for PROPACK")
        start = time.time()

        for i, matrices in enumerate(matrixList):
            print("Iteration: " + str(i))
            X, U, s, V = matrices
            SparseUtils.svdSparseLowRank(X, U, s, V, k)

        times.append(time.time() - start)
        print(times)
Esempio n. 2
0
"""
import sys
import logging
import scipy.sparse
import numpy
from sparsesvd import sparsesvd
from exp.util.SparseUtils import SparseUtils

numpy.random.seed(21)
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
numpy.set_printoptions(precision=3, suppress=True, linewidth=100)

m = 10
n = 10
r = 1
U0, s0, V0 = SparseUtils.generateLowRank((m, n), r)

numInds = 10
inds = numpy.unique(numpy.random.randint(0, m * n, numInds))
A = SparseUtils.reconstructLowRank(U0, s0, V0, inds)
#print(A.todense())

t0 = s0 + numpy.random.rand(s0.shape[0]) * 0.1
B = SparseUtils.reconstructLowRank(U0, t0, V0, inds)
#print(B.todense())

k = 9
U, s, V = sparsesvd(A, k)
U2, s2, V2 = sparsesvd(B, k)

print(A.todense())
Esempio n. 3
0
"""
import sys 
import logging
import scipy.sparse
import numpy
from sparsesvd import sparsesvd
from exp.util.SparseUtils import SparseUtils 

numpy.random.seed(21)
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
numpy.set_printoptions(precision=3, suppress=True, linewidth=100)

m = 10 
n = 10 
r = 1
U0, s0, V0 = SparseUtils.generateLowRank((m, n), r)

numInds = 10 
inds = numpy.unique(numpy.random.randint(0, m*n, numInds)) 
A = SparseUtils.reconstructLowRank(U0, s0, V0, inds)
#print(A.todense())

t0 = s0 + numpy.random.rand(s0.shape[0])*0.1
B = SparseUtils.reconstructLowRank(U0, t0, V0, inds)
#print(B.todense())

k = 9
U, s, V = sparsesvd(A, k)
U2, s2, V2 = sparsesvd(B, k)

print(A.todense())