OpenMD 3.1
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
Armijo.cpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2001, 2002, 2003 Nicolas Di Césaré
5
6 This file is part of QuantLib, a free-software/open-source library
7 for financial quantitative analysts and developers - http://quantlib.org/
8
9 QuantLib is free software: you can redistribute it and/or modify it
10 under the terms of the QuantLib license. You should have received a
11 copy of the license along with this program; if not, please email
12 <quantlib-dev@lists.sf.net>. The license is also available online at
13 <http://quantlib.org/license.shtml>.
14
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the license for more details.
18*/
19
21
24
25namespace QuantLib {
26
27 RealType ArmijoLineSearch::operator()(Problem& P, EndCriteria::Type& ecType,
28 const EndCriteria& endCriteria,
29 const RealType t_ini) {
30 // OptimizationMethod& method = P.method();
31 Constraint& constraint = P.constraint();
32 succeed_ = true;
33 bool maxIter = false;
34 RealType qtold, t = t_ini;
35 size_t loopNumber = 0;
36
37 RealType q0 = P.functionValue();
38 RealType qp0 = P.gradientNormValue();
39
40 qt_ = q0;
41 qpt_ =
42 (gradient_.empty()) ? qp0 : -P.DotProduct(gradient_, searchDirection_);
43
44 // Initialize gradient
45 gradient_ = DynamicVector<RealType>(P.currentValue().size());
46 // Compute new point
47 xtd_ = P.currentValue();
48 t = update(xtd_, searchDirection_, t, constraint);
49 // Compute function value at the new point
50 qt_ = P.value(xtd_);
51
52 // Enter in the loop if the criterion is not satisfied
53 if ((qt_ - q0) > -alpha_ * t * qpt_) {
54 do {
55 loopNumber++;
56 // Decrease step
57 t *= beta_;
58 // Store old value of the function
59 qtold = qt_;
60 // New point value
61 xtd_ = P.currentValue();
62 t = update(xtd_, searchDirection_, t, constraint);
63
64 // Compute function value at the new point
65 qt_ = P.value(xtd_);
66 P.gradient(gradient_, xtd_);
67 // and it squared norm
68 maxIter = endCriteria.checkMaxIterations(loopNumber, ecType);
69 } while ((((qt_ - q0) > (-alpha_ * t * qpt_)) ||
70 ((qtold - q0) <= (-alpha_ * t * qpt_ / beta_))) &&
71 (!maxIter));
72 }
73
74 if (maxIter) succeed_ = false;
75
76 // Compute new gradient
77 P.gradient(gradient_, xtd_);
78 // and it squared norm
79 // qpt_ = P.computeGradientNormValue(gradient_);
80 qpt_ = P.DotProduct(gradient_, gradient_);
81
82 // Return new step value
83 return t;
84 }
85
86} // namespace QuantLib
Armijo line-search class.
Abstract optimization method class.
Abstract optimization problem class.
Dynamically-sized vector class.
RealType operator()(Problem &P, EndCriteria::Type &ecType, const EndCriteria &, const RealType t_ini)
Perform line search.
Definition Armijo.cpp:27
Base constraint class.
Criteria to end optimization process:
bool checkMaxIterations(const size_t iteration, EndCriteria::Type &ecType) const
Test if the number of iteration is below MaxIterations.
DynamicVector< RealType > xtd_
new x and its gradient
DynamicVector< RealType > searchDirection_
current values of the search direction
RealType qt_
objective function value and gradient norm corresponding to xtd_
bool succeed_
flag to know if linesearch succeed
Constrained optimization problem.
Definition Problem.hpp:37
void gradient(DynamicVector< RealType > &grad_f, const DynamicVector< RealType > &x)
call objective function gradient computation and increment
Definition Problem.hpp:130
RealType functionValue() const
value of objective function
Definition Problem.hpp:86
RealType value(const DynamicVector< RealType > &x)
call objective function computation and increment evaluation counter
Definition Problem.hpp:121
RealType gradientNormValue() const
value of objective function gradient norm
Definition Problem.hpp:92
Constraint & constraint() const
Constraint.
Definition Problem.hpp:65
const DynamicVector< RealType > & currentValue() const
current value of the local minimum
Definition Problem.hpp:77