OpenMD
3.2
Molecular Dynamics in the Open
Toggle main menu visibility
Loading...
Searching...
No Matches
Problem.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) 2007 Ferdinando Ametrano
5
Copyright (C) 2007 François du Vignaud
6
Copyright (C) 2001, 2002, 2003 Nicolas Di Césaré
7
8
This file is part of QuantLib, a free-software/open-source library
9
for financial quantitative analysts and developers - http://quantlib.org/
10
11
QuantLib is free software: you can redistribute it and/or modify it
12
under the terms of the QuantLib license. You should have received a
13
copy of the license along with this program; if not, please email
14
<quantlib-dev@lists.sf.net>. The license is also available online at
15
<http://quantlib.org/license.shtml>.
16
17
This program is distributed in the hope that it will be useful, but WITHOUT
18
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19
FOR A PARTICULAR PURPOSE. See the license for more details.
20
*/
21
22
/*! \file problem.hpp
23
\brief Abstract optimization problem class
24
*/
25
26
#ifndef quantlib_optimization_problem_h
27
#define quantlib_optimization_problem_h
28
29
#include "
optimization/Method.hpp
"
30
#include "
optimization/ObjectiveFunction.hpp
"
31
#include "optimization/StatusFunction.hpp"
32
33
namespace
QuantLib {
34
35
class
Constraint
;
36
//! Constrained optimization problem
37
class
Problem
{
38
public
:
39
//! default constructor
40
Problem
(
ObjectiveFunction
&
objectiveFunction
,
Constraint
&
constraint
,
41
OpenMD::StatusFunction
& statFunc,
42
const
DynamicVector<RealType>
& initialValue =
43
DynamicVector<RealType>
()) :
44
objectiveFunction_
(
objectiveFunction
),
45
constraint_
(
constraint
),
currentValue_
(initialValue),
46
statusFunction_
(statFunc) {}
47
48
/*! \warning it does not reset the current minumum to any initial value
49
*/
50
void
reset
();
51
52
//! call objective function computation and increment evaluation counter
53
RealType
value
(
const
DynamicVector<RealType>
& x);
54
55
//! call objective function gradient computation and increment
56
// evaluation counter
57
void
gradient
(
DynamicVector<RealType>
& grad_f,
58
const
DynamicVector<RealType>
& x);
59
60
//! call objective function computation and it gradient
61
RealType
valueAndGradient
(
DynamicVector<RealType>
& grad_f,
62
const
DynamicVector<RealType>
& x);
63
64
//! Constraint
65
Constraint
&
constraint
()
const
{
return
constraint_
; }
66
67
//! Objective function
68
ObjectiveFunction
&
objectiveFunction
()
const
{
return
objectiveFunction_
; }
69
70
void
setCurrentValue(
const
DynamicVector<RealType>
&
currentValue
) {
71
currentValue_
=
currentValue
;
72
statusFunction_
.writeStatus(
functionEvaluation_
, gradientEvaluation_,
73
currentValue_
,
functionValue_
);
74
}
75
76
//! current value of the local minimum
77
const
DynamicVector<RealType>
&
currentValue
()
const
{
78
return
currentValue_
;
79
}
80
81
void
setFunctionValue(RealType
functionValue
) {
82
functionValue_
=
functionValue
;
83
}
84
85
//! value of objective function
86
RealType
functionValue
()
const
{
return
functionValue_
; }
87
88
void
setGradientNormValue(RealType squaredNorm) {
89
squaredNorm_ = squaredNorm;
90
}
91
//! value of objective function gradient norm
92
RealType
gradientNormValue
()
const
{
return
squaredNorm_; }
93
94
//! number of evaluation of objective function
95
int
functionEvaluation
()
const
{
return
functionEvaluation_
; }
96
97
//! number of evaluation of objective function gradient
98
int
gradientEvaluation
()
const
{
return
gradientEvaluation_; }
99
100
RealType DotProduct(
DynamicVector<RealType>
& v1,
101
DynamicVector<RealType>
& v2);
102
RealType computeGradientNormValue(
DynamicVector<RealType>
& grad_f);
103
104
protected
:
105
//! Unconstrained objective function
106
ObjectiveFunction
&
objectiveFunction_
;
107
//! Constraint
108
Constraint
&
constraint_
;
109
//! current value of the local minimum
110
DynamicVector<RealType>
currentValue_
;
111
//! function and gradient norm values at the curentValue_ (i.e. the last
112
//! step)
113
RealType
functionValue_
, squaredNorm_;
114
//! number of evaluation of objective function and its gradient
115
int
functionEvaluation_
, gradientEvaluation_;
116
//! status function
117
StatusFunction
&
statusFunction_
;
118
};
119
120
// inline definitions
121
inline
RealType
Problem::value
(
const
DynamicVector<RealType>
& x) {
122
++
functionEvaluation_
;
123
functionValue_
=
objectiveFunction_
.value(x);
124
statusFunction_
.writeStatus(
functionEvaluation_
, gradientEvaluation_,
125
currentValue_
,
functionValue_
);
126
127
return
functionValue_
;
128
}
129
130
inline
void
Problem::gradient
(
DynamicVector<RealType>
& grad_f,
131
const
DynamicVector<RealType>
& x) {
132
++gradientEvaluation_;
133
objectiveFunction_
.gradient(grad_f, x);
134
}
135
136
inline
RealType
Problem::valueAndGradient
(
DynamicVector<RealType>
& grad_f,
137
const
DynamicVector<RealType>
& x) {
138
++
functionEvaluation_
;
139
++gradientEvaluation_;
140
functionValue_
=
objectiveFunction_
.valueAndGradient(grad_f, x);
141
statusFunction_
.writeStatus(
functionEvaluation_
, gradientEvaluation_,
142
currentValue_
,
functionValue_
);
143
return
functionValue_
;
144
}
145
146
inline
void
Problem::reset
() {
147
functionEvaluation_
= gradientEvaluation_ = 0;
148
functionValue_
= squaredNorm_ = 0;
149
}
150
151
}
// namespace QuantLib
152
153
#endif
Method.hpp
Abstract optimization method class.
ObjectiveFunction.hpp
Optimization objective function class.
OpenMD::DynamicVector
Dynamically-sized vector class.
Definition
DynamicVector.hpp:74
OpenMD::StatusFunction
Definition
StatusFunction.hpp:11
QuantLib::Constraint
Base constraint class.
Definition
Constraint.hpp:35
QuantLib::ObjectiveFunction
Objective function abstract class for optimization problem.
Definition
ObjectiveFunction.hpp:35
QuantLib::Problem::objectiveFunction
ObjectiveFunction & objectiveFunction() const
Objective function.
Definition
Problem.hpp:68
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::gradientEvaluation
int gradientEvaluation() const
number of evaluation of objective function gradient
Definition
Problem.hpp:98
QuantLib::Problem::constraint_
Constraint & constraint_
Constraint.
Definition
Problem.hpp:108
QuantLib::Problem::currentValue_
DynamicVector< RealType > currentValue_
current value of the local minimum
Definition
Problem.hpp:110
QuantLib::Problem::functionEvaluation
int functionEvaluation() const
number of evaluation of objective function
Definition
Problem.hpp:95
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::objectiveFunction_
ObjectiveFunction & objectiveFunction_
Unconstrained objective function.
Definition
Problem.hpp:106
QuantLib::Problem::Problem
Problem(ObjectiveFunction &objectiveFunction, Constraint &constraint, OpenMD::StatusFunction &statFunc, const DynamicVector< RealType > &initialValue=DynamicVector< RealType >())
default constructor
Definition
Problem.hpp:40
QuantLib::Problem::functionEvaluation_
int functionEvaluation_
number of evaluation of objective function and its gradient
Definition
Problem.hpp:115
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::statusFunction_
StatusFunction & statusFunction_
status function
Definition
Problem.hpp:117
QuantLib::Problem::functionValue_
RealType functionValue_
function and gradient norm values at the curentValue_ (i.e. the last step)
Definition
Problem.hpp:113
QuantLib::Problem::reset
void reset()
Definition
Problem.hpp:146
QuantLib::Problem::valueAndGradient
RealType valueAndGradient(DynamicVector< RealType > &grad_f, const DynamicVector< RealType > &x)
call objective function computation and it gradient
Definition
Problem.hpp:136
QuantLib::Problem::currentValue
const DynamicVector< RealType > & currentValue() const
current value of the local minimum
Definition
Problem.hpp:77
optimization
Problem.hpp
Generated on
for OpenMD by
1.17.0