QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
armijo.cpp
Go to the documentation of this file.
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
23
24namespace QuantLib {
25
27 EndCriteria::Type& ecType,
28 const EndCriteria& endCriteria,
29 const Real t_ini)
30 {
31 //OptimizationMethod& method = P.method();
32 Constraint& constraint = P.constraint();
33 succeed_=true;
34 bool maxIter = false;
35 Real qtold, t = t_ini;
36 Size loopNumber = 0;
37
38 Real q0 = P.functionValue();
39 Real qp0 = P.gradientNormValue();
40
41 qt_ = q0;
43
44 // Initialize gradient
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_);
67 // and it squared norm
68 maxIter = endCriteria.checkMaxIterations(loopNumber, ecType);
69 } while (
70 (((qt_ - q0) > (-alpha_ * t * qpt_)) ||
71 ((qtold - q0) <= (-alpha_ * t * qpt_ / beta_))) &&
72 (!maxIter));
73 }
74
75 if (maxIter)
76 succeed_ = false;
77
78 // Compute new gradient
80 // and it squared norm
82
83 // Return new step value
84 return t;
85 }
86
87}
Armijo line-search class.
Real operator()(Problem &P, EndCriteria::Type &ecType, const EndCriteria &, Real t_ini) override
Perform line search.
Definition: armijo.cpp:26
1-D array used in linear algebra.
Definition: array.hpp:52
bool empty() const
whether the array is empty
Definition: array.hpp:499
Size size() const
dimension of the array
Definition: array.hpp:495
Base constraint class.
Definition: constraint.hpp:35
Criteria to end optimization process:
Definition: endcriteria.hpp:40
bool checkMaxIterations(Size iteration, EndCriteria::Type &ecType) const
Definition: endcriteria.cpp:56
bool succeed_
flag to know if linesearch succeed
Definition: linesearch.hpp:77
Array searchDirection_
current values of the search direction
Definition: linesearch.hpp:71
Real update(Array &params, const Array &direction, Real beta, const Constraint &constraint)
Definition: linesearch.cpp:26
Array xtd_
new x and its gradient
Definition: linesearch.hpp:73
Real qt_
cost function value and gradient norm corresponding to xtd_
Definition: linesearch.hpp:75
Constrained optimization problem.
Definition: problem.hpp:42
const Array & currentValue() const
current value of the local minimum
Definition: problem.hpp:81
Real functionValue() const
value of cost function
Definition: problem.hpp:88
Real gradientNormValue() const
value of cost function gradient norm
Definition: problem.hpp:94
Constraint & constraint() const
Constraint.
Definition: problem.hpp:71
Real value(const Array &x)
call cost function computation and increment evaluation counter
Definition: problem.hpp:116
void gradient(Array &grad_f, const Array &x)
call cost function gradient computation and increment
Definition: problem.hpp:126
const DefaultType & t
QL_REAL Real
real number
Definition: types.hpp:50
std::size_t Size
size of a container
Definition: types.hpp:58
Abstract optimization method class.
Definition: any.hpp:35
Real DotProduct(const Array &v1, const Array &v2)
Definition: array.hpp:553
Abstract optimization problem class.