44 #ifndef GLOBIPACK_POLY_INTERP_LINE_SEARCH_DEF_HPP
45 #define GLOBIPACK_POLY_INTERP_LINE_SEARCH_DEF_HPP
48 #include "GlobiPack_ArmijoPolyInterpLineSearch_decl.hpp"
49 #include "Teuchos_TabularOutputter.hpp"
58 template<
typename Scalar>
60 : eta_(ArmijoPolyInterpLineSearchUtils::eta_default),
61 minFrac_(ArmijoPolyInterpLineSearchUtils::minFrac_default),
62 maxFrac_(ArmijoPolyInterpLineSearchUtils::maxFrac_default),
63 minIters_(ArmijoPolyInterpLineSearchUtils::minIters_default),
64 maxIters_(ArmijoPolyInterpLineSearchUtils::maxIters_default),
65 doMaxIters_(ArmijoPolyInterpLineSearchUtils::doMaxIters_default)
69 template<
typename Scalar>
76 template<
typename Scalar>
83 template<
typename Scalar>
90 template<
typename Scalar>
97 template<
typename Scalar>
104 template<
typename Scalar>
114 template<
class Scalar>
120 namespace AQLSU = ArmijoPolyInterpLineSearchUtils;
121 using Teuchos::getParameter;
123 eta_ = getParameter<double>(*paramList, AQLSU::eta_name);
124 minFrac_ = getParameter<double>(*paramList, AQLSU::minFrac_name);
125 maxFrac_ = getParameter<double>(*paramList, AQLSU::maxFrac_name);
126 minIters_ = getParameter<int>(*paramList, AQLSU::minIters_name);
127 maxIters_ = getParameter<int>(*paramList, AQLSU::maxIters_name);
128 doMaxIters_ = getParameter<bool>(*paramList, AQLSU::doMaxIters_name);
135 setMyParamList(paramList);
139 template<
class Scalar>
143 namespace AQLSU = ArmijoPolyInterpLineSearchUtils;
148 pl->
set( AQLSU::eta_name, AQLSU::eta_default );
149 pl->
set( AQLSU::minFrac_name, AQLSU::minFrac_default );
150 pl->
set( AQLSU::maxFrac_name, AQLSU::maxFrac_default );
151 pl->
set( AQLSU::minIters_name, AQLSU::minIters_default );
152 pl->
set( AQLSU::maxIters_name, AQLSU::maxIters_default );
153 pl->
set( AQLSU::doMaxIters_name, AQLSU::doMaxIters_default );
163 template<
typename Scalar>
170 template<
typename Scalar>
177 template<
typename Scalar>
187 using Teuchos::ptrFromRef;
193 #endif // TEUCHOS_DEBUG
199 *out <<
"\nStarting Armijo Quadratic interpolation linesearch ...\n";
209 #endif // TEUCHOS_DEBUG
211 const Scalar phi_k = point_k.
phi;
212 Scalar &alpha_k = point_kp1->alpha;
213 Scalar &phi_kp1 = point_kp1->phi;
217 const Scalar Dphi_k = point_k.
Dphi;
222 <<
"\nDphi_k = " << Dphi_k
223 <<
"\nphi_k = " << phi_k
226 *out <<
"\nminIters == " << minIters_ <<
"\n";
228 *out <<
"\ndoMaxIters == true, maxing out maxIters = "
229 <<maxIters_<<
" iterations!\n";
232 TabularOutputter tblout(out);
234 tblout.pushFieldSpec(
"itr", TO::INT);
235 tblout.pushFieldSpec(
"alpha_k", TO::DOUBLE);
236 tblout.pushFieldSpec(
"phi_kp1", TO::DOUBLE);
237 tblout.pushFieldSpec(
"phi_kp1-frac_phi", TO::DOUBLE);
238 tblout.pushFieldSpec(
"alpha_interp", TO::DOUBLE);
239 tblout.pushFieldSpec(
"alpha_min", TO::DOUBLE);
240 tblout.pushFieldSpec(
"alpha_max", TO::DOUBLE);
242 tblout.outputHeader();
246 "ArmijoPolyInterpLineSearch::doLineSearch(): "
247 "The given descent direction for the given "
248 "phi Dphi_k="<<Dphi_k<<
" >= 0!" );
251 Scalar best_alpha = alpha_k;
252 Scalar best_phi = phi_kp1;
255 bool success =
false;
257 for ( ; numIters < maxIters_; ++numIters ) {
261 Scalar frac_phi = phi_k + eta_ * alpha_k * Dphi_k;
262 tblout.outputField(numIters);
263 tblout.outputField(alpha_k);
264 tblout.outputField(phi_kp1);
265 tblout.outputField(((phi_kp1)-frac_phi));
267 if (ST::isnaninf(phi_kp1)) {
270 alpha_k = minFrac_ * alpha_k;
271 best_alpha = ST::zero();
277 if (phi_kp1 < frac_phi) {
280 if (numIters < minIters_) {
283 else if ( !doMaxIters_ || ( doMaxIters_ && numIters == maxIters_ - 1 ) ) {
284 tblout.nextRow(
true);
301 ( -as<Scalar>(0.5) * Dphi_k * alpha_k * alpha_k )
303 ( (phi_kp1) - phi_k - alpha_k * Dphi_k );
305 tblout.outputField(alpha_quad);
310 const Scalar alpha_min = minFrac_ * alpha_k;
311 const Scalar alpha_max = maxFrac_ * alpha_k;
313 tblout.outputField(alpha_min);
314 tblout.outputField(alpha_max);
318 max(alpha_min, alpha_quad),
324 tblout.nextRow(
true);
329 phi_kp1 = computeValue<Scalar>(phi, alpha_k);
332 if (phi_kp1 < best_phi) {
334 best_alpha = alpha_k;
340 *numIters_out = numIters;
343 *out <<
"\nLine search success!\n";
349 alpha_k = best_alpha;
350 phi_kp1 = computeValue<Scalar>(phi, best_alpha);
351 *out <<
"\nLine search failure!\n";
360 #endif // GLOBIPACK_POLY_INTERP_LINE_SEARCH_DEF_HPP
Scalar phi
The value of the merit function phi(alpha).
bool is_null(const boost::shared_ptr< T > &p)
Scalar Dphi
The value of the derivative of the merit function Dphi(alpha).
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
#define TEUCHOS_ASSERT_INEQUALITY(val1, comp, val2)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
RCP< const ParameterList > getValidParameters() const
Thrown if search direction not a descent direction for the merit function.
virtual bool doLineSearch(const MeritFunc1DBase< Scalar > &phi, const PointEval1D< Scalar > &point_k, const Ptr< PointEval1D< Scalar > > &point_kp1, const Ptr< int > &numIters) const
Scalar alpha
The value of the unknown alpha.
Represents the evaluation point of the merit function phi(alpha) and/or is derivative Dphi(alpha)...
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
void validateParametersAndSetDefaults(ParameterList const &validParamList, int const depth=1000)
void setParameterList(RCP< ParameterList > const ¶mList)
virtual bool requiresDerivEvals() const
Returns false.
ArmijoPolyInterpLineSearch()
Construct with default parameters.
TypeTo as(const TypeFrom &t)
Base class for 1D merit fucntions used in globalization methods.
#define TEUCHOS_ASSERT(assertion_test)
#define TEUCHOS_ASSERT_EQUALITY(val1, val2)
virtual bool requiresBaseDeriv() const
Returns true.