ROL
ROL_PH_ErrorObjective.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_ERROROBJECTIVE_H
45#define PH_ERROROBJECTIVE_H
46
47#include "ROL_Objective.hpp"
49
56namespace ROL {
57
58template <class Real>
59class PH_ErrorObjective : public Objective<Real> {
60private:
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 }
84 obj_->gradient(*g_,x,tol);
86 }
87 }
88
89public:
90
92 ParameterList &parlist)
93 : obj_(obj),
94 isValueComputed_(false),
96 isGradientComputed_(false) {
97 std::string risk = parlist.sublist("SOL").sublist("Error Measure").get("Name","Least Squares");
99 switch(ed) {
101 quad_ = makePtr<MeanVarianceQuadrangle<Real>>(parlist); break;
103 quad_ = makePtr<TruncatedMeanQuadrangle<Real>>(parlist); break;
105 quad_ = makePtr<QuantileQuadrangle<Real>>(parlist); break;
107 quad_ = makePtr<MoreauYosidaCVaR<Real>>(parlist); break;
109 quad_ = makePtr<GenMoreauYosidaCVaR<Real>>(parlist); break;
111 quad_ = makePtr<LogExponentialQuadrangle<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 error measure type " << risk << "!");
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 err = quad_->error(val_,0);
131 return err;
132 }
133
134 void gradient( Vector<Real> &g, const Vector<Real> &x, Real &tol ) {
135 getValue(x,tol);
136 Real err = quad_->error(val_,1);
137 getGradient(x,tol);
138 g.set(*g_); g.scale(err);
139 }
140
141 void hessVec( Vector<Real> &hv, const Vector<Real> &v, const Vector<Real> &x, Real &tol ) {
142 getValue(x,tol);
143 Real err1 = quad_->error(val_,1);
144 Real err2 = quad_->error(val_,2);
145 getGradient(x,tol);
146 //Real gv = v.dot(g_->dual());
147 Real gv = v.apply(*g_);
148 obj_->hessVec(hv,v,x,tol);
149 hv.scale(err1); hv.axpy(err2*gv,*g_);
150 }
151
152 void setParameter(const std::vector<Real> &param) {
153 obj_->setParameter(param);
155 }
156
157};
158
159}
160#endif
Provides the interface to evaluate objective functions.
virtual void setParameter(const std::vector< Real > &param)
Provides the interface for the progressive hedging error objective.
Ptr< ExpectationQuad< Real > > quad_
void getGradient(const Vector< Real > &x, Real &tol)
Real value(const Vector< Real > &x, Real &tol)
Compute value.
const Ptr< Objective< Real > > obj_
PH_ErrorObjective(const Ptr< Objective< Real > > &obj, ParameterList &parlist)
void getValue(const Vector< Real > &x, Real &tol)
void setParameter(const std::vector< Real > &param)
void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
void update(const Vector< Real > &x, bool flag=true, int iter=-1)
Update objective function.
Defines the linear algebra or vector space interface.
virtual Real apply(const Vector< Real > &x) const
Apply to a dual vector. This is equivalent to the call .
virtual void set(const Vector &x)
Set where .
virtual void scale(const Real alpha)=0
Compute where .
virtual const Vector & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis,...
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
EErrorMeasure StringToEErrorMeasure(std::string s)
@ ERRORMEASURE_QUANTILEQUADRANGLE
@ ERRORMEASURE_SMOOTHEDWORSTCASEQUADRANGLE
@ ERRORMEASURE_LOGEXPONENTIALQUADRANGLE
@ ERRORMEASURE_MEANVARIANCEQUADRANGLE
@ ERRORMEASURE_TRUNCATEDMEANQUADRANGLE
@ ERRORMEASURE_GENMOREAUYOSIDACVAR
@ ERRORMEASURE_LOGQUANTILEQUADRANGLE