def proximal_huber(space, gamma):
    """Proximal factory of the Huber norm.

    Parameters
    ----------
    space : `TensorSpace`
        The domain of the functional
    gamma : float
        The smoothing parameter of the Huber norm functional.

    Returns
    -------
    prox_factory : function
        Factory for the proximal operator to be initialized.

    See Also
    --------
    odl.solvers.default_functionals.Huber : the Huber norm functional

    Notes
    -----
    The proximal operator is given by given by the proximal operator of
    ``1/(2*gamma) * L2 norm`` in points that are ``<= gamma``, and by the
    proximal operator of the l1 norm in points that are ``> gamma``.
    """

    gamma = float(gamma)

    class ProximalHuber(Operator):

        """Proximal operator of Huber norm."""

        def __init__(self, sigma):
            """Initialize a new instance.

            Parameters
            ----------
            sigma : positive float
            """
            self.sigma = float(sigma)
            super(ProximalHuber, self).__init__(domain=space, range=space,
                                                linear=False)

        def _call(self, x, out):
            """Return ``self(x, out=out)``."""
            if isinstance(self.domain, ProductSpace):
                norm = PointwiseNorm(self.domain, 2)(x)
            else:
                norm = x.ufuncs.absolute()

            mask = norm.ufuncs.less_equal(gamma + self.sigma)
            out[mask] = gamma / (gamma + self.sigma) * x[mask]

            mask.ufuncs.logical_not(out=mask)
            sign_x = x.ufuncs.sign()
            out[mask] = x[mask] - self.sigma * sign_x[mask]

            return out

    return ProximalHuber
def proximal_huber ( space , gamma ) : gamma = float ( gamma ) class ProximalHuber ( Operator ) : def __init__ ( self , sigma ) : self . sigma = float ( sigma ) super ( ProximalHuber , self ) . __init__ ( domain = space , range = space , linear = False ) def _call ( self , x , out ) : if isinstance ( self . domain , ProductSpace ) : norm = PointwiseNorm ( self . domain , 2 ) ( x ) else : norm = x . ufuncs . absolute ( ) mask = norm . ufuncs . less_equal ( gamma + self . sigma ) out [ mask ] = gamma / ( gamma + self . sigma ) * x [ mask ] mask . ufuncs . logical_not ( out = mask ) sign_x = x . ufuncs . sign ( ) out [ mask ] = x [ mask ] - self . sigma * sign_x [ mask ] return out return ProximalHuber
Proximal factory of the Huber norm.

    Parameters
    ----------
    space : `TensorSpace`
        The domain of the functional
    gamma : float
        The smoothing parameter of the Huber norm functional.

    Returns
    -------
    prox_factory : function
        Factory for the proximal operator to be initialized.

    See Also
    --------
    odl.solvers.default_functionals.Huber : the Huber norm functional

    Notes
    -----
    The proximal operator is given by given by the proximal operator of
    ``1/(2*gamma) * L2 norm`` in points that are ``<= gamma``, and by the
    proximal operator of the l1 norm in points that are ``> gamma``.