def test_proximal_method():

    X = np.random.standard_normal((100, 50))
    X[:, :7] *= 5

    qX = identity_quadratic(1, X, 0, 0)
    P = FM.nuclear_norm(X.shape, lagrange=1)
    RP = todense(P.proximal(qX))

    B = FM.nuclear_norm(X.shape, bound=1)
    RB = todense(B.proximal(qX))

    BO = FM.operator_norm(X.shape, bound=1)
    PO = FM.operator_norm(X.shape, lagrange=1)

    RPO = todense(PO.proximal(qX))
    RBO = todense(BO.proximal(qX))

    D = np.linalg.svd(X, full_matrices=0)[1]
    lD = np.linalg.svd(RP, full_matrices=0)[1]
    lagrange_rank = (lD > 1.e-10).sum()
    all_close(lD[:lagrange_rank] + P.lagrange, D[:lagrange_rank],
              'proximal method lagrange', None)

    bD = np.linalg.svd(RB, full_matrices=0)[1]
    bound_rank = (bD > 1.e-10).sum()

    all_close(bD[:bound_rank],
              projl1(D, B.bound)[:bound_rank], 'proximal method bound', None)

    nt.assert_true(np.linalg.norm(RPO + RB - X) / np.linalg.norm(X) < 0.01)
    nt.assert_true(np.linalg.norm(RBO + RP - X) / np.linalg.norm(X) < 0.01)
Esempio n. 2
0
def test_proximal_method():

    X = np.random.standard_normal((100, 50))
    X[:,:7] *= 5

    qX = identity_quadratic(1,X,0,0)
    P = FM.nuclear_norm(X.shape, lagrange=1)
    RP = todense(P.proximal(qX))

    B = FM.nuclear_norm(X.shape, bound=1)
    RB = todense(B.proximal(qX))

    BO = FM.operator_norm(X.shape, bound=1)
    PO = FM.operator_norm(X.shape, lagrange=1)

    RPO = todense(PO.proximal(qX))
    RBO = todense(BO.proximal(qX))

    D = np.linalg.svd(X, full_matrices=0)[1]
    lD = np.linalg.svd(RP, full_matrices=0)[1]
    lagrange_rank = (lD > 1.e-10).sum()
    all_close(lD[:lagrange_rank] + P.lagrange, D[:lagrange_rank], 'proximal method lagrange', None)

    bD = np.linalg.svd(RB, full_matrices=0)[1]
    bound_rank = (bD > 1.e-10).sum()

    all_close(bD[:bound_rank], projl1(D, B.bound)[:bound_rank], 'proximal method bound', None)

    nt.assert_true(np.linalg.norm(RPO+RB-X) / np.linalg.norm(X) < 0.01)
    nt.assert_true(np.linalg.norm(RBO+RP-X) / np.linalg.norm(X) < 0.01)
def test_proximal_maps():

    X = np.random.standard_normal((100, 50))
    X[:, :7] *= 5

    P = FM.nuclear_norm(X.shape, lagrange=1)
    RP = todense(P.lagrange_prox(X))

    B = FM.nuclear_norm(X.shape, bound=1)
    RB = todense(B.bound_prox(X))

    BO = FM.operator_norm(X.shape, bound=1)
    PO = FM.operator_norm(X.shape, lagrange=1)

    RPO = todense(PO.lagrange_prox(X))
    RBO = todense(BO.bound_prox(X))

    D = np.linalg.svd(X, full_matrices=0)[1]
    lD = np.linalg.svd(RP, full_matrices=0)[1]
    lagrange_rank = (lD > 1.e-10).sum()
    all_close(lD[:lagrange_rank] + P.lagrange, D[:lagrange_rank],
              'proximal lagrange', None)

    bD = np.linalg.svd(RB, full_matrices=0)[1]
    bound_rank = (bD > 1.e-10).sum()

    all_close(bD[:bound_rank],
              projl1(D, B.bound)[:bound_rank], 'proximal bound', None)

    nt.assert_true(np.linalg.norm(RPO + RB - X) / np.linalg.norm(X) < 0.01)
    nt.assert_true(np.linalg.norm(RBO + RP - X) / np.linalg.norm(X) < 0.01)

    # running code to ensure it is tested

    P.conjugate
    P.quadratic = identity_quadratic(1, 0, 0, 0)
    P.conjugate

    BO.conjugate
    BO.quadratic = identity_quadratic(1, 0, 0, 0)
    BO.conjugate

    B.conjugate
    B.quadratic = identity_quadratic(1, 0, 0, 0)
    B.conjugate

    PO.conjugate
    PO.quadratic = identity_quadratic(1, 0, 0, 0)
    PO.conjugate
Esempio n. 4
0
def test_proximal_maps():

    X = np.random.standard_normal((100, 50))
    X[:,:7] *= 5

    P = FM.nuclear_norm(X.shape, lagrange=1)
    RP = todense(P.lagrange_prox(X))

    B = FM.nuclear_norm(X.shape, bound=1)
    RB = todense(B.bound_prox(X))

    BO = FM.operator_norm(X.shape, bound=1)
    PO = FM.operator_norm(X.shape, lagrange=1)

    RPO = todense(PO.lagrange_prox(X))
    RBO = todense(BO.bound_prox(X))

    D = np.linalg.svd(X, full_matrices=0)[1]
    lD = np.linalg.svd(RP, full_matrices=0)[1]
    lagrange_rank = (lD > 1.e-10).sum()
    all_close(lD[:lagrange_rank] + P.lagrange, D[:lagrange_rank], 'proximal lagrange', None)

    bD = np.linalg.svd(RB, full_matrices=0)[1]
    bound_rank = (bD > 1.e-10).sum()

    all_close(bD[:bound_rank], projl1(D, B.bound)[:bound_rank], 'proximal bound', None)

    nt.assert_true(np.linalg.norm(RPO+RB-X) / np.linalg.norm(X) < 0.01)
    nt.assert_true(np.linalg.norm(RBO+RP-X) / np.linalg.norm(X) < 0.01)

    # running code to ensure it is tested

    P.conjugate
    P.quadratic = identity_quadratic(1, 0, 0, 0)
    P.conjugate

    BO.conjugate
    BO.quadratic = identity_quadratic(1, 0, 0, 0)
    BO.conjugate

    B.conjugate
    B.quadratic = identity_quadratic(1, 0, 0, 0)
    B.conjugate

    PO.conjugate
    PO.quadratic = identity_quadratic(1, 0, 0, 0)
    PO.conjugate