public double[] Solve( Func <double[], double> f, double[] startValue, int nIter) { OptVector xOld = new OptVector(startValue); OptVector xNew = new OptVector(); OptVector derivativeOld = new OptVector(numericalDerivative.EvaluatePartialDerivative(f, xOld.MinArray, 1)); OptVector direction = -1.0 * derivativeOld; OptVector derivativeNew = new OptVector(); for (int i = 0; i < nIter; i++) { StepSize = strongWolfeLineSearch.GetStepLength(f, direction, xOld, 20, MaxIterLineSearch); xNew = xOld + StepSize * direction; if (CheckEarlyExit(xNew, xOld)) { break; } derivativeNew = new OptVector(numericalDerivative.EvaluatePartialDerivative(f, xNew.MinArray, 1)); double beta = PolakRibiere(derivativeNew, derivativeOld); direction = beta * direction - derivativeNew; xOld = xNew; derivativeOld = derivativeNew; } return(xNew.MinArray); }
public double[] Solve( Func <double[], double> f, double[] startValue, int nIter) { OptVector xOld = new OptVector(startValue); OptVector xNew = new OptVector(); OptVector derivativeOld = new OptVector(numericalDerivative.EvaluatePartialDerivative(f, xOld.MinArray, 1)); OptVector[] oldInvHessian = OptimizationHelper.GetIdentity(startValue.Length); OptVector direction = OptVector.Mult(oldInvHessian, -1.0 * derivativeOld); OptVector derivativeNew = new OptVector(); for (int i = 0; i < nIter; i++) { StepSize = strongWolfeLineSearch.GetStepLength(f, direction, xOld, 4.0, MaxIterLineSearch); OptVector sk = StepSize * direction; xNew = xOld + sk; if (xNew.MinArray.Contains(double.NaN)) { break; } if (EarlyExit && CheckEarlyExit(xNew, xOld)) { break; } derivativeNew = new OptVector(numericalDerivative.EvaluatePartialDerivative(f, xNew.MinArray, 1)); OptVector yk = sk; OptVector[] newInvHessian = GetApproximateInverseHessianMatrix( oldInvHessian, yk, sk); direction = OptVector.Mult(newInvHessian, derivativeNew) * -1.0; xOld = xNew; oldInvHessian = newInvHessian; derivativeOld = derivativeNew; } return(xNew.MinArray); }