//! Perform line search public override double value(Problem P, ref EndCriteria.Type ecType, EndCriteria endCriteria, double t_ini) { //OptimizationMethod& method = P.method(); Constraint constraint = P.constraint(); succeed_ = true; bool maxIter = false; double qtold; double t = t_ini; int loopNumber = 0; double q0 = P.functionValue(); double qp0 = P.gradientNormValue(); qt_ = q0; qpt_ = (gradient_.Count == 0) ? qp0 : -Vector.DotProduct(gradient_, searchDirection_); // Initialize gradient gradient_ = new Vector(P.currentValue().Count); // Compute new point xtd_ = (Vector)P.currentValue().Clone(); t = update(ref xtd_, searchDirection_, t, constraint); // Compute function value at the new point qt_ = P.value(xtd_); // Enter in the loop if the criterion is not satisfied if ((qt_ - q0) > -alpha_ * t * qpt_) { do { loopNumber++; // Decrease step t *= beta_; // Store old value of the function qtold = qt_; // New point value xtd_ = P.currentValue(); t = update(ref xtd_, searchDirection_, t, constraint); // Compute function value at the new point qt_ = P.value(xtd_); P.gradient(gradient_, xtd_); // and it squared norm maxIter = endCriteria.checkMaxIterations(loopNumber, ref ecType); } while ((((qt_ - q0) > (-alpha_ * t * qpt_)) || ((qtold - q0) <= (-alpha_ * t * qpt_ / beta_))) && (!maxIter)); } if (maxIter) { succeed_ = false; } // Compute new gradient P.gradient(gradient_, xtd_); // and it squared norm qpt_ = Vector.DotProduct(gradient_, gradient_); // Return new step value return(t); }
//! Perform line search public override double value(Problem P, ref EndCriteria.Type ecType, EndCriteria endCriteria, double t_ini) { //OptimizationMethod& method = P.method(); Constraint constraint = P.constraint(); succeed_ = true; bool maxIter = false; double qtold; double t = t_ini; int loopNumber = 0; double q0 = P.functionValue(); double qp0 = P.gradientNormValue(); qt_ = q0; qpt_ = (gradient_.Count == 0) ? qp0 : -Vector.DotProduct(gradient_, searchDirection_); // Initialize gradient gradient_ = new Vector(P.currentValue().Count); // Compute new point xtd_ = (Vector)P.currentValue().Clone(); t = update(ref xtd_, searchDirection_, t, constraint); // Compute function value at the new point qt_ = P.value(xtd_); // Enter in the loop if the criterion is not satisfied if ((qt_ - q0) > -alpha_ * t * qpt_) { do { loopNumber++; // Decrease step t *= beta_; // Store old value of the function qtold = qt_; // New point value xtd_ = P.currentValue(); t = update(ref xtd_, searchDirection_, t, constraint); // Compute function value at the new point qt_ = P.value(xtd_); P.gradient(gradient_, xtd_); // and it squared norm maxIter = endCriteria.checkMaxIterations(loopNumber, ref ecType); } while ((((qt_ - q0) > (-alpha_ * t * qpt_)) || ((qtold - q0) <= (-alpha_ * t * qpt_ / beta_))) && (!maxIter)); } if (maxIter) succeed_ = false; // Compute new gradient P.gradient(gradient_, xtd_); // and it squared norm qpt_ = Vector.DotProduct(gradient_, gradient_); // Return new step value return t; }