(self, flat_grad, eps=1e-2, damping=False)
return
Performs curvature update.

        Inputs:
            flat_grad (tensor): 1-D tensor of flattened gradient for computing
                gradient difference with previously stored gradient
            eps (float): constant for curvature pair rejection or damping (default: 1e-2)
            damping (bool): flag for using Powell damping (default: False)
Performs curvature update.
Performs curvature update .
def curvature_update(self, flat_grad, eps=1e-2, damping=False):
        """
        Performs curvature update.

        Inputs:
            flat_grad (tensor): 1-D tensor of flattened gradient for computing
                gradient difference with previously stored gradient
            eps (float): constant for curvature pair rejection or damping (default: 1e-2)
            damping (bool): flag for using Powell damping (default: False)
        """

        assert len(self.param_groups) == 1

        # load parameters
        if(eps <= 0):
            raise(ValueError('Invalid eps; must be positive.'))

        group = self.param_groups[0]
        history_size = group['history_size']
        debug = group['debug']

        # variables cached in state (for tracing)
        state = self.state['global_state']
        fail = state.get('fail')

        # check if line search failed
        if not fail:

            d = state.get('d')
            t = state.get('t')
            old_dirs = state.get('old_dirs')
            old_stps = state.get('old_stps')
            H_diag = state.get('H_diag')
            prev_flat_grad = state.get('prev_flat_grad')
            Bs = state.get('Bs')

            # compute y's
            y = flat_grad.sub(prev_flat_grad)
            s = d.mul(t)
            sBs = s.dot(Bs)
            ys = y.dot(s)  # y*s

            # update L-BFGS matrix
            if ys > eps*sBs or damping == True:

                # perform Powell damping
                if damping == True and ys < eps*sBs:
                    if debug:
                        print('Applying Powell damping...')
                    theta = ((1-eps)*sBs)/(sBs - ys)
                    y = theta*y + (1-theta)*Bs

                # updating memory
                if len(old_dirs) == history_size:
                    # shift history by one (limited-memory)
                    old_dirs.pop(0)
                    old_stps.pop(0)

                # store new direction/step
                old_dirs.append(s)
                old_stps.append(y)

                # update scale of initial Hessian approximation
                H_diag = ys / y.dot(y)  # (y*y)

                state['old_dirs'] = old_dirs
                state['old_stps'] = old_stps
                state['H_diag'] = H_diag

            else:
                # save skip
                state['curv_skips'] += 1
                if debug:
                    print('Curvature pair skipped due to failed criterion')

        else:
            # save skip
            state['fail_skips'] += 1
            if debug:
                print('Line search failed; curvature pair update skipped')

        return
def curvature_update ( self , flat_grad , eps = 1e-2 , damping = False ) : assert len ( self . param_groups ) == 1 # load parameters if ( eps <= 0 ) : raise ( ValueError ( 'Invalid eps; must be positive.' ) ) group = self . param_groups [ 0 ] history_size = group [ 'history_size' ] debug = group [ 'debug' ] # variables cached in state (for tracing) state = self . state [ 'global_state' ] fail = state . get ( 'fail' ) # check if line search failed if not fail : d = state . get ( 'd' ) t = state . get ( 't' ) old_dirs = state . get ( 'old_dirs' ) old_stps = state . get ( 'old_stps' ) H_diag = state . get ( 'H_diag' ) prev_flat_grad = state . get ( 'prev_flat_grad' ) Bs = state . get ( 'Bs' ) # compute y's y = flat_grad . sub ( prev_flat_grad ) s = d . mul ( t ) sBs = s . dot ( Bs ) ys = y . dot ( s ) # y*s # update L-BFGS matrix if ys > eps * sBs or damping == True : # perform Powell damping if damping == True and ys < eps * sBs : if debug : print ( 'Applying Powell damping...' ) theta = ( ( 1 - eps ) * sBs ) / ( sBs - ys ) y = theta * y + ( 1 - theta ) * Bs # updating memory if len ( old_dirs ) == history_size : # shift history by one (limited-memory) old_dirs . pop ( 0 ) old_stps . pop ( 0 ) # store new direction/step old_dirs . append ( s ) old_stps . append ( y ) # update scale of initial Hessian approximation H_diag = ys / y . dot ( y ) # (y*y) state [ 'old_dirs' ] = old_dirs state [ 'old_stps' ] = old_stps state [ 'H_diag' ] = H_diag else : # save skip state [ 'curv_skips' ] += 1 if debug : print ( 'Curvature pair skipped due to failed criterion' ) else : # save skip state [ 'fail_skips' ] += 1 if debug : print ( 'Line search failed; curvature pair update skipped' ) return