Exemple #1
0
def test_proximal_convconj_l1_simple_space_with_data():
    """Proximal factory for the convex conjugate of the L1-norm."""

    # Image space
    space = odl.uniform_discr(0, 1, 10)
    x_arr = np.arange(-5, 5)
    x = space.element(x_arr)

    # RHS data
    g_arr = np.arange(10, 0, -1)
    g = space.element(g_arr)

    # Factory function returning the proximal operator
    lam = 2
    prox_factory = proximal_cconj_l1(space, lam=lam, g=g)

    # Initialize the proximal operator of F^*
    sigma = 0.25
    prox = prox_factory(sigma)

    assert isinstance(prox, odl.Operator)

    # Apply the proximal operator returning its optimal point
    x_opt = space.element()
    prox(x, x_opt)

    # Explicit computation: (x - sigma * g) / max(lam, |x - sigma * g|)
    denom = np.maximum(lam, np.abs(x_arr - sigma * g_arr))
    x0_verify = lam * (x_arr - sigma * g_arr) / denom

    assert all_almost_equal(x_opt, x0_verify, HIGH_ACC)
Exemple #2
0
def test_proximal_convconj_l1_product_space():
    """Proximal factory for the convex conjugate of the L1-norm using
    product spaces."""

    # Product space for matrix of operators
    op_domain = odl.ProductSpace(odl.uniform_discr(0, 1, 10), 2)

    # Element in the product space where the proximal operator is evaluated
    x0_arr = np.arange(-5, 5)
    x1_arr = np.arange(10, 0, -1)
    x = op_domain.element([x0_arr, x1_arr])

    # Create a data element in the product space
    g0_arr = x1_arr.copy()
    g1_arr = x0_arr.copy()
    g = op_domain.element([g0_arr, g1_arr])

    # Factory function returning the proximal operator
    lam = 2
    prox_factory = proximal_cconj_l1(op_domain, lam=lam, g=g, isotropic=True)

    # Initialize the proximal operator
    sigma = 0.25
    prox = prox_factory(sigma)

    assert isinstance(prox, odl.Operator)

    # Apply the proximal operator returning its optimal point
    x_opt = prox(x)

    # Explicit computation: (x - sigma * g) / max(lam, |x - sigma * g|)
    denom = np.maximum(lam,
                       np.sqrt((x0_arr - sigma * g0_arr) ** 2 +
                               (x1_arr - sigma * g1_arr) ** 2))
    x_verify = lam * (x - sigma * g) / denom

    # Compare components
    assert all_almost_equal(x_verify, x_opt)