Logo
Fully annotated reference manual - version 1.8.12
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
Problem_MT Class Reference

Constrained optimization problem. More...

#include <qle/math/problem_mt.hpp>

+ Collaboration diagram for Problem_MT:

Public Member Functions

 Problem_MT (const std::vector< QuantLib::ext::shared_ptr< CostFunction > > &costFunctions, Constraint &constraint, const Array &initialValue=Array())
 
void reset ()
 
Real value (const Size i, const Array &x)
 call cost function i computation and increment evaluation counter More...
 
Array values (const Size i, const Array &x)
 call cost values i computation and increment evaluation counter More...
 
void gradient (const Size i, Array &grad_f, const Array &x)
 call cost function i gradient computation and increment More...
 
Real valueAndGradient (const Size i, Array &grad_f, const Array &x)
 call cost function i computation and it gradient More...
 
Constraintconstraint () const
 Constraint. More...
 
Integer availableCostFunctions () const
 number of available independent cost functions More...
 
QuantLib::ext::shared_ptr< CostFunction > costFunction (const Size i) const
 Cost function. More...
 
const std::vector< QuantLib::ext::shared_ptr< CostFunction > > & costFunctions () const
 Cost funcionts. More...
 
void setCurrentValue (const Array &currentValue)
 
const Array & currentValue () const
 current value of the local minimum More...
 
void setFunctionValue (Real functionValue)
 
Real functionValue () const
 value of cost function More...
 
void setGradientNormValue (Real squaredNorm)
 
Real gradientNormValue () const
 value of cost function gradient norm More...
 
Integer functionEvaluation () const
 number of evaluation of cost function More...
 
Integer gradientEvaluation () const
 number of evaluation of cost function gradient More...
 

Protected Attributes

std::vector< QuantLib::ext::shared_ptr< CostFunction > > costFunctions_
 Unconstrained cost function. More...
 
Constraintconstraint_
 Constraint. More...
 
Array currentValue_
 current value of the local minimum More...
 
Real functionValue_
 function and gradient norm values at the curentValue_ (i.e. the last step) More...
 
Real squaredNorm_
 
std::vector< Integer > functionEvaluation_
 number of evaluation of cost function and its gradient More...
 
std::vector< Integer > gradientEvaluation_
 

Detailed Description

Constrained optimization problem.

Warning:
The passed Constraint instances are stored by reference. The user of this class must make sure that they are not destroyed before the Problem instance.

Definition at line 64 of file problem_mt.hpp.

Constructor & Destructor Documentation

◆ Problem_MT()

Problem_MT ( const std::vector< QuantLib::ext::shared_ptr< CostFunction > > &  costFunctions,
Constraint constraint,
const Array &  initialValue = Array() 
)

The requirement is that the cost functions can be evaluated from multiple threads without data races, which can e.g. be done by complete separation of the underlying data. Note that some methods in this class are not thread safe, namely reset, setCurrentValue, setFunctionValue, setGradientNormValue, i.e. those can not be used from several threads in a mt optimizer

Definition at line 72 of file problem_mt.hpp.

76 currentValue_(initialValue), functionEvaluation_(costFunctions.size(),0),
std::vector< Integer > functionEvaluation_
number of evaluation of cost function and its gradient
Definition: problem_mt.hpp:146
Array currentValue_
current value of the local minimum
Definition: problem_mt.hpp:142
const std::vector< QuantLib::ext::shared_ptr< CostFunction > > & costFunctions() const
Cost funcionts.
Definition: problem_mt.hpp:108
Constraint & constraint_
Constraint.
Definition: problem_mt.hpp:140
Constraint & constraint() const
Constraint.
Definition: problem_mt.hpp:99
std::vector< QuantLib::ext::shared_ptr< CostFunction > > costFunctions_
Unconstrained cost function.
Definition: problem_mt.hpp:138
std::vector< Integer > gradientEvaluation_
Definition: problem_mt.hpp:146

Member Function Documentation

◆ reset()

void reset ( )
Warning:
it does not reset the current minumum to any initial value

Definition at line 172 of file problem_mt.hpp.

172 {
173 for(Size i=0;i<costFunctions_.size();++i) {
175 }
176 functionValue_ = squaredNorm_ = Null<Real>();
177 }
Real functionValue_
function and gradient norm values at the curentValue_ (i.e. the last step)
Definition: problem_mt.hpp:144

◆ value()

Real value ( const Size  i,
const Array &  x 
)

call cost function i computation and increment evaluation counter

Definition at line 150 of file problem_mt.hpp.

150 {
151 ++functionEvaluation_.at(i);
152 return costFunctions_.at(i)->value(x);
153 }

◆ values()

Array values ( const Size  i,
const Array &  x 
)

call cost values i computation and increment evaluation counter

Definition at line 155 of file problem_mt.hpp.

155 {
156 ++functionEvaluation_.at(i);
157 return costFunctions_.at(i)->values(x);
158 }

◆ gradient()

void gradient ( const Size  i,
Array &  grad_f,
const Array &  x 
)

call cost function i gradient computation and increment

Definition at line 160 of file problem_mt.hpp.

160 {
161 ++gradientEvaluation_.at(i);
162 costFunctions_[i]->gradient(grad_f, x);
163 }

◆ valueAndGradient()

Real valueAndGradient ( const Size  i,
Array &  grad_f,
const Array &  x 
)

call cost function i computation and it gradient

Definition at line 165 of file problem_mt.hpp.

166 {
167 ++functionEvaluation_.at(i);
168 ++gradientEvaluation_.at(i);
169 return costFunctions_[i]->valueAndGradient(grad_f, x);
170 }

◆ constraint()

Constraint & constraint ( ) const

Constraint.

Definition at line 99 of file problem_mt.hpp.

99{ return constraint_; }
+ Here is the caller graph for this function:

◆ availableCostFunctions()

Integer availableCostFunctions ( ) const

number of available independent cost functions

Definition at line 102 of file problem_mt.hpp.

102{ return costFunctions_.size(); }

◆ costFunction()

QuantLib::ext::shared_ptr< CostFunction > costFunction ( const Size  i) const

Cost function.

Definition at line 105 of file problem_mt.hpp.

105{ return costFunctions_.at(i); }

◆ costFunctions()

const std::vector< QuantLib::ext::shared_ptr< CostFunction > > & costFunctions ( ) const

Cost funcionts.

Definition at line 108 of file problem_mt.hpp.

108{ return costFunctions_; }
+ Here is the caller graph for this function:

◆ setCurrentValue()

void setCurrentValue ( const Array &  currentValue)

Definition at line 110 of file problem_mt.hpp.

110 {
112 }
const Array & currentValue() const
current value of the local minimum
Definition: problem_mt.hpp:115
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ currentValue()

const Array & currentValue ( ) const

current value of the local minimum

Definition at line 115 of file problem_mt.hpp.

115{ return currentValue_; }
+ Here is the caller graph for this function:

◆ setFunctionValue()

void setFunctionValue ( Real  functionValue)

Definition at line 117 of file problem_mt.hpp.

117 {
119 }
Real functionValue() const
value of cost function
Definition: problem_mt.hpp:122
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ functionValue()

Real functionValue ( ) const

value of cost function

Definition at line 122 of file problem_mt.hpp.

122{ return functionValue_; }
+ Here is the caller graph for this function:

◆ setGradientNormValue()

void setGradientNormValue ( Real  squaredNorm)

Definition at line 124 of file problem_mt.hpp.

124 {
125 squaredNorm_=squaredNorm;
126 }

◆ gradientNormValue()

Real gradientNormValue ( ) const

value of cost function gradient norm

Definition at line 128 of file problem_mt.hpp.

128{ return squaredNorm_; }

◆ functionEvaluation()

Integer functionEvaluation ( ) const

number of evaluation of cost function

Definition at line 179 of file problem_mt.hpp.

179 {
180 Integer tmp = 0;
181 for (Size i = 0; i < costFunctions_.size(); ++i)
182 tmp += functionEvaluation_.at(i);
183 return tmp;
184 }

◆ gradientEvaluation()

Integer gradientEvaluation ( ) const

number of evaluation of cost function gradient

Definition at line 186 of file problem_mt.hpp.

186 {
187 Integer tmp = 0;
188 for (Size i = 0; i < costFunctions_.size(); ++i)
189 tmp += gradientEvaluation_.at(i);
190 return tmp;
191 }

Member Data Documentation

◆ costFunctions_

std::vector<QuantLib::ext::shared_ptr<CostFunction> > costFunctions_
protected

Unconstrained cost function.

Definition at line 138 of file problem_mt.hpp.

◆ constraint_

Constraint& constraint_
protected

Constraint.

Definition at line 140 of file problem_mt.hpp.

◆ currentValue_

Array currentValue_
protected

current value of the local minimum

Definition at line 142 of file problem_mt.hpp.

◆ functionValue_

Real functionValue_
protected

function and gradient norm values at the curentValue_ (i.e. the last step)

Definition at line 144 of file problem_mt.hpp.

◆ squaredNorm_

Real squaredNorm_
protected

Definition at line 144 of file problem_mt.hpp.

◆ functionEvaluation_

std::vector<Integer> functionEvaluation_
protected

number of evaluation of cost function and its gradient

Definition at line 146 of file problem_mt.hpp.

◆ gradientEvaluation_

std::vector<Integer> gradientEvaluation_
protected

Definition at line 146 of file problem_mt.hpp.