private void invokeLineInitialize(double funcAtStart, double maxStep) { function.setInput(initialStep); double funcAtInit = function.computeFunction(); lineSearch.init(funcAtStart,derivAtZero,funcAtInit,initialStep,0,maxStep); firstStep = true; }
function.computeGradient(temp0_Nx1.data); System.arraycopy(function.getCurrentState(),0,x.data,0,N); return terminateSearch(true);
/** * Specify the function being optimized * @param function Function to optimize * @param funcMinValue Minimum possible function value. E.g. 0 for least squares. */ public void setFunction( GradientLineFunction function , double funcMinValue ) { this.function = function; this.funcMinValue = funcMinValue; lineSearch.setFunction(function,funcMinValue); N = function.getN(); B = new DMatrixRMaj(N,N); searchVector = new DMatrixRMaj(N,1); g = new DMatrixRMaj(N,1); s = new DMatrixRMaj(N,1); y = new DMatrixRMaj(N,1); x = new DMatrixRMaj(N,1); temp0_Nx1 = new DMatrixRMaj(N,1); temp1_Nx1 = new DMatrixRMaj(N,1); }
private boolean setupLineSearch( double funcAtStart , double[] startPoint , double[] startDeriv, double[] direction ) { // derivative of the line search is the dot product of the gradient and search direction derivAtZero = 0; for( int i = 0; i < N; i++ ) { derivAtZero += startDeriv[i]*direction[i]; } // degenerate case if( derivAtZero > 0 ) return false; else if( derivAtZero == 0 ) return true; // setup line functions function.setLine(startPoint, direction); // use wolfe condition to set the maximum step size maxStep = (funcMinValue-funcAtStart)/(lineSearch.getGTol()*derivAtZero); initialStep = 1 < maxStep ? 1 : maxStep; invokeLineInitialize(funcAtStart,maxStep); return true; }
System.arraycopy(function.getCurrentState(),0,x.data,0,N);
function.computeGradient(temp0_Nx1.data); System.arraycopy(function.getCurrentState(),0,x.data,0,N); return terminateSearch(true);
/** * Specify the function being optimized * @param function Function to optimize * @param funcMinValue Minimum possible function value. E.g. 0 for least squares. */ public void setFunction( GradientLineFunction function , double funcMinValue ) { this.function = function; this.funcMinValue = funcMinValue; lineSearch.setFunction(function,funcMinValue); N = function.getN(); B = new DMatrixRMaj(N,N); searchVector = new DMatrixRMaj(N,1); g = new DMatrixRMaj(N,1); s = new DMatrixRMaj(N,1); y = new DMatrixRMaj(N,1); x = new DMatrixRMaj(N,1); temp0_Nx1 = new DMatrixRMaj(N,1); temp1_Nx1 = new DMatrixRMaj(N,1); }
private boolean setupLineSearch( double funcAtStart , double[] startPoint , double[] startDeriv, double[] direction ) { // derivative of the line search is the dot product of the gradient and search direction derivAtZero = 0; for( int i = 0; i < N; i++ ) { derivAtZero += startDeriv[i]*direction[i]; } // degenerate case if( derivAtZero > 0 ) return false; else if( derivAtZero == 0 ) return true; // setup line functions function.setLine(startPoint, direction); // use wolfe condition to set the maximum step size maxStep = (funcMinValue-funcAtStart)/(lineSearch.getGTol()*derivAtZero); initialStep = 1 < maxStep ? 1 : maxStep; invokeLineInitialize(funcAtStart,maxStep); return true; }
System.arraycopy(function.getCurrentState(),0,x.data,0,N);
private void invokeLineInitialize(double funcAtStart, double maxStep) { function.setInput(initialStep); double funcAtInit = function.computeFunction(); lineSearch.init(funcAtStart,derivAtZero,funcAtInit,initialStep,0,maxStep); firstStep = true; }
public void initialize(double[] initial) { this.mode = 0; this.hasConverged = false; this.iterations = 0; // set the change in x to be zero s.zero(); // default to an initial inverse Hessian approximation as // the identity matrix. This can be overridden or improved by an heuristic below CommonOps_DDRM.setIdentity(B); // save the initial value of x System.arraycopy(initial, 0, x.data, 0, N); function.setInput(x.data); fx = function.computeFunction(); updated = false; if( verbose != null ) { verbose.println("Steps fx change |step| f-test g-test max-step "); verbose.printf("%-4d %9.3E %10.3E %9.3E %9.3E %9.3E %6.2f\n", iterations, fx, 0.0,0.0,0.0,0.0, 0.0); } }
public void initialize(double[] initial) { this.mode = 0; this.hasConverged = false; this.iterations = 0; // set the change in x to be zero s.zero(); // default to an initial inverse Hessian approximation as // the identity matrix. This can be overridden or improved by an heuristic below CommonOps_DDRM.setIdentity(B); // save the initial value of x System.arraycopy(initial, 0, x.data, 0, N); function.setInput(x.data); fx = function.computeFunction(); updated = false; if( verbose != null ) { verbose.println("Steps fx change |step| f-test g-test max-step "); verbose.printf("%-4d %9.3E %10.3E %9.3E %9.3E %9.3E %6.2f\n", iterations, fx, 0.0,0.0,0.0,0.0, 0.0); } }