ROL
ROL_RiskLessObjective_Def.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Rapid Optimization Library (ROL) Package
4 //
5 // Copyright 2014 NTESS and the ROL contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef ROL_RISKLESSOBJECTIVE_DEF_HPP
11 #define ROL_RISKLESSOBJECTIVE_DEF_HPP
12 
13 namespace ROL {
14 
15 template<typename Real>
17 
18 template<typename Real>
19 void RiskLessObjective<Real>::update( const Vector<Real> &x, UpdateType type, int iter ) {
20  Ptr<const Vector<Real>> x0
21  = dynamic_cast<const RiskVector<Real>&>(x).getVector();
22  obj_->update(*x0,type,iter);
23 }
24 
25 template<typename Real>
26 void RiskLessObjective<Real>::update( const Vector<Real> &x, bool flag, int iter ) {
27  Ptr<const Vector<Real>> x0
28  = dynamic_cast<const RiskVector<Real>&>(x).getVector();
29  obj_->update(*x0,flag,iter);
30 }
31 
32 template<typename Real>
33 Real RiskLessObjective<Real>::value( const Vector<Real> &x, Real &tol ) {
34  Ptr<const Vector<Real>> x0
35  = dynamic_cast<const RiskVector<Real>&>(x).getVector();
36  return obj_->value(*x0,tol);
37 }
38 
39 template<typename Real>
41  Ptr<Vector<Real>> g0
42  = dynamic_cast<RiskVector<Real>&>(g).getVector();
43  Ptr<const Vector<Real>> x0
44  = dynamic_cast<const RiskVector<Real>&>(x).getVector();
45  obj_->gradient(*g0,*x0,tol);
46 }
47 
48 template<typename Real>
50  const Vector<Real> &x, Real &tol ) {
51  Ptr<Vector<Real>> hv0
52  = dynamic_cast<RiskVector<Real>&>(hv).getVector();
53  Ptr<const Vector<Real>> v0
54  = dynamic_cast<const RiskVector<Real>&>(v).getVector();
55  Ptr<const Vector<Real>> x0
56  = dynamic_cast<const RiskVector<Real>&>(x).getVector();
57  obj_->hessVec(*hv0,*v0,*x0,tol);
58 }
59 
60 template<typename Real>
62  const Vector<Real> &x, Real &tol ) {
63  Ptr<Vector<Real>> Pv0
64  = dynamic_cast<RiskVector<Real>&>(Pv).getVector();
65  Ptr<const Vector<Real>> v0
66  = dynamic_cast<const RiskVector<Real>&>(v).getVector();
67  Ptr<const Vector<Real>> x0
68  = dynamic_cast<const RiskVector<Real>&>(x).getVector();
69  obj_->precond(*Pv0,*v0,*x0,tol);
70 }
71 
72 template<typename Real>
73 void RiskLessObjective<Real>::setParameter(const std::vector<Real> &param) {
75  obj_->setParameter(param);
76 }
77 
78 }
79 
80 #endif
Provides the interface to evaluate objective functions.
void setParameter(const std::vector< Real > &param) override
void precond(Vector< Real > &Pv, const Vector< Real > &v, const Vector< Real > &x, Real &tol) override
Apply preconditioner to vector.
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:46
RiskLessObjective(const Ptr< Objective< Real >> &obj)
void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol) override
Apply Hessian approximation to vector.
void update(const Vector< Real > &x, UpdateType type, int iter=-1) override
Update objective function.
Real value(const Vector< Real > &x, Real &tol) override
Compute value.
virtual void setParameter(const std::vector< Real > &param)
const Ptr< Obj > obj_
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol) override
Compute gradient.