Beispiel #1
0
def test_proximal_composition(pos_scalar, sigma):
    """Test for proximal of composition with semi-orthogonal linear operator.

    This test is for ``prox[f * L](x)``, where ``L`` is a linear operator such
    that ``L * L.adjoint = mu * IdentityOperator``. Specifically, ``L`` is
    taken to be ``scal * IdentityOperator``, since this is equivalent to
    scaling of the argument.
    """
    sigma = float(sigma)
    space = odl.uniform_discr(0, 1, 10)
    prox_factory = proximal_l2_squared(space)

    # The semi-orthogonal linear operator
    scal = pos_scalar
    L = odl.ScalingOperator(space, scal)
    mu = scal ** 2  # L = scal * I => L * L.adjoint = scal ** 2 * I
    prox_factory_composition = proximal_composition(prox_factory, L, mu)
    prox = prox_factory_composition(sigma)

    assert isinstance(prox, odl.Operator)

    x = space.element(np.arange(-5, 5))
    prox_x = prox(x)
    equiv_prox = proximal_arg_scaling(prox_factory, scal)(sigma)
    expected_result = equiv_prox(x)
    assert all_almost_equal(prox_x, expected_result, places=PLACES)
def test_proximal_composition(pos_scalar, sigma):
    """Test for proximal of composition with semi-orthogonal linear operator.

    This test is for ``prox[f * L](x)``, where ``L`` is a linear operator such
    that ``L * L.adjoint = mu * IdentityOperator``. Specifically, ``L`` is
    taken to be ``scal * IdentityOperator``, since this is equivalent to
    scaling of the argument.
    """
    sigma = float(sigma)
    space = odl.uniform_discr(0, 1, 10)
    prox_factory = proximal_l2_squared(space)

    # The semi-orthogonal linear operator
    scal = pos_scalar
    L = odl.ScalingOperator(space, scal)
    mu = scal ** 2  # L = scal * I => L * L.adjoint = scal ** 2 * I
    prox_factory_composition = proximal_composition(prox_factory, L, mu)
    prox = prox_factory_composition(sigma)

    assert isinstance(prox, odl.Operator)

    x = space.element(np.arange(-5, 5))
    prox_x = prox(x)
    equiv_prox = proximal_arg_scaling(prox_factory, scal)(sigma)
    expected_result = equiv_prox(x)
    assert all_almost_equal(prox_x, expected_result, places=PLACES)
Beispiel #3
0
def test_proximal_arg_scaling(scalar, sigma):
    """Test for the proximal of scaling: ``prox[F(. * a)]``."""
    sigma = float(sigma)
    space = odl.uniform_discr(0, 1, 10)
    lam = 1.2
    prox_factory = proximal_l2_squared(space, lam=lam)

    scaling_param = scalar
    prox = proximal_arg_scaling(prox_factory, scaling_param)(sigma)

    x = noise_element(space)
    # works for scaling_param == 0, too
    expected_result = x / (2 * sigma * lam * scaling_param ** 2 + 1)

    assert all_almost_equal(prox(x), expected_result, places=PLACES)
def test_proximal_arg_scaling(scalar, sigma):
    """Test for the proximal of scaling: ``prox[F(. * a)]``."""
    sigma = float(sigma)
    space = odl.uniform_discr(0, 1, 10)
    lam = 1.2
    prox_factory = proximal_l2_squared(space, lam=lam)

    scaling_param = scalar
    prox = proximal_arg_scaling(prox_factory, scaling_param)(sigma)

    x = noise_element(space)
    # works for scaling_param == 0, too
    expected_result = x / (2 * sigma * lam * scaling_param ** 2 + 1)

    assert all_almost_equal(prox(x), expected_result, places=PLACES)