Пример #1
0
    def proximal(self, x, penalty=1):

        x = self.dom.check_input(x)
        n = utils.norm(x)

        if n <= self.threshold * (penalty + 1): return x / (penalty + 1)
        else: return (1 - penalty * self.threshold / n) * x
Пример #2
0
    def __init__(self, a, b):
        """
        Class constructor.

        Parameters
        ----------
        a : array_like
            The vector :math:`a` defining the half-space.
        b : float
            The scalar :math:`b` defining the half-space.
        
        Raises
        ------
        ValueError.
        
        Notes
        -----
        The vector `a` is normalized to a unit vector, hence `b` is divided
        by the norm of `a`.
        """

        a = np.reshape(a, (-1, 1))  # reshape to column vector
        super().__init__(a.size, 1)

        if not np.isscalar(b):
            raise ValueError("Coefficient `b` must be a scalar.")

        # store arguments
        norm_a = utils.norm(a)
        self.a, self.b = a / norm_a, b / norm_a
Пример #3
0
    def gradient(self, x):

        x = self.dom.check_input(x)
        n = utils.norm(x)

        if n <= self.threshold: return x
        else: return self.threshold * x / n
Пример #4
0
    def function(self, x):

        x = self.dom.check_input(x)
        n = utils.norm(x)

        if n <= self.threshold: return n**2 / 2
        else: return self.threshold * (n - self.threshold / 2)
Пример #5
0
    def gradient(self, x):

        x = float(x)
        n = utils.norm(x)

        if n <= self.threshold: return x
        else: return self.threshold * x / n
Пример #6
0
    def __init__(self, A, b):
        """
        Class constructor.
        
        If :math:`m = 1` then the space is an hyper-plane and a closed form
        projection is available. Otherwise, the projection employes a
        pseudo-inverse computation for projecting.

        Parameters
        ----------
        A : array_like
            The constraint matrix.
        b : array_like
            The constraint vector.

        Notes
        -----
        If it is an hyperplane, `A` is normalized to a unit vector, hence `b` 
        is divided by the norm of `A`.
        """

        b = np.reshape(b, (-1, 1))

        if b.size != A.shape[0]:
            raise ValueError("Incompatible shapes of `A` and `b`.")
        super().__init__(A.shape[1], 1)

        # store arguments
        self.A, self.b = A, b
        self.hyperplane = A.shape[0] == 1

        if self.hyperplane:
            norm_A = utils.norm(A)
            self.A, self.b = A / norm_A, b / norm_A
        else:
            self.A_pinv = la.pinv(self.A)
Пример #7
0
    def contains(self, x):

        x = self.check_input(x)

        return utils.norm(x - self.center) <= self.radius
Пример #8
0
    def hessian(self, x):

        x = self.dom.check_input(x)

        if utils.norm(x) <= self.threshold: return np.eye(self.dom.size)
        else: return np.zeros((self.dom.size, self.dom.size))
Пример #9
0
    def contains(self, x):

        x = self.check_input(x)

        return abs(utils.norm(x - self.center) - self.radius) <= _eps