private boolean computeSearchDirection ( ) { // Compute the function's gradient function . computeGradient ( temp0_Nx1 . data ) ; // compute the change in gradient for ( int i = 0 ; i < N ; i ++ ) { y . data [ i ] = temp0_Nx1 . data [ i ] - g . data [ i ] ; g . data [ i ] = temp0_Nx1 . data [ i ] ; } // Update the inverse Hessian matrix if ( iterations != 0 ) { EquationsBFGS . inverseUpdate ( B , s , y , temp0_Nx1 , temp1_Nx1 ) ; } // compute the search direction CommonOps_DDRM . mult ( - 1 , B , g , searchVector ) ; // use the line search to find the next x if ( ! setupLineSearch ( fx , x . data , g . data , searchVector . data ) ) { // the search direction has a positive derivative, meaning the B matrix is // no longer SPD. Attempt to fix the situation by resetting the matrix resetMatrixB ( ) ; // do the search again, it can't fail this time CommonOps_DDRM . mult ( - 1 , B , g , searchVector ) ; setupLineSearch ( fx , x . data , g . data , searchVector . data ) ; } else if ( Math . abs ( derivAtZero ) <= gtol ) { if ( verbose != null ) { verbose . printf ( "finished select direction, gtest=%e\n" , Math . abs ( derivAtZero ) ) ; } // the input might have been modified by the function. So copy it System . arraycopy ( function . getCurrentState ( ) , 0 , x . data , 0 , N ) ; return terminateSearch ( true ) ; } mode = 1 ; iterations ++ ; return false ; }
Computes the next search direction using BFGS