ROL
ROL_PH_RegretObjective.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ************************************************************************
3 //
4 // Rapid Optimization Library (ROL) Package
5 // Copyright (2014) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact lead developers:
38 // Drew Kouri (dpkouri@sandia.gov) and
39 // Denis Ridzal (dridzal@sandia.gov)
40 //
41 // ************************************************************************
42 // @HEADER
43 //
44 #ifndef PH_REGRETOBJECTIVE_H
45 #define PH_REGRETOBJECTIVE_H
46 
47 #include "ROL_Objective.hpp"
49 
56 namespace ROL {
57 
58 template <class Real>
59 class PH_RegretObjective : public Objective<Real> {
60 private:
61  const Ptr<Objective<Real>> obj_;
62  Ptr<ExpectationQuad<Real>> quad_;
63 
65  Real val_;
66 
69  Ptr<Vector<Real>> g_;
70 
71  void getValue(const Vector<Real> &x, Real &tol) {
72  if (!isValueComputed_) {
73  val_ = obj_->value(x,tol);
74  isValueComputed_ = true;
75  }
76  }
77 
78  void getGradient(const Vector<Real> &x, Real &tol) {
80  g_ = x.dual().clone();
82  }
83  if (!isGradientComputed_) {
84  obj_->gradient(*g_,x,tol);
85  isGradientComputed_ = true;
86  }
87  }
88 
89 public:
90 
92  ParameterList &parlist)
93  : obj_(obj),
94  isValueComputed_(false),
96  isGradientComputed_(false) {
97  std::string regret = parlist.sublist("SOL").sublist("Regret Measure").get("Name","Mean Absolute Loss");
99  switch(ed) {
101  quad_ = makePtr<QuantileQuadrangle<Real>>(parlist); break;
103  quad_ = makePtr<MoreauYosidaCVaR<Real>>(parlist); break;
105  quad_ = makePtr<GenMoreauYosidaCVaR<Real>>(parlist); break;
107  quad_ = makePtr<LogExponentialQuadrangle<Real>>(parlist); break;
109  quad_ = makePtr<MeanVarianceQuadrangle<Real>>(parlist); break;
111  quad_ = makePtr<TruncatedMeanQuadrangle<Real>>(parlist); break;
113  quad_ = makePtr<LogQuantileQuadrangle<Real>>(parlist); break;
115  quad_ = makePtr<SmoothedWorstCaseQuadrangle<Real>>(parlist); break;
116  default:
117  ROL_TEST_FOR_EXCEPTION(true,std::invalid_argument,
118  "Invalid regret measure type " << regret << "!");
119  }
120  }
121 
122  void update( const Vector<Real> &x, bool flag = true, int iter = -1 ) {
123  obj_->update(x,flag,iter);
124  isValueComputed_ = false;
125  isGradientComputed_ = false;
126  }
127 
128  Real value( const Vector<Real> &x, Real &tol ) {
129  getValue(x,tol);
130  Real reg = quad_->regret(val_,0);
131  return reg;
132  }
133 
134  void gradient( Vector<Real> &g, const Vector<Real> &x, Real &tol ) {
135  getValue(x,tol);
136  Real reg = quad_->regret(val_,1);
137  getGradient(x,tol);
138  g.set(*g_); g.scale(reg);
139  }
140 
141  void hessVec( Vector<Real> &hv, const Vector<Real> &v, const Vector<Real> &x, Real &tol ) {
142  getValue(x,tol);
143  Real reg1 = quad_->regret(val_,1);
144  Real reg2 = quad_->regret(val_,2);
145  getGradient(x,tol);
146  Real gv = v.dot(g_->dual());
147  obj_->hessVec(hv,v,x,tol);
148  hv.scale(reg1); hv.axpy(reg2*gv,*g_);
149  }
150 
151  void setParameter(const std::vector<Real> &param) {
152  obj_->setParameter(param);
154  }
155 
156 };
157 
158 }
159 #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:226
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
virtual void scale(const Real alpha)=0
Compute where .
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
Definition: ROL_Vector.hpp:153
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:80
virtual Real dot(const Vector &x) const =0
Compute where .
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:209
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)