def cod2sparseSOMP(D, X, L=20, numThreads=-1):

    #D = np.asfortranarray(D / np.tile(np.sqrt((D*D).sum(axis=0)),(D.shape[0],1)))

    X_ = np.asfortranarray(X)
    D_ = np.asfortranarray(D)

    print "Using Simultaneous Orthogonal Matching Pursuit for sparse codification. Please wait..."

    init_time = time.time()
    ind_groups = np.array(xrange(0, X_.shape[1], 1), dtype=np.int32)
    alpha = spams.somp(X=X_,
                       D=D_,
                       L=L,
                       list_groups=ind_groups,
                       numThreads=numThreads)

    end_time = time.time()

    t = end_time - init_time

    print "%f signals processed per second\n" % (float(alpha.shape[1]) / t)

    print "Total time: ", t, "seconds"

    A = alpha.todense()

    #print A[0]

    return A
Exemplo n.º 2
0
def test_somp():
    np.random.seed(0)
    X = np.asfortranarray(np.random.normal(size = (64,10000)),dtype=myfloat)
    D = np.asfortranarray(np.random.normal(size = (64,200)))
    D = np.asfortranarray(D / np.tile(np.sqrt((D*D).sum(axis=0)),(D.shape[0],1)),dtype=myfloat)
    ind_groups = np.array(range(0,10000,10),dtype=np.int32)
    tic = time.time()
    alpha = spams.somp(X,D,ind_groups,L = 10,eps = 0.1,numThreads=-1)
    tac = time.time()
    t = tac - tic
    print("%f signals processed per second" %(X.shape[1] / t))
    return None
Exemplo n.º 3
0
def test_somp():
    np.random.seed(0)
    X = np.asfortranarray(np.random.normal(size=(64, 10000)), dtype=myfloat)
    D = np.asfortranarray(np.random.normal(size=(64, 200)))
    D = np.asfortranarray(D / np.tile(np.sqrt((D * D).sum(axis=0)),
                                      (D.shape[0], 1)),
                          dtype=myfloat)
    ind_groups = np.array(six.moves.xrange(0, 10000, 10), dtype=np.int32)
    tic = time.time()
    alpha = spams.somp(X, D, ind_groups, L=10, eps=0.1, numThreads=-1)
    tac = time.time()
    t = tac - tic
    print("%f signals processed per second" % (X.shape[1] / t))
    return None
Exemplo n.º 4
0
D = np.asfortranarray(D / np.tile(np.sqrt((D * D).sum(axis=0)),
                                  (D.shape[0], 1)),
                      dtype=np.double)
#D=np.asfortranarray(D, dtype=np.double)

tiles, labels = dp.extract_tiles(shuffle=False, dim=tileDim)

labels = np.reshape(labels, (labels.shape[0] * labels.shape[1]))
tiles = np.reshape(tiles, (tiles.shape[0] * tiles.shape[1], tiles.shape[2]))
tiles = np.asfortranarray(tiles.T, dtype=np.double)

ind_groups = np.array(np.arange(0, tiles.shape[1], tileDim * tileDim),
                      dtype=np.int32)

A = spams.somp(tiles, D, ind_groups, L=10, eps=0.1, numThreads=-1)

A = sparse.coo_matrix(A)
A = A.todense()
A = A.T

train_coefs, test_coefs = dp.split(A, portion=0.9)
train_labels, test_labels = dp.split(labels, portion=0.9)

numtest = 50

model = knn.knn(k=5)
preds = np.zeros(numtest)

for i in range(numtest):
    preds[i] = model.fit(train_coefs,
Exemplo n.º 5
0
 def _encode(self, X, A):
     # Solve min_{A_i} ||A_i||_{0,infty}  s.t  ||X_i-D A_i||_2^2 <= eps*n_i
     ind_groups = arange(0, X.shape[1], 10, dtype=int32)
     S=somp(X, A, ind_groups, L=self.nnz, numThreads=-1).todense()
     return S