예제 #1
0
    def prox(self, w, index, factor=1.0, eps=consts.TOLERANCE, max_iter=100):
        """The proximal operator of the non-differentiable part of the
        function with the given index.

        From the interface "MultiblockProximalOperator".

        Parameters
        ----------
        w : list of numpy arrays
            The parameter vectors at which to compute the proximal operator.

        index : int
            Non-negative integer. The variable for which to compute the
            proximal operator.

        factor : float
            Positive float. A factor by which the Lagrange multiplier is
            scaled. This is usually the step size.
        """
        prox = self._p[index]
        proj = self._c[index]

        # We have no penalties with proximal operators and no constraints:
        if len(prox) == 0 and len(proj) == 0:
            prox_w = w[index]  # Do nothing!

        # There is one proximal operator and no constraints:
        elif len(prox) == 1 and len(proj) == 0:
            prox_w = prox[0].prox(w[index],
                                  factor=factor,
                                  eps=consts.TOLERANCE,
                                  max_iter=100)

        # There are two proximal operators, and no constraints:
        elif len(prox) == 2 and len(proj) == 0:
            from parsimony.algorithms.proximal import DykstrasProximalAlgorithm
            prox_combo = DykstrasProximalAlgorithm(eps=eps, max_iter=max_iter)

            prox_w = prox_combo.run(prox, w[index], factor=factor)

        # There are no proximal operators, but one or two constraints:
        elif len(prox) == 0 and (len(proj) == 1 or len(proj) == 2):
            prox_w = self.proj(w, index, eps=eps, max_iter=max_iter)

        # There are at least one proximal operator and at least one constraint:
        else:
            from parsimony.algorithms.proximal \
                import ParallelDykstrasProximalAlgorithm
            combo = ParallelDykstrasProximalAlgorithm(eps=eps,
                                                      max_iter=max_iter,
                                                      min_iter=1)
            prox_w = combo.run(w[index], prox=prox, proj=proj, factor=factor)

        return prox_w
예제 #2
0
    def prox(self, w, index, factor=1.0, eps=consts.TOLERANCE, max_iter=100):
        """The proximal operator of the non-differentiable part of the
        function with the given index.

        From the interface "MultiblockProximalOperator".

        Parameters
        ----------
        w : list of numpy arrays
            The parameter vectors at which to compute the proximal operator.

        index : int
            Non-negative integer. The variable for which to compute the
            proximal operator.

        factor : float
            Positive float. A factor by which the Lagrange multiplier is
            scaled. This is usually the step size.
        """
        prox = self._p[index]
        proj = self._c[index]

        # We have no penalties with proximal operators and no constraints:
        if len(prox) == 0 and len(proj) == 0:
            prox_w = w[index]  # Do nothing!

        # There is one proximal operator and no constraints:
        elif len(prox) == 1 and len(proj) == 0:
            prox_w = prox[0].prox(w[index], factor=factor,
                                  eps=consts.TOLERANCE, max_iter=100)

        # There are two proximal operators, and no constraints:
        elif len(prox) == 2 and len(proj) == 0:
            from parsimony.algorithms.proximal import DykstrasProximalAlgorithm
            prox_combo = DykstrasProximalAlgorithm(eps=eps, max_iter=max_iter)

            prox_w = prox_combo.run(prox, w[index], factor=factor)

        # There are no proximal operators, but one or two constraints:
        elif len(prox) == 0 and (len(proj) == 1 or len(proj) == 2):
            prox_w = self.proj(w, index, eps=eps, max_iter=max_iter)

        # There are at least one proximal operator and at least one constraint:
        else:
            from parsimony.algorithms.proximal \
                import ParallelDykstrasProximalAlgorithm
            combo = ParallelDykstrasProximalAlgorithm(eps=eps,
                                                      max_iter=max_iter,
                                                      min_iter=1)
            prox_w = combo.run(w[index], prox=prox, proj=proj, factor=factor)

        return prox_w
예제 #3
0
    def prox(self, w, index, factor=1.0, eps=consts.TOLERANCE, max_iter=100):
        """The proximal operator of the non-differentiable part of the
        function with the given index.

        From the interface "MultiblockProximalOperator".

        Parameters
        ----------
        w : List of numpy arrays. The weight vectors.

        index : Non-negative integer. Which variable the step is for.

        factor : Positive float. A factor by which the Lagrange multiplier is
                scaled. This is usually the step size.
        """
        prox = self._prox[index]
        proj = self._c[index]

        if len(prox) == 0 and len(proj) == 0:
            prox_w = w[index]

        elif len(prox) == 1 and len(proj) == 0:
            prox_w = prox[0].prox(w[index])

        elif len(prox) == 0 and (len(proj) == 1 or len(proj) == 2):
            prox_w = self.proj(w, index, eps=eps, max_iter=max_iter)

        else:
            from parsimony.algorithms.proximal \
                    import ParallelDykstrasProximalAlgorithm
            combo = ParallelDykstrasProximalAlgorithm(output=False,
                                                      eps=eps,
                                                      max_iter=max_iter,
                                                      min_iter=1)
            prox_w = combo.run(w[index], prox=prox, proj=proj, factor=factor)

        return prox_w
예제 #4
0
    def prox(self, w, index, factor=1.0, eps=consts.TOLERANCE, max_iter=100):
        """The proximal operator of the non-differentiable part of the
        function with the given index.

        From the interface "MultiblockProximalOperator".

        Parameters
        ----------
        w : List of numpy arrays. The weight vectors.

        index : Non-negative integer. Which variable the step is for.

        factor : Positive float. A factor by which the Lagrange multiplier is
                scaled. This is usually the step size.
        """
        prox = self._prox[index]
        proj = self._c[index]

        if len(prox) == 0 and len(proj) == 0:
            prox_w = w[index]

        elif len(prox) == 1 and len(proj) == 0:
            prox_w = prox[0].prox(w[index])

        elif len(prox) == 0 and (len(proj) == 1 or len(proj) == 2):
            prox_w = self.proj(w, index, eps=eps, max_iter=max_iter)

        else:
            from parsimony.algorithms.proximal \
                import ParallelDykstrasProximalAlgorithm
            combo = ParallelDykstrasProximalAlgorithm(eps=eps,
                                                      max_iter=max_iter,
                                                      min_iter=1)
            prox_w = combo.run(w[index], prox=prox, proj=proj, factor=factor)

        return prox_w