示例#1
0
def demo():
    A = np.random.randn(100, 200)
    X = np.random.randn(100, 100)
    lamb = 0.01

    print("solve min |Z|_* + lambda |E|_21 s.t. X = AZ + E by exact ALM ...")

    tic = time.time()
    Z1, E1 = solve_lrr(X, A, lamb, reg=0, alm_type=0)
    obj1 = np.sum(np.linalg.svd(Z1)[1]) + lamb * np.sum(np.sqrt(np.sum(E1 ** 2,
                                                                       1)))
    print("Elapsed time:", time.time() - tic)

    print("objective value=", obj1)

    print("solve min |Z|_* + lambda |E|_21 s.t. X = AZ + E by inexact ALM ...")

    tic = time.time()
    Z2, E2 = solve_lrr(X, A, lamb, reg=0, alm_type=1)
    obj2 = np.sum(np.linalg.svd(Z2)[1]) + lamb * np.sum(np.sqrt(np.sum(E2 ** 2,
                                                                       1)))
    print("Elapsed time:", time.time() - tic)
    print("objective value=", obj2)

    diff = np.max(np.abs(Z1 - Z2))

    print("### Warning: difference of the solution found by those two \
          approaches: |Z1 - Z2|_inf=%f" % diff)

    print("solve min |Z|_* + lambda |E|_1 s.t. X = AZ + E by exact ALM ...")
    tic = time.time()
    Z1, E1 = solve_lrr(X, A, lamb, reg=1, alm_type=0)
    obj1 = np.sum(np.linalg.svd(Z1)[1]) + lamb * np.sum(np.sqrt(np.sum(E1 ** 2,
                                                                       1)))
    print("Elapsed time:", time.time() - tic)

    print("objective value=", obj1)

    print("solve min |Z|_* + lambda |E|_1 s.t. X = AZ + E by inexact ALM ...")
    tic = time.time()
    Z2, E2 = solve_lrr(X, A, lamb, reg=1, alm_type=1)
    obj2 = np.sum(np.linalg.svd(Z2)[1]) + lamb * np.sum(np.sqrt(np.sum(E2 ** 2,
                                                                       1)))
    print("Elapsed time:", time.time() - tic)
    print("objective value=", obj2)

    diff = np.max(np.abs(Z1 - Z2))

    print("### Warning: difference of the solution found by those two\
          approaches: |Z1 - Z2|_inf=", diff)
示例#2
0
文件: demo.py 项目: barbosaaob/lrr
def demo():
    A = np.random.randn(100, 200)
    X = np.random.randn(100, 100)
    lamb = 0.01

    print "solve min |Z|_* + lambda |E|_21 s.t. X = AZ + E by exact ALM ..."

    tic = time.time()
    Z1, E1 = solve_lrr(X, A, lamb, reg=0, alm_type=0)
    obj1 = np.sum(np.linalg.svd(Z1)[1]) + lamb * np.sum(np.sqrt(np.sum(E1 ** 2,
                                                                       1)))
    print "Elapsed time:", time.time() - tic

    print "objective value=", obj1

    print "solve min |Z|_* + lambda |E|_21 s.t. X = AZ + E by inexact ALM ..."

    tic = time.time()
    Z2, E2 = solve_lrr(X, A, lamb, reg=0, alm_type=1)
    obj2 = np.sum(np.linalg.svd(Z2)[1]) + lamb * np.sum(np.sqrt(np.sum(E2 ** 2,
                                                                       1)))
    print "Elapsed time:", time.time() - tic
    print "objective value=", obj2

    diff = np.max(np.abs(Z1 - Z2))

    print "### Warning: difference of the solution found by those two \
          approaches: |Z1 - Z2|_inf=%f" % diff

    print "solve min |Z|_* + lambda |E|_1 s.t. X = AZ + E by exact ALM ..."
    tic = time.time()
    Z1, E1 = solve_lrr(X, A, lamb, reg=1, alm_type=0)
    obj1 = np.sum(np.linalg.svd(Z1)[1]) + lamb * np.sum(np.sqrt(np.sum(E1 ** 2,
                                                                       1)))
    print "Elapsed time:", time.time() - tic

    print "objective value=", obj1

    print "solve min |Z|_* + lambda |E|_1 s.t. X = AZ + E by inexact ALM ..."
    tic = time.time()
    Z2, E2 = solve_lrr(X, A, lamb, reg=1, alm_type=1)
    obj2 = np.sum(np.linalg.svd(Z2)[1]) + lamb * np.sum(np.sqrt(np.sum(E2 ** 2,
                                                                       1)))
    print "Elapsed time:", time.time() - tic
    print "objective value=", obj2

    diff = np.max(np.abs(Z1 - Z2))

    print "### Warning: difference of the solution found by those two\
          approaches: |Z1 - Z2|_inf=", diff
示例#3
0
def LowRank(source, target):
    A = source.numpy()
    X = target.numpy()
    lamb = 0.01
    loss = 0

    #print("solve min |Z|_* + lambda |E|_1 s.t. X = AZ + E by exact ALM ...")
    #tic = time.time()
    #Z1, E1 = solve_lrr(X, A, lamb, alm_type=0)
    #obj1 = np.sum(np.linalg.svd(Z1)[1]) + lamb * np.sum(np.sqrt(np.sum(E1 ** 2, 1)))
    #print("Elapsed time:", time.time() - tic)
    #print("objective value=", obj1)

    #print("solve min |Z|_* + lambda |E|_1 s.t. X = AZ + E by inexact ALM ...")
    tic = time.time()
    Z2, E2 = solve_lrr(X, A, lamb, alm_type=1)
    obj2 = np.sum(
        np.linalg.svd(Z2)[1]) + lamb * np.sum(np.sqrt(np.sum(E2**2, 1)))
    #print("Elapsed time:", time.time() - tic)
    #print("objective value=", obj2)

    #diff = np.max(np.abs(Z1 - Z2))
    loss = np.max(np.abs(Z2))
    print("low-rank loss", loss)

    return loss
示例#4
0
import numpy as np
import sys

sys.path.insert(0, "/home/adriano/workspace/lrr")

from solve_lrr import solve_lrr

data = np.loadtxt("/tmp/data")
X = data.T
A = X
l = 0.1

Z, E = solve_lrr(X, A, l, reg=1, alm_type=1, display=True)

np.savetxt("/tmp/Z", Z)
np.savetxt("/tmp/E", E)
示例#5
0
文件: validation.py 项目: wawjddq/lrr
import numpy as np
import sys
sys.path.insert(0, '/home/adriano/workspace/lrr')

from solve_lrr import solve_lrr

data = np.loadtxt('/tmp/data')
X = data.T
A = X
l = 0.1

Z, E = solve_lrr(X, A, l, reg=1, alm_type=1, display=True)

np.savetxt('/tmp/Z', Z)
np.savetxt('/tmp/E', E)