ROL
ROL_ChainRuleObjective.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_CHAIN_RULE_OBJECTIVE_HPP
11#define ROL_CHAIN_RULE_OBJECTIVE_HPP
12
13#include "ROL_Objective.hpp"
14#include "ROL_Constraint.hpp"
15
30namespace ROL {
31
32template<typename Real>
33class ChainRuleObjective : public ROL::Objective<Real> {
34public:
35
43 const Ptr<Constraint<Real>>& con,
44 const Vector<Real>& x,
45 const Vector<Real>& l )
46 : obj_(obj), con_(con), g_(l.clone()), y_(l.dual().clone()), Jv_(l.dual().clone()),
47 HJv_(l.clone()), JtHJv_(x.dual().clone()), tol_(0) {}
48
49 virtual ~ChainRuleObjective() = default;
50
58 virtual void update( const Vector<Real> &x, UpdateType type, int iter = -1 ) {
59 con_->update(x,type,iter);
60 con_->value(*y_,x,tol_);
61 obj_->update(*y_,type,iter);
62 }
63
71 virtual void update( const Vector<Real> &x, bool flag = true, int iter = -1 ) {
72 con_->update(x,flag,iter);
73 con_->value(*y_,x,tol_);
74 obj_->update(*y_,flag,iter);
75 }
76
83 virtual Real value( const Vector<Real> &x, Real &tol ) {
84 con_->value(*y_,x,tol);
85 return obj_->value(*y_,tol);
86 }
87
96 virtual void gradient( Vector<Real> &g, const Vector<Real> &x, Real &tol ) {
97 con_->value(*y_,x,tol);
98 obj_->gradient(*g_,*y_,tol);
99 con_->applyAdjointJacobian(g,*g_,x,tol);
100 }
101
110 virtual void hessVec( Vector<Real> &hv, const Vector<Real> &v, const Vector<Real> &x, Real &tol ) {
111 con_->value(*y_,x,tol);
112 obj_->gradient(*g_,*y_,tol);
113 con_->applyJacobian(*Jv_,v,x,tol);
114 obj_->hessVec(*HJv_,*Jv_,*y_,tol);
115 con_->applyAdjointJacobian(*JtHJv_,*HJv_,x,tol);
116 con_->applyAdjointHessian(hv,*g_,v,x,tol);
117 hv.plus(*JtHJv_);
118 }
119
120private:
121
122 const Ptr<Objective<Real>> obj_;
123 const Ptr<Constraint<Real>> con_;
124 Ptr<Vector<Real>> g_, y_, Jv_, HJv_, JtHJv_;
125 Real tol_;
126
127}; // class ChainRuleObjective
128
129} // namespace ROL
130
131#endif // ROL_CHAIN_RULE_OBJECTIVE_HPP
Defines an objective of the form f(g(x)) where.
virtual Real value(const Vector< Real > &x, Real &tol)
Compute value.
virtual void update(const Vector< Real > &x, bool flag=true, int iter=-1)
Update objective function.
ChainRuleObjective(const Ptr< Objective< Real > > &obj, const Ptr< Constraint< Real > > &con, const Vector< Real > &x, const Vector< Real > &l)
Constructor.
virtual void update(const Vector< Real > &x, UpdateType type, int iter=-1)
Update objective function.
const Ptr< Objective< Real > > obj_
virtual void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
virtual ~ChainRuleObjective()=default
virtual void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
const Ptr< Constraint< Real > > con_
Defines the general constraint operator interface.
Provides the interface to evaluate objective functions.
Defines the linear algebra or vector space interface.
virtual void plus(const Vector &x)=0
Compute , where .