QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
linesearch.hpp
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) 2006 Ferdinando Ametrano
5 Copyright (C) 2001, 2002, 2003 Nicolas Di Césaré
6
7 This file is part of QuantLib, a free-software/open-source library
8 for financial quantitative analysts and developers - http://quantlib.org/
9
10 QuantLib is free software: you can redistribute it and/or modify it
11 under the terms of the QuantLib license. You should have received a
12 copy of the license along with this program; if not, please email
13 <quantlib-dev@lists.sf.net>. The license is also available online at
14 <http://quantlib.org/license.shtml>.
15
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the license for more details.
19*/
20
21/*! \file linesearch.hpp
22 \brief Line search abstract class
23*/
24
25#ifndef quantlib_optimization_line_search_h_
26#define quantlib_optimization_line_search_h_
27
28#include <ql/math/array.hpp>
30
31namespace QuantLib {
32
33 class Problem;
34 class Constraint;
35 class EndCriteria;
36
37 //! Base class for line search
38 class LineSearch {
39 public:
40 //! Default constructor
41 explicit LineSearch(Real = 0.0) {}
42 //! Destructor
43 virtual ~LineSearch() = default;
44
45 //! return last x value
46 const Array& lastX() { return xtd_; }
47 //! return last cost function value
48 Real lastFunctionValue() const { return qt_; }
49 //! return last gradient
50 const Array& lastGradient() { return gradient_; }
51 //! return square norm of last gradient
52 Real lastGradientNorm2() const { return qpt_; }
53
54 bool succeed() const { return succeed_; }
55
56 //! Perform line search
57 virtual Real operator()(Problem& P, // Optimization problem
58 EndCriteria::Type& ecType,
59 const EndCriteria&,
60 Real t_ini) = 0; // initial value of line-search step
61 Real update(Array& params,
62 const Array& direction,
63 Real beta,
64 const Constraint& constraint);
65
66 //! current value of the search direction
67 const Array& searchDirection() const { return searchDirection_; }
69 protected:
70 //! current values of the search direction
72 //! new x and its gradient
74 //! cost function value and gradient norm corresponding to xtd_
75 Real qt_ = 0.0, qpt_ = 0.0;
76 //! flag to know if linesearch succeed
77 bool succeed_ = true;
78 };
79}
80
81#endif
1-D array used in linear algebra.
1-D array used in linear algebra.
Definition: array.hpp:52
Base constraint class.
Definition: constraint.hpp:35
Criteria to end optimization process:
Definition: endcriteria.hpp:40
Base class for line search.
Definition: linesearch.hpp:38
const Array & lastGradient()
return last gradient
Definition: linesearch.hpp:50
Array & searchDirection()
Definition: linesearch.hpp:68
const Array & searchDirection() const
current value of the search direction
Definition: linesearch.hpp:67
virtual ~LineSearch()=default
Destructor.
bool succeed_
flag to know if linesearch succeed
Definition: linesearch.hpp:77
Array searchDirection_
current values of the search direction
Definition: linesearch.hpp:71
const Array & lastX()
return last x value
Definition: linesearch.hpp:46
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
virtual Real operator()(Problem &P, EndCriteria::Type &ecType, const EndCriteria &, Real t_ini)=0
Perform line search.
Real lastGradientNorm2() const
return square norm of last gradient
Definition: linesearch.hpp:52
LineSearch(Real=0.0)
Default constructor.
Definition: linesearch.hpp:41
Real lastFunctionValue() const
return last cost function value
Definition: linesearch.hpp:48
bool succeed() const
Definition: linesearch.hpp:54
Real qt_
cost function value and gradient norm corresponding to xtd_
Definition: linesearch.hpp:75
Constrained optimization problem.
Definition: problem.hpp:42
Optimization criteria class.
QL_REAL Real
real number
Definition: types.hpp:50
Definition: any.hpp:35
Real beta
Definition: sabr.cpp:200