コード例 #1
0
ファイル: bqp.py プロジェクト: joeywen/nlpy
    def projected_gradient(self, x0, g=None, active_set=None, qval=None, **kwargs):
        """
        Perform a sequence of projected gradient steps starting from x0.
        If the actual gradient at x is known, it should be passed using the
        `g` keyword.
        If the active set at x0 is known, it should be passed using the
        `active_set` keyword.
        If the value of the quadratic objective at x0 is known, it should
        be passed using the `qval` keyword.

        Return (x,(lower,upper)) where x is an updated iterate that satisfies
        a sufficient decrease condition or at which the active set, given by
        (lower,upper), settled down.
        """
        maxiter = kwargs.get('maxiter', 10)
        qp = self.qp

        if g is None:
            g = self.qp.grad(x0)

        if qval is None:
            qval = self.qp.obj(x0)

        if active_set is None:
            active_set = self.get_active_set(x0)
        lower, upper = active_set

        print 'Entering projected_gradient'
        print '  qval=', qval, 'lower=', lower, ', upper=', upper

        x = x0.copy()
        settled_down = False
        sufficient_decrease = False
        best_decrease = 0
        iter = 0

        while not settled_down and not sufficient_decrease and \
              iter < maxiter:

            iter += 1
            qOld = qval
            # TODO: Use appropriate initial steplength.
            (x, qval) = self.projected_linesearch(x, g, -g, qval)

            # Check decrease in objective.
            decrease = qOld - qval
            if decrease <= self.pgrad_reltol * best_decrease:
                sufficient_decrease = True
            best_decrease = max(best_decrease, decrease)

            # Check active set at updated iterate.
            lowerTrial, upperTrial = self.get_active_set(x)
            if identical(lower,lowerTrial) and identical(upper,upperTrial):
                settled_down = True
            lower, upper = lowerTrial, upperTrial

            print '  qval=', qval, 'lower=', lower, ', upper=', upper
            print '  settled=', repr(settled_down), ', decrease=', repr(sufficient_decrease)

        return (x, (lower, upper))
コード例 #2
0
ファイル: bqp.py プロジェクト: joeywen/nlpy
 def check_feasible(self, x):
     """
     Safety function. Check that x is feasible with respect to the
     bound constraints.
     """
     Px = self.project(x)
     if not identical(x,Px):
         raise InfeasibleError, 'Received infeasible point.'
     return None
コード例 #3
0
ファイル: bqp.py プロジェクト: vishalbelsare/nlpy
 def check_feasible(self, x):
     """
     Safety function. Check that x is feasible with respect to the
     bound constraints.
     """
     Px = self.project(x)
     if not identical(x, Px):
         raise InfeasibleError, 'Received infeasible point.'
     return None
コード例 #4
0
ファイル: bqp.py プロジェクト: vishalbelsare/nlpy
    def projected_gradient(self,
                           x0,
                           g=None,
                           active_set=None,
                           qval=None,
                           **kwargs):
        """
        Perform a sequence of projected gradient steps starting from x0.
        If the actual gradient at x is known, it should be passed using the
        `g` keyword.
        If the active set at x0 is known, it should be passed using the
        `active_set` keyword.
        If the value of the quadratic objective at x0 is known, it should
        be passed using the `qval` keyword.

        Return (x,(lower,upper)) where x is an updated iterate that satisfies
        a sufficient decrease condition or at which the active set, given by
        (lower,upper), settled down.
        """
        maxiter = kwargs.get('maxiter', 10)
        qp = self.qp

        if g is None:
            g = self.qp.grad(x0)

        if qval is None:
            qval = self.qp.obj(x0)

        if active_set is None:
            active_set = self.get_active_set(x0)
        lower, upper = active_set

        print 'Entering projected_gradient'
        print '  qval=', qval, 'lower=', lower, ', upper=', upper

        x = x0.copy()
        settled_down = False
        sufficient_decrease = False
        best_decrease = 0
        iter = 0

        while not settled_down and not sufficient_decrease and \
              iter < maxiter:

            iter += 1
            qOld = qval
            # TODO: Use appropriate initial steplength.
            (x, qval) = self.projected_linesearch(x, g, -g, qval)

            # Check decrease in objective.
            decrease = qOld - qval
            if decrease <= self.pgrad_reltol * best_decrease:
                sufficient_decrease = True
            best_decrease = max(best_decrease, decrease)

            # Check active set at updated iterate.
            lowerTrial, upperTrial = self.get_active_set(x)
            if identical(lower, lowerTrial) and identical(upper, upperTrial):
                settled_down = True
            lower, upper = lowerTrial, upperTrial

            print '  qval=', qval, 'lower=', lower, ', upper=', upper
            print '  settled=', repr(settled_down), ', decrease=', repr(
                sufficient_decrease)

        return (x, (lower, upper))