OpenMD
3.2
Molecular Dynamics in the Open
Toggle main menu visibility
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
20
#include "
optimization/Armijo.hpp
"
21
22
#include "
optimization/Method.hpp
"
23
#include "
optimization/Problem.hpp
"
24
25
namespace
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.hpp
Armijo line-search class.
Method.hpp
Abstract optimization method class.
Problem.hpp
Abstract optimization problem class.
OpenMD::DynamicVector
Dynamically-sized vector class.
Definition
DynamicVector.hpp:74
QuantLib::ArmijoLineSearch::operator()
RealType operator()(Problem &P, EndCriteria::Type &ecType, const EndCriteria &, const RealType t_ini)
Perform line search.
Definition
Armijo.cpp:27
QuantLib::Constraint
Base constraint class.
Definition
Constraint.hpp:35
QuantLib::EndCriteria
Criteria to end optimization process:
Definition
EndCriteria.hpp:42
QuantLib::EndCriteria::checkMaxIterations
bool checkMaxIterations(const size_t iteration, EndCriteria::Type &ecType) const
Test if the number of iteration is below MaxIterations.
Definition
EndCriteria.cpp:61
QuantLib::LineSearch::xtd_
DynamicVector< RealType > xtd_
new x and its gradient
Definition
LineSearch.hpp:76
QuantLib::LineSearch::searchDirection_
DynamicVector< RealType > searchDirection_
current values of the search direction
Definition
LineSearch.hpp:74
QuantLib::LineSearch::qt_
RealType qt_
objective function value and gradient norm corresponding to xtd_
Definition
LineSearch.hpp:78
QuantLib::LineSearch::succeed_
bool succeed_
flag to know if linesearch succeed
Definition
LineSearch.hpp:80
QuantLib::Problem
Constrained optimization problem.
Definition
Problem.hpp:37
QuantLib::Problem::gradient
void gradient(DynamicVector< RealType > &grad_f, const DynamicVector< RealType > &x)
call objective function gradient computation and increment
Definition
Problem.hpp:130
QuantLib::Problem::functionValue
RealType functionValue() const
value of objective function
Definition
Problem.hpp:86
QuantLib::Problem::value
RealType value(const DynamicVector< RealType > &x)
call objective function computation and increment evaluation counter
Definition
Problem.hpp:121
QuantLib::Problem::gradientNormValue
RealType gradientNormValue() const
value of objective function gradient norm
Definition
Problem.hpp:92
QuantLib::Problem::constraint
Constraint & constraint() const
Constraint.
Definition
Problem.hpp:65
QuantLib::Problem::currentValue
const DynamicVector< RealType > & currentValue() const
current value of the local minimum
Definition
Problem.hpp:77
optimization
Armijo.cpp
Generated on
for OpenMD by
1.17.0