コード例 #1
0
ファイル: container.py プロジェクト: sowuy/regreg
    def conjugate_problem(self, conj=None, initial=None, smooth_multiplier=1.):
        """
        Create a problem object for solving the conjugate problem
        """

        if conj is not None:
            self.conjugate = conj
        if not hasattr(self, 'conjugate'):
            #If the conjugate of the loss function is not provided use the generic solver
            self.conjugate = conjugate(self.loss)

        prox = self.dual_prox
        nonsmooth = self.evaluate_dual_atoms

        if initial is None:
            z = np.zeros((), self.dual_dtype)
            for segment in self.dual_segments:
                z[segment] += np.random.standard_normal(z[segment].shape)

            # XXX dtype manipulations -- would be nice not to have to do this
            z = z.reshape((1, )).view(np.float)
            initial = self.dual_prox(z, 1.)

        return dummy_problem(self.conjugate_smooth_eval, nonsmooth, prox,
                             initial, smooth_multiplier)
コード例 #2
0
ファイル: atoms.py プロジェクト: fperez/regreg
 def dual_problem(self, smooth_func, smooth_multiplier=1., initial=None):
     """
     Return a problem instance 
     """
     prox = self.dual_prox
     nonsmooth = self.evaluate_dual_constraint
     if initial is None:
         initial = np.random.standard_normal(self.p)
     return dummy_problem(smooth_func, nonsmooth, prox, initial, smooth_multiplier)
コード例 #3
0
ファイル: atoms.py プロジェクト: sowuy/regreg
 def dual_problem(self, smooth_func, smooth_multiplier=1., initial=None):
     """
     Return a problem instance 
     """
     prox = self.dual_prox
     nonsmooth = self.evaluate_dual_constraint
     if initial is None:
         initial = np.random.standard_normal(self.p)
     return dummy_problem(smooth_func, nonsmooth, prox, initial,
                          smooth_multiplier)
コード例 #4
0
ファイル: container.py プロジェクト: fperez/regreg
    def problem(self, smooth_multiplier=1., initial=None):
        """
        Create a problem object for solving the general problem with the two-loop algorithm
        """

        prox = self.primal_prox
        nonsmooth = self.evaluate_primal_atoms
        if initial is None:
            initial = np.random.standard_normal(self.primal_shape)
            initial = initial/np.linalg.norm(initial)
        if nonsmooth(initial) + self.loss.smooth_eval(initial,mode='func') == np.inf:
            raise ValueError('initial point is not feasible')
        
        return dummy_problem(self.loss.smooth_eval, nonsmooth, prox, initial, smooth_multiplier)
コード例 #5
0
ファイル: container.py プロジェクト: sowuy/regreg
    def problem(self, smooth_multiplier=1., initial=None):
        """
        Create a problem object for solving the general problem with the two-loop algorithm
        """

        prox = self.primal_prox
        nonsmooth = self.evaluate_primal_atoms
        if initial is None:
            initial = np.random.standard_normal(self.primal_shape)
            initial = initial / np.linalg.norm(initial)
        if nonsmooth(initial) + self.loss.smooth_eval(initial,
                                                      mode='func') == np.inf:
            raise ValueError('initial point is not feasible')

        return dummy_problem(self.loss.smooth_eval, nonsmooth, prox, initial,
                             smooth_multiplier)
コード例 #6
0
ファイル: blocks.py プロジェクト: fperez/regreg
    def __init__(self, atom, initial=None):
        self.atom = atom
        Y = np.zeros(atom.p)
        if initial is None:
            initial = np.zeros(atom.m)
        if not atom.noneD:
            self.loss = smooth.squaredloss(atom.D.T, Y)
        else:
            self.loss = smooth.signal_approximator(Y)

        dual_atom = atom.dual_constraint
        prox = dual_atom.primal_prox
        nonsmooth = dual_atom.evaluate_constraint
        if nonsmooth(initial) == np.inf:
            raise ValueError("initial point is not feasible")

        self.problem = dummy_problem(self.loss.smooth_eval, nonsmooth, prox, initial)
コード例 #7
0
ファイル: container.py プロジェクト: fperez/regreg
    def dual_problem(self, y, L_P=1, initial=None):
        """
        Return a problem instance of the dual
        prox problem with a given y value.
        """
        self._dual_prox_center = y
        if initial is None:
            z = np.zeros((), self.dual_dtype)
            for segment in self.dual_segments:
                z[segment] += np.random.standard_normal(z[segment].shape)

            # XXX dtype manipulations -- would be nice not to have to do this
            z = z.reshape((1,)).view(np.float)
            initial = self.dual_prox(z, 1.)
        nonsmooth = self.evaluate_dual_atoms
        prox = self.dual_prox
        return dummy_problem(self._dual_smooth_eval, nonsmooth, prox, initial, 1.)
コード例 #8
0
ファイル: container.py プロジェクト: sowuy/regreg
    def dual_problem(self, y, L_P=1, initial=None):
        """
        Return a problem instance of the dual
        prox problem with a given y value.
        """
        self._dual_prox_center = y
        if initial is None:
            z = np.zeros((), self.dual_dtype)
            for segment in self.dual_segments:
                z[segment] += np.random.standard_normal(z[segment].shape)

            # XXX dtype manipulations -- would be nice not to have to do this
            z = z.reshape((1, )).view(np.float)
            initial = self.dual_prox(z, 1.)
        nonsmooth = self.evaluate_dual_atoms
        prox = self.dual_prox
        return dummy_problem(self._dual_smooth_eval, nonsmooth, prox, initial,
                             1.)
コード例 #9
0
    def __init__(self, atom, initial=None):
        self.atom = atom
        Y = np.zeros(atom.p)
        if initial is None:
            initial = np.zeros(atom.m)
        if not atom.noneD:
            self.loss = smooth.squaredloss(atom.D.T, Y)
        else:
            self.loss = smooth.signal_approximator(Y)

        dual_atom = atom.dual_constraint
        prox = dual_atom.primal_prox
        nonsmooth = dual_atom.evaluate_constraint
        if nonsmooth(initial) == np.inf:
            raise ValueError('initial point is not feasible')

        self.problem = dummy_problem(self.loss.smooth_eval, nonsmooth, prox,
                                     initial)
コード例 #10
0
ファイル: container.py プロジェクト: fperez/regreg
    def conjugate_problem(self, conj=None, initial=None, smooth_multiplier=1.):
        """
        Create a problem object for solving the conjugate problem
        """

        if conj is not None:
            self.conjugate = conj
        if not hasattr(self, 'conjugate'):
            #If the conjugate of the loss function is not provided use the generic solver
            self.conjugate = conjugate(self.loss)

        prox = self.dual_prox
        nonsmooth = self.evaluate_dual_atoms

        if initial is None:
            z = np.zeros((), self.dual_dtype)
            for segment in self.dual_segments:
                z[segment] += np.random.standard_normal(z[segment].shape)

            # XXX dtype manipulations -- would be nice not to have to do this
            z = z.reshape((1,)).view(np.float)
            initial = self.dual_prox(z, 1.)

        return dummy_problem(self.conjugate_smooth_eval, nonsmooth, prox, initial, smooth_multiplier)