Exemplo n.º 1
0
    def getStep(self, X, G):
        """
        use the Fortran MYLBFGS code from GMIN to update the LBFGS memory and get the step size and direction.
        """
        self.X = X
        self.G = G
        # save the position and gradient change
        if self._iter > 0:
            N = self.N
            M = self.M
            
            #
            # need write the change in position and the change in gradient
            # to W.  This should be done more elegantly
            #
            ISPT= N + 2*M     # index for storage of search steps
            IYPT= ISPT + N*M  # index for storage of gradient differences

            NPT = N*((self._point + M - 1) % M)  
            # s = X - self.Xold
            # y = G - self.Gold
            self.W[ISPT+NPT : ISPT+NPT +N] = self.dXold
            self.W[IYPT+NPT : IYPT+NPT +N] = self.dGold    

        
        self.stp = mylbfgs_updatestep(self._iter, self.M, G, self.W, self.H0vec, self._point)
        
        self.H0 = self.H0vec[0]
        self._iter += 1
        self._point = self._iter % self.M
        
        return self.stp
Exemplo n.º 2
0
    def getStep(self, X, G):
        """
        use the Fortran MYLBFGS code from GMIN to update the LBFGS memory and get the step size and direction.
        """
        self.X = X
        self.G = G
        # save the position and gradient change
        if self._iter > 0:
            N = self.N
            M = self.M

            #
            # need write the change in position and the change in gradient
            # to W.  This should be done more elegantly
            #
            ISPT = N + 2 * M  # index for storage of search steps
            IYPT = ISPT + N * M  # index for storage of gradient differences

            NPT = N * ((self._point + M - 1) % M)
            # s = X - self.Xold
            # y = G - self.Gold
            self.W[ISPT + NPT:ISPT + NPT + N] = self.dXold
            self.W[IYPT + NPT:IYPT + NPT + N] = self.dGold

        self.stp = mylbfgs_updatestep(self._iter, self.M, G, self.W,
                                      self.H0vec, self._point)

        self.H0 = self.H0vec[0]
        self._iter += 1
        self._point = self._iter % self.M

        return self.stp
Exemplo n.º 3
0
    def getStep(self, X, G):
        """
        use the Fortran LBFGS code from GMIN to get the step
        size and direction.
        """
        self.X = X
        self.G = G
        #save the position and gradient change
        if self.iter > 0:
            N = self.N
            M = self.M
            
            #
            # need write the change in position and the change in gradient
            # to W.  This should be done more elegantly
            #
            ISPT= N + 2*M     # index for storage of search steps
            IYPT= ISPT + N*M  # index for storage of gradient differences

            NPT = N*((self.point + M - 1) % M)  
            #s = X - self.Xold
            #y = G - self.Gold
            #print "YS YY py", np.dot( y, s ), np.dot( y,y ), ISPT+NPT
            self.W[ISPT+NPT : ISPT+NPT +N] = X - self.Xold
            self.W[IYPT+NPT : IYPT+NPT +N] = G - self.Gold    
        self.Xold = X.copy()
        self.Gold = G.copy()

        
        #print self.iter, self.point
        self.stp = mylbfgs_updatestep(self.iter, self.M, G, self.W, self.H0vec, self.point, [self.N])
        
        #print "stp", np.linalg.norm(self.stp), self.stp
        #print "G", self.G
        #print "overlap", np.dot(self.stp, self.G)
        #print "H0", self.H0
        self.H0 = self.H0vec[0]
        self.iter += 1
        self.point = self.iter % self.M
        
        return self.stp
Exemplo n.º 4
0
    def getStep(self, X, G):
        """
        use the Fortran LBFGS code from GMIN to get the step
        size and direction.
        """
        self.X = X
        self.G = G
        #save the position and gradient change
        if self.iter > 0:
            N = self.N
            M = self.M

            #
            # need write the change in position and the change in gradient
            # to W.  This should be done more elegantly
            #
            ISPT = N + 2 * M  # index for storage of search steps
            IYPT = ISPT + N * M  # index for storage of gradient differences

            NPT = N * ((self.point + M - 1) % M)
            #s = X - self.Xold
            #y = G - self.Gold
            #print "YS YY py", np.dot( y, s ), np.dot( y,y ), ISPT+NPT
            self.W[ISPT + NPT:ISPT + NPT + N] = X - self.Xold
            self.W[IYPT + NPT:IYPT + NPT + N] = G - self.Gold
        self.Xold = X.copy()
        self.Gold = G.copy()

        #print self.iter, self.point
        self.stp = mylbfgs_updatestep(self.iter, self.M, G, self.W, self.H0vec,
                                      self.point, [self.N])

        #print "stp", np.linalg.norm(self.stp), self.stp
        #print "G", self.G
        #print "overlap", np.dot(self.stp, self.G)
        #print "H0", self.H0
        self.H0 = self.H0vec[0]
        self.iter += 1
        self.point = self.iter % self.M

        return self.stp