コード例 #1
0
ファイル: test_weighted_atoms.py プロジェクト: sroet/regreg
def test_proximal_maps():
    shape = 20

    bound = 0.14
    lagrange = 0.13

    Z = np.random.standard_normal(shape) * 2
    W = 0.02 * np.random.standard_normal(shape)
    U = 0.02 * np.random.standard_normal(shape)
    linq = rr.identity_quadratic(0, 0, W, 0)

    basis = np.linalg.svd(np.random.standard_normal((4, 20)),
                          full_matrices=0)[2]

    w1 = np.ones(20) * 0.5
    w2 = w1 * 0
    w2[:10] = 2.

    for L, atom, q, offset, FISTA, coef_stop, w in itertools.product(
        [0.5, 1, 0.1], sorted(WA.conjugate_weighted_pairs.keys()),
        [None, linq], [None, U], [False, True], [False, True], [w1, w2]):

        # we only have two weighted atoms,
        # l1 in lagrange and supnorm in bound

        print 'w: ', w.shape
        if atom == WA.l1norm:
            p = atom(shape, w, quadratic=q, offset=offset, lagrange=lagrange)
        else:
            p = atom(shape, w, quadratic=q, offset=offset, bound=bound)

        for t in solveit(p, Z, W, U, linq, L, FISTA, coef_stop):
            yield t
コード例 #2
0
ファイル: test_block_norms.py プロジェクト: amitibo/regreg
def test_proximal_maps():
    shape = (5,4)

    bound = 0.14
    lagrange = 0.13


    Z = np.random.standard_normal(shape) * 2
    W = 0.02 * np.random.standard_normal(shape)
    U = 0.02 * np.random.standard_normal(shape)
    linq = rr.identity_quadratic(0,0,W,0)

    basis = np.linalg.svd(np.random.standard_normal((4,20)), full_matrices=0)[2]

    for L, atom, q, offset, FISTA, coef_stop in itertools.product([0.5,1,0.1], 
                                                       sorted(B.conjugate_block_pairs.keys()),
                                              [None, linq],
                                              [None, U],
                                              [False, True],
                                              [False, True]):

        if atom not in [B.block_max, B.block_sum]:
            p = atom(shape, quadratic=q, lagrange=lagrange,
                       offset=offset)
            d = p.conjugate 
            yield ac, p.lagrange_prox(Z, lipschitz=L), Z-d.bound_prox(Z*L, lipschitz=1./L)/L, 'testing lagrange_prox and bound_prox starting from atom %s ' % atom

            # some arguments of the constructor

            nt.assert_raises(AttributeError, setattr, p, 'bound', 4.)
            nt.assert_raises(AttributeError, setattr, d, 'lagrange', 4.)

            nt.assert_raises(AttributeError, setattr, p, 'bound', 4.)
            nt.assert_raises(AttributeError, setattr, d, 'lagrange', 4.)

            for t in solveit(p, Z, W, U, linq, L, FISTA, coef_stop):
                yield t

            b = atom(shape, bound=bound, quadratic=q,
                     offset=offset)

            for t in solveit(b, Z, W, U, linq, L, FISTA, coef_stop):
                yield t
コード例 #3
0
ファイル: test_svd_norms.py プロジェクト: sroet/regreg
def test_proximal_maps():
    shape = (5, 4)

    bound = 0.14
    lagrange = 0.13

    Z = np.random.standard_normal(shape) * 2
    W = 0.02 * np.random.standard_normal(shape)
    U = 0.02 * np.random.standard_normal(shape)
    linq = rr.identity_quadratic(0, 0, W, 0)

    basis = np.linalg.svd(np.random.standard_normal((4, 20)),
                          full_matrices=0)[2]

    for L, atom, q, offset, FISTA, coef_stop in itertools.product(
        [0.5, 1, 0.1], sorted(S.conjugate_svd_pairs.keys()), [None, linq],
        [None, U], [False, True], [False, True]):

        p = atom(shape, quadratic=q, lagrange=lagrange, offset=offset)
        d = p.conjugate
        yield ac, p.lagrange_prox(Z, lipschitz=L), Z - d.bound_prox(
            Z * L, lipschitz=1. / L
        ) / L, 'testing lagrange_prox and bound_prox starting from atom %s ' % atom

        # some arguments of the constructor

        nt.assert_raises(AttributeError, setattr, p, 'bound', 4.)
        nt.assert_raises(AttributeError, setattr, d, 'lagrange', 4.)

        nt.assert_raises(AttributeError, setattr, p, 'bound', 4.)
        nt.assert_raises(AttributeError, setattr, d, 'lagrange', 4.)

        for t in solveit(p, Z, W, U, linq, L, FISTA, coef_stop):
            yield t

        b = atom(shape, bound=bound, quadratic=q, offset=offset)

        for t in solveit(b, Z, W, U, linq, L, FISTA, coef_stop):
            yield t
コード例 #4
0
ファイル: test_cones.py プロジェクト: sroet/regreg
def test_proximal_maps():
    shape = 20

    Z = np.random.standard_normal(shape) * 2
    W = 0.02 * np.random.standard_normal(shape)
    U = 0.02 * np.random.standard_normal(shape)
    linq = rr.identity_quadratic(0, 0, W, 0)

    for L, atom, q, offset, FISTA, coef_stop in itertools.product(
        [0.5, 1, 0.1], sorted(C.conjugate_cone_pairs.keys()), [None, linq],
        [None, U], [False, True], [False, True]):

        p = atom(shape, quadratic=q, offset=offset)

        for t in solveit(p, Z, W, U, linq, L, FISTA, coef_stop):
            yield t
コード例 #5
0
def test_proximal_maps():
    shape = 20

    Z = np.random.standard_normal(shape) * 2
    W = 0.02 * np.random.standard_normal(shape)
    U = 0.02 * np.random.standard_normal(shape)
    linq = rr.identity_quadratic(0, 0, W, 0)

    basis = np.linalg.svd(np.random.standard_normal((4, 20)), full_matrices=0)[2]

    for L, atom, q, offset, FISTA, coef_stop in itertools.product(
        [0.5, 1, 0.1], sorted(LC.conjugate_cone_pairs.keys()), [None, linq], [None, U], [False, True], [False, True]
    ):

        p = atom(shape, basis, quadratic=q, offset=offset)

        for t in solveit(p, Z, W, U, linq, L, FISTA, coef_stop):
            yield t
コード例 #6
0
ファイル: test_cones.py プロジェクト: gmelikian/regreg
def test_proximal_maps():
    shape = 20

    Z = np.random.standard_normal(shape) * 2
    W = 0.02 * np.random.standard_normal(shape)
    U = 0.02 * np.random.standard_normal(shape)
    linq = rr.identity_quadratic(0,0,W,0)

    for L, atom, q, offset, FISTA, coef_stop in itertools.product( 
        [0.5,1,0.1], 
        [C.l2_epigraph, C.l2_epigraph_polar],#sorted(C.conjugate_cone_pairs.keys()),
        [None, linq],
        [None, U],
        [False, True],
        [False, True]):

        p = atom(shape, quadratic=q,
                   offset=offset)

        for t in solveit(p, Z, W, U, linq, L, FISTA, coef_stop):
            yield t
コード例 #7
0
ファイル: test_weighted_atoms.py プロジェクト: amitibo/regreg
def test_proximal_maps():
    shape = 20

    bound = 0.14
    lagrange = 0.13

    Z = np.random.standard_normal(shape) * 2
    W = 0.02 * np.random.standard_normal(shape)
    U = 0.02 * np.random.standard_normal(shape)
    linq = rr.identity_quadratic(0,0,W,0)

    basis = np.linalg.svd(np.random.standard_normal((4,20)), full_matrices=0)[2]

    w1 = np.ones(20) * 0.5
    w2 = w1 * 0
    w2[:10] = 2.

    for L, atom, q, offset, FISTA, coef_stop, w in itertools.product([0.5,1,0.1], 
                                               sorted(WA.conjugate_weighted_pairs.keys()),
                                              [None, linq],
                                              [None, U],
                                              [False, True],
                                              [False, True],
                                              [w1, w2]):

        # we only have two weighted atoms,
        # l1 in lagrange and supnorm in bound

        print 'w: ', w.shape
        if atom == WA.l1norm:
            p = atom(shape, w, quadratic=q,
                     offset=offset, lagrange=lagrange)
        else:
            p = atom(shape, w, quadratic=q,
                     offset=offset, bound=bound)
            
        for t in solveit(p, Z, W, U, linq, L, FISTA, coef_stop):
            yield t