37 EndCriteria::Type LineSearchBasedMethod::minimize(
39 RealType initialStepSize = 1.0) {
41 RealType ftol = endCriteria.functionEpsilon();
42 size_t maxStationaryStateIterations_ =
43 endCriteria.maxStationaryStateIterations();
44 EndCriteria::Type ecType = EndCriteria::None;
47 size_t iterationNumber_ = 0;
53 RealType fnew, fold, gold2;
58 RealType t = initialStepSize;
61 size_t sz = lineSearch_->searchDirection().size();
67 P.setGradientNormValue(P.DotProduct(prevGradient, prevGradient));
68 lineSearch_->searchDirection() = -prevGradient;
70 bool first_time =
true;
77 if (!first_time) prevGradient = lineSearch_->lastGradient();
79 t = (*lineSearch_)(P, ecType, endCriteria, t);
83 if (lineSearch_->succeed()) {
86 x_ = lineSearch_->lastX();
87 P.setCurrentValue(x_);
89 P.setFunctionValue(lineSearch_->lastFunctionValue());
93 P.setGradientNormValue(lineSearch_->lastGradientNorm2());
96 direction = getUpdatedDirection(P, gold2, prevGradient);
98 sddiff = direction - lineSearch_->searchDirection();
100 lineSearch_->searchDirection() = direction;
104 fnew = P.functionValue();
105 fdiff = 2.0 * std::fabs(fnew - fold) /
106 (std::fabs(fnew) + std::fabs(fold) +
107 std::numeric_limits<RealType>::epsilon());
110 endCriteria.checkMaxIterations(iterationNumber_, ecType)) {
111 endCriteria.checkStationaryFunctionValue(
112 0.0, 0.0, maxStationaryStateIterations_, ecType);
113 endCriteria.checkMaxIterations(iterationNumber_, ecType);
116 P.setCurrentValue(x_);
123 P.setCurrentValue(x_);