ROL
ROL_PH_ErrorObjective.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 PH_ERROROBJECTIVE_H
11 #define PH_ERROROBJECTIVE_H
12 
13 #include "ROL_Objective.hpp"
15 
22 namespace ROL {
23 
24 template <class Real>
25 class PH_ErrorObjective : public Objective<Real> {
26 private:
27  const Ptr<Objective<Real>> obj_;
28  Ptr<ExpectationQuad<Real>> quad_;
29 
31  Real val_;
32 
35  Ptr<Vector<Real>> g_;
36 
37  void getValue(const Vector<Real> &x, Real &tol) {
38  if (!isValueComputed_) {
39  val_ = obj_->value(x,tol);
40  isValueComputed_ = true;
41  }
42  }
43 
44  void getGradient(const Vector<Real> &x, Real &tol) {
46  g_ = x.dual().clone();
48  }
49  if (!isGradientComputed_) {
50  obj_->gradient(*g_,x,tol);
51  isGradientComputed_ = true;
52  }
53  }
54 
55 public:
56 
58  ParameterList &parlist)
59  : obj_(obj),
60  isValueComputed_(false),
62  isGradientComputed_(false) {
63  std::string risk = parlist.sublist("SOL").sublist("Error Measure").get("Name","Least Squares");
65  switch(ed) {
67  quad_ = makePtr<MeanVarianceQuadrangle<Real>>(parlist); break;
69  quad_ = makePtr<TruncatedMeanQuadrangle<Real>>(parlist); break;
71  quad_ = makePtr<QuantileQuadrangle<Real>>(parlist); break;
73  quad_ = makePtr<MoreauYosidaCVaR<Real>>(parlist); break;
75  quad_ = makePtr<GenMoreauYosidaCVaR<Real>>(parlist); break;
77  quad_ = makePtr<LogExponentialQuadrangle<Real>>(parlist); break;
79  quad_ = makePtr<LogQuantileQuadrangle<Real>>(parlist); break;
81  quad_ = makePtr<SmoothedWorstCaseQuadrangle<Real>>(parlist); break;
82  default:
83  ROL_TEST_FOR_EXCEPTION(true,std::invalid_argument,
84  "Invalid error measure type " << risk << "!");
85  }
86  }
87 
88  void update( const Vector<Real> &x, bool flag = true, int iter = -1 ) {
89  obj_->update(x,flag,iter);
90  isValueComputed_ = false;
91  isGradientComputed_ = false;
92  }
93 
94  Real value( const Vector<Real> &x, Real &tol ) {
95  getValue(x,tol);
96  Real err = quad_->error(val_,0);
97  return err;
98  }
99 
100  void gradient( Vector<Real> &g, const Vector<Real> &x, Real &tol ) {
101  getValue(x,tol);
102  Real err = quad_->error(val_,1);
103  getGradient(x,tol);
104  g.set(*g_); g.scale(err);
105  }
106 
107  void hessVec( Vector<Real> &hv, const Vector<Real> &v, const Vector<Real> &x, Real &tol ) {
108  getValue(x,tol);
109  Real err1 = quad_->error(val_,1);
110  Real err2 = quad_->error(val_,2);
111  getGradient(x,tol);
112  //Real gv = v.dot(g_->dual());
113  Real gv = v.apply(*g_);
114  obj_->hessVec(hv,v,x,tol);
115  hv.scale(err1); hv.axpy(err2*gv,*g_);
116  }
117 
118  void setParameter(const std::vector<Real> &param) {
119  obj_->setParameter(param);
121  }
122 
123 };
124 
125 }
126 #endif
Provides the interface to evaluate objective functions.
virtual const Vector & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
Definition: ROL_Vector.hpp:192
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
const Ptr< Objective< Real > > obj_
virtual void scale(const Real alpha)=0
Compute where .
virtual Real apply(const Vector< Real > &x) const
Apply to a dual vector. This is equivalent to the call .
Definition: ROL_Vector.hpp:204
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
Definition: ROL_Vector.hpp:119
void update(const Vector< Real > &x, bool flag=true, int iter=-1)
Update objective function.
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:46
void getValue(const Vector< Real > &x, Real &tol)
Real value(const Vector< Real > &x, Real &tol)
Compute value.
Provides the interface for the progressive hedging error objective.
void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
Ptr< ExpectationQuad< Real > > quad_
virtual void setParameter(const std::vector< Real > &param)
EErrorMeasure StringToEErrorMeasure(std::string s)
virtual void set(const Vector &x)
Set where .
Definition: ROL_Vector.hpp:175
PH_ErrorObjective(const Ptr< Objective< Real >> &obj, ParameterList &parlist)
void setParameter(const std::vector< Real > &param)
Ptr< Vector< Real > > g_
void getGradient(const Vector< Real > &x, Real &tol)