def proj_l2(v, gamma, axis=None): r"""Projection operator of the :math:`\ell_2` norm. The projection operator of the uncentered :math:`\ell_2` norm, .. math:: \mathrm{argmin}_{\mathbf{x}} (1/2) \| \mathbf{x} - \mathbf{v} \|_2^2 \; \text{ s.t. } \; \| \mathbf{x} - \mathbf{s} \|_2 \leq \gamma can be computed as :math:`\mathbf{s} + \mathrm{proj}_{f,\gamma} (\mathbf{v} - \mathbf{s})` where :math:`f(\mathbf{x}) = \| \mathbf{x} \|_2`. Parameters ---------- v : array_like Input array :math:`\mathbf{v}` gamma : float Parameter :math:`\gamma` axis : None or int or tuple of ints, optional (default None) Axes of `v` over which to compute the :math:`\ell_2` norm. If `None`, an entire multi-dimensional array is treated as a vector. If axes are specified, then distinct norm values are computed over the indices of the remaining axes of input array `v`. Returns ------- x : ndarray Output array """ d = np.sqrt(np.sum(v**2, axis=axis, keepdims=True)) return (d <= gamma)*v + (d > gamma)*(gamma*sl.zdivide(v, d))
def uinit(self, ushape): """Return initialiser for working variable U.""" if self.opt['Y0'] is None: return np.zeros(ushape, dtype=self.dtype) else: # If initial Y is non-zero, initial U is chosen so that # the relevant dual optimality criterion (see (3.10) in # boyd-2010-distributed) is satisfied. Yss = np.sqrt(np.sum(self.Y**2, axis=self.S.ndim, keepdims=True)) return (self.lmbda/self.rho)*sl.zdivide(self.Y, Yss)
def prox_l2(v, alpha, axis=None): r"""Compute the proximal operator of the :math:`\ell_2` norm (vector shrinkage/soft thresholding) .. math:: \mathrm{prox}_{\alpha f}(\mathbf{v}) = \mathcal{S}_{2,\alpha} (\mathbf{v}) = \frac{\mathbf{v}} {\|\mathbf{v}\|_2} \max(0, \|\mathbf{v}\|_2 - \alpha) \;, where :math:`f(\mathbf{x}) = \|\mathbf{x}\|_2`. Parameters ---------- v : array_like Input array :math:`\mathbf{v}` alpha : float or array_like Parameter :math:`\alpha` axis : None or int or tuple of ints, optional (default None) Axes of `v` over which to compute the :math:`\ell_2` norm. If `None`, an entire multi-dimensional array is treated as a vector. If axes are specified, then distinct norm values are computed over the indices of the remaining axes of input array `v`, which is equivalent to the proximal operator of the sum over these values (i.e. an :math:`\ell_{2,1}` norm). Returns ------- x : ndarray Output array """ a = np.sqrt(np.sum(v**2, axis=axis, keepdims=True)) b = np.maximum(0, a - alpha) b = sl.zdivide(b, a) return np.asarray(b * v, dtype=v.dtype)
def proj_l2(v, gamma, axis=None): r"""Compute the projection operator of the :math:`\ell_2` norm. The projection operator of the uncentered :math:`\ell_2` norm, .. math:: \mathrm{argmin}_{\mathbf{x}} (1/2) \| \mathbf{x} - \mathbf{v} \|_2^2 \; \text{ s.t. } \; \| \mathbf{x} - \mathbf{s} \|_2 \leq \gamma can be computed as :math:`\mathbf{s} + \mathrm{proj}_{f,\gamma} (\mathbf{v} - \mathbf{s})` where :math:`f(\mathbf{x}) = \| \mathbf{x} \|_2`. Parameters ---------- v : array_like Input array :math:`\mathbf{v}` gamma : float Parameter :math:`\gamma` axis : None or int or tuple of ints, optional (default None) Axes of `v` over which to compute the :math:`\ell_2` norm. If `None`, an entire multi-dimensional array is treated as a vector. If axes are specified, then distinct norm values are computed over the indices of the remaining axes of input array `v`. Returns ------- x : ndarray Output array """ d = np.sqrt(np.sum(v**2, axis=axis, keepdims=True)) return np.asarray((d <= gamma) * v + (d > gamma) * (gamma * sl.zdivide(v, d)), dtype=v.dtype)