Beispiel #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_convex_conj_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)
Beispiel #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_convex_conj_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)
Beispiel #3
0
def test_proximal_convconj_l1_simple_space_without_data():
    """Proximal factory for the convex conjugate of the L1-norm."""

    # Image space
    space = odl.uniform_discr(0, 1, 10)

    # Image element
    x_arr = np.arange(-5, 5)
    x = space.element(x_arr)

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

    # 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
    # Explicit computation: x / max(lam, |x|)
    denom = np.maximum(lam, np.sqrt(x_arr**2))
    x_exact = lam * x_arr / denom

    # Using out
    x_opt = space.element()
    x_result = prox(x, x_opt)
    assert x_result is x_opt
    assert all_almost_equal(x_opt, x_exact, HIGH_ACC)

    # Without out
    x_result = prox(x)
    assert all_almost_equal(x_result, x_exact, HIGH_ACC)

    # With aliased out
    x_result = prox(x, x)
    assert all_almost_equal(x_result, x_exact, HIGH_ACC)