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)*zdivide(self.Y, Yss)
def proj_l2(v, gamma, axis=None): r"""Compute the projection operator of the :math:`\ell_2` norm .. math:: \mathrm{proj}_{f, \gamma}(\mathbf{v}) = \mathrm{argmin}_{\mathbf{x}} (1/2) \| \mathbf{x} - \mathbf{v} \|_2^2 \; \text{ s.t. } \; \| \mathbf{x} \|_2 \leq \gamma \;, where :math:`f(\mathbf{x}) = \|\mathbf{x}\|_2`. Note that the projection operator of the :math:`\ell_2` norm centered at :math:`\mathbf{s}`, .. 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})`. 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 """ if np.isrealobj(v): d = np.sqrt(np.sum(v**2, axis=axis, keepdims=True)) else: d = np.sqrt(np.sum(np.abs(v)**2, axis=axis, keepdims=True)) return np.asarray((d <= gamma) * v + (d > gamma) * (gamma * zdivide(v, d)), dtype=v.dtype)
def proj_l2ball(b, s, r, axes=None): r"""Projection onto the :math:`\ell_2` ball. Project :math:`\mathbf{b}` onto the :math:`\ell_2` ball of radius :math:`r` about :math:`\mathbf{s}`, i.e. :math:`\{ \mathbf{x} : \|\mathbf{x} - \mathbf{s} \|_2 \leq r \}`. Note that ``proj_l2ball(b, s, r)`` is equivalent to :func:`.prox.proj_l2` ``(b - s, r) + s``. **NB**: This function is to be deprecated; please use :func:`.prox.proj_l2` instead (see note above about interface differences). Parameters ---------- b : array_like Vector :math:`\mathbf{b}` to be projected s : array_like Centre of :math:`\ell_2` ball :math:`\mathbf{s}` r : float Radius of ball axes : sequence of ints, optional (default all axes) Axes over which to compute :math:`\ell_2` norms Returns ------- x : ndarray Projection of :math:`\mathbf{b}` into ball """ wstr = "Function sporco.linalg.proj_l2ball is deprecated; please " \ "use sporco.prox.proj_l2 (noting the interface difference) " \ "instead." warnings.simplefilter('always', DeprecationWarning) warnings.warn(wstr, DeprecationWarning, stacklevel=2) warnings.simplefilter('default', DeprecationWarning) d = np.sqrt(np.sum((b - s)**2, axis=axes, keepdims=True)) p = zdivide(b - s, d) return np.asarray((d <= r) * b + (d > r) * (s + r * p), b.dtype)
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 """ if np.isrealobj(v): a = np.sqrt(np.sum(v**2, axis=axis, keepdims=True)) else: a = np.sqrt(np.sum(np.abs(v)**2, axis=axis, keepdims=True)) b = np.maximum(0, a - alpha) b = zdivide(b, a) return np.asarray(b * v, dtype=v.dtype)