ROL
ROL_PH_RegretObjective.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_REGRETOBJECTIVE_H
11 #define PH_REGRETOBJECTIVE_H
12 
13 #include "ROL_Objective.hpp"
15 
22 namespace ROL {
23 
24 template <class Real>
25 class PH_RegretObjective : 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 regret = parlist.sublist("SOL").sublist("Regret Measure").get("Name","Mean Absolute Loss");
65  switch(ed) {
67  quad_ = makePtr<QuantileQuadrangle<Real>>(parlist); break;
69  quad_ = makePtr<MoreauYosidaCVaR<Real>>(parlist); break;
71  quad_ = makePtr<GenMoreauYosidaCVaR<Real>>(parlist); break;
73  quad_ = makePtr<LogExponentialQuadrangle<Real>>(parlist); break;
75  quad_ = makePtr<MeanVarianceQuadrangle<Real>>(parlist); break;
77  quad_ = makePtr<TruncatedMeanQuadrangle<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 regret measure type " << regret << "!");
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 reg = quad_->regret(val_,0);
97  return reg;
98  }
99 
100  void gradient( Vector<Real> &g, const Vector<Real> &x, Real &tol ) {
101  getValue(x,tol);
102  Real reg = quad_->regret(val_,1);
103  getGradient(x,tol);
104  g.set(*g_); g.scale(reg);
105  }
106 
107  void hessVec( Vector<Real> &hv, const Vector<Real> &v, const Vector<Real> &x, Real &tol ) {
108  getValue(x,tol);
109  Real reg1 = quad_->regret(val_,1);
110  Real reg2 = quad_->regret(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(reg1); hv.axpy(reg2*gv,*g_);
116  }
117 
118  void setParameter(const std::vector<Real> &param) {
119  obj_->setParameter(param);
121  }
122 
123 };
124 
125 }
126 #endif
Ptr< ExpectationQuad< Real > > quad_
PH_RegretObjective(const Ptr< Objective< Real >> &obj, ParameterList &parlist)
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.
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.
void setParameter(const std::vector< Real > &param)
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:46
Real value(const Vector< Real > &x, Real &tol)
Compute value.
ERegretMeasure StringToERegretMeasure(std::string s)
Provides the interface for the progressive hedging regret objective.
virtual void setParameter(const std::vector< Real > &param)
void getGradient(const Vector< Real > &x, Real &tol)
const Ptr< Objective< Real > > obj_
virtual void set(const Vector &x)
Set where .
Definition: ROL_Vector.hpp:175
void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
void getValue(const Vector< Real > &x, Real &tol)