OpenMD 3.1
Molecular Dynamics in the Open
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
31#include "optimization/StatusFunction.hpp"
32
33namespace QuantLib {
34
35 class Constraint;
36 //! Constrained optimization problem
37 class Problem {
38 public:
39 //! default constructor
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
59
60 //! call objective function computation and it gradient
63
64 //! Constraint
65 Constraint& constraint() const { return constraint_; }
66
67 //! Objective function
69
70 void setCurrentValue(const DynamicVector<RealType>& currentValue) {
72 statusFunction_.writeStatus(functionEvaluation_, gradientEvaluation_,
74 }
75
76 //! current value of the local minimum
78 return currentValue_;
79 }
80
81 void setFunctionValue(RealType 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
96
97 //! number of evaluation of objective function gradient
98 int gradientEvaluation() const { return gradientEvaluation_; }
99
100 RealType DotProduct(DynamicVector<RealType>& v1,
102 RealType computeGradientNormValue(DynamicVector<RealType>& grad_f);
103
104 protected:
105 //! Unconstrained objective function
107 //! Constraint
109 //! current value of the local minimum
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
118 };
119
120 // inline definitions
121 inline RealType Problem::value(const DynamicVector<RealType>& x) {
124 statusFunction_.writeStatus(functionEvaluation_, gradientEvaluation_,
126
127 return functionValue_;
128 }
129
131 const DynamicVector<RealType>& x) {
132 ++gradientEvaluation_;
133 objectiveFunction_.gradient(grad_f, x);
134 }
135
137 const DynamicVector<RealType>& x) {
139 ++gradientEvaluation_;
141 statusFunction_.writeStatus(functionEvaluation_, gradientEvaluation_,
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
Abstract optimization method class.
Optimization objective function class.
Dynamically-sized vector class.
Base constraint class.
Objective function abstract class for optimization problem.
virtual RealType value(const DynamicVector< RealType > &x)=0
method to overload to compute the objective function value in x
virtual RealType valueAndGradient(DynamicVector< RealType > &grad, const DynamicVector< RealType > &x)
method to overload to compute grad_f, the first derivative
virtual void gradient(DynamicVector< RealType > &grad, const DynamicVector< RealType > &x)
method to overload to compute grad_f, the first derivative of
Constrained optimization problem.
Definition Problem.hpp:37
ObjectiveFunction & objectiveFunction() const
Objective function.
Definition Problem.hpp:68
void gradient(DynamicVector< RealType > &grad_f, const DynamicVector< RealType > &x)
call objective function gradient computation and increment
Definition Problem.hpp:130
int gradientEvaluation() const
number of evaluation of objective function gradient
Definition Problem.hpp:98
Constraint & constraint_
Constraint.
Definition Problem.hpp:108
DynamicVector< RealType > currentValue_
current value of the local minimum
Definition Problem.hpp:110
int functionEvaluation() const
number of evaluation of objective function
Definition Problem.hpp:95
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
ObjectiveFunction & objectiveFunction_
Unconstrained objective function.
Definition Problem.hpp:106
Problem(ObjectiveFunction &objectiveFunction, Constraint &constraint, OpenMD::StatusFunction &statFunc, const DynamicVector< RealType > &initialValue=DynamicVector< RealType >())
default constructor
Definition Problem.hpp:40
int functionEvaluation_
number of evaluation of objective function and its gradient
Definition Problem.hpp:115
RealType gradientNormValue() const
value of objective function gradient norm
Definition Problem.hpp:92
Constraint & constraint() const
Constraint.
Definition Problem.hpp:65
StatusFunction & statusFunction_
status function
Definition Problem.hpp:117
RealType functionValue_
function and gradient norm values at the curentValue_ (i.e. the last step)
Definition Problem.hpp:113
RealType valueAndGradient(DynamicVector< RealType > &grad_f, const DynamicVector< RealType > &x)
call objective function computation and it gradient
Definition Problem.hpp:136
const DynamicVector< RealType > & currentValue() const
current value of the local minimum
Definition Problem.hpp:77