ROL
ROL_PH_Objective.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_OBJECTIVE_H
45 #define PH_OBJECTIVE_H
46 
47 #include "ROL_PH_RiskObjective.hpp"
51 #include "ROL_PH_ProbObjective.hpp"
52 #include "ROL_PH_bPOEObjective.hpp"
53 
60 namespace ROL {
61 
62 template <class Real>
63 class PH_Objective : public Objective<Real> {
64 private:
65  Ptr<Objective<Real>> obj_;
66  Ptr<const Vector<Real>> xbar_, w_;
67  Ptr<Vector<Real>> xprimal_;
69 
70 public:
71 
72  PH_Objective(const Ptr<Objective<Real>> &obj,
73  const Ptr<Vector<Real>> &x,
74  const Real penaltyParam,
75  ParameterList &parlist)
76  : xbar_(nullPtr), w_(nullPtr), xprimal_(nullPtr),
77  penaltyParam_(penaltyParam) {
78  xprimal_ = x->clone();
79  std::string type = parlist.sublist("SOL").get("Stochastic Component Type","Risk Neutral");
80  if (type == "Risk Averse") {
81  obj_ = makePtr<PH_RiskObjective<Real>>(obj,parlist);
82  }
83  else if (type == "Deviation") {
84  obj_ = makePtr<PH_DeviationObjective<Real>>(obj,parlist);
85  }
86  else if (type == "Regret") {
87  obj_ = makePtr<PH_RegretObjective<Real>>(obj,parlist);
88  }
89  else if (type == "Error") {
90  obj_ = makePtr<PH_ErrorObjective<Real>>(obj,parlist);
91  }
92  else if (type == "Probability") {
93  std::string prob = parlist.sublist("SOL").sublist("Probability").get("Name","bPOE");
94  if (prob == "Smoothed POE") {
95  obj_ = makePtr<PH_ProbObjective<Real>>(obj,parlist);
96  }
97  else if (prob == "bPOE") {
98  obj_ = makePtr<PH_bPOEObjective<Real>>(obj,parlist);
99  }
100  else {
101  ROL_TEST_FOR_EXCEPTION(true,std::invalid_argument,
102  "Invalid probability type " << prob << "!");
103  }
104  }
105  else if (type == "Risk Neutral") {
106  obj_ = obj;
107  }
108  else {
109  ROL_TEST_FOR_EXCEPTION(true,std::invalid_argument,
110  "Invalid stochastic component type " << type << "!");
111  }
112  }
113 
114  void setData(const Ptr<const Vector<Real>> &xbar,
115  const Ptr<const Vector<Real>> &w,
116  const Real penaltyParam) {
117  xbar_ = xbar;
118  w_ = w;
119  penaltyParam_ = penaltyParam;
120  }
121 
122  void update( const Vector<Real> &x, bool flag = true, int iter = -1 ) {
123  obj_->update(x,flag,iter);
124  }
125 
126  Real value( const Vector<Real> &x, Real &tol ) {
127  const Real half(0.5), one(1);
128  Real val = obj_->value(x,tol);
129  Real wx = x.dot(*w_);
130  xprimal_->set(x);
131  xprimal_->axpy(-one,*xbar_);
132  Real xx = xprimal_->dot(*xprimal_);
133  return val + wx + half*penaltyParam_*xx;
134  }
135 
136  void gradient( Vector<Real> &g, const Vector<Real> &x, Real &tol ) {
137  obj_->gradient(g,x,tol);
138  xprimal_->set(*w_);
139  xprimal_->axpy(penaltyParam_,x);
140  xprimal_->axpy(-penaltyParam_,*xbar_);
141  g.plus(xprimal_->dual());
142  }
143 
144  void hessVec( Vector<Real> &hv, const Vector<Real> &v, const Vector<Real> &x, Real &tol ) {
145  obj_->hessVec(hv,v,x,tol);
146  hv.axpy(penaltyParam_,v.dual());
147  }
148 
149  void setParameter(const std::vector<Real> &param) {
150  obj_->setParameter(param);
152  }
153 
154 };
155 
156 }
157 #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:226
Real value(const Vector< Real > &x, Real &tol)
Compute value.
virtual void plus(const Vector &x)=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.
Ptr< Objective< Real > > obj_
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:80
virtual Real dot(const Vector &x) const =0
Compute where .
Provides the interface for the progressive hedging objective.
void setData(const Ptr< const Vector< Real >> &xbar, const Ptr< const Vector< Real >> &w, const Real penaltyParam)
Ptr< const Vector< Real > > w_
void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
virtual void setParameter(const std::vector< Real > &param)
Ptr< Vector< Real > > xprimal_
PH_Objective(const Ptr< Objective< Real >> &obj, const Ptr< Vector< Real >> &x, const Real penaltyParam, ParameterList &parlist)
Ptr< const Vector< Real > > xbar_
void hessVec(Vector< Real > &hv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply Hessian approximation to vector.
void setParameter(const std::vector< Real > &param)