ROL
ROL_PH_Objective.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_OBJECTIVE_H
11 #define PH_OBJECTIVE_H
12 
13 #include "ROL_PH_RiskObjective.hpp"
17 #include "ROL_PH_ProbObjective.hpp"
18 #include "ROL_PH_bPOEObjective.hpp"
19 
26 namespace ROL {
27 
28 template <class Real>
29 class PH_Objective : public Objective<Real> {
30 private:
31  Ptr<Objective<Real>> obj_;
32  Ptr<const Vector<Real>> xbar_, w_;
33  Ptr<Vector<Real>> xprimal_;
35 
36 public:
37 
38  PH_Objective(const Ptr<Objective<Real>> &obj,
39  const Ptr<Vector<Real>> &x,
40  const Real penaltyParam,
41  ParameterList &parlist)
42  : xbar_(nullPtr), w_(nullPtr), xprimal_(nullPtr),
43  penaltyParam_(penaltyParam) {
44  xprimal_ = x->clone();
45  std::string type = parlist.sublist("SOL").get("Type","Risk Neutral");
46  if (type == "Risk Averse") {
47  obj_ = makePtr<PH_RiskObjective<Real>>(obj,parlist);
48  }
49  else if (type == "Deviation") {
50  obj_ = makePtr<PH_DeviationObjective<Real>>(obj,parlist);
51  }
52  else if (type == "Regret") {
53  obj_ = makePtr<PH_RegretObjective<Real>>(obj,parlist);
54  }
55  else if (type == "Error") {
56  obj_ = makePtr<PH_ErrorObjective<Real>>(obj,parlist);
57  }
58  else if (type == "Probability") {
59  std::string prob = parlist.sublist("SOL").sublist("Probability").get("Name","bPOE");
60  if (prob == "Smoothed POE") {
61  obj_ = makePtr<PH_ProbObjective<Real>>(obj,parlist);
62  }
63  else if (prob == "bPOE") {
64  obj_ = makePtr<PH_bPOEObjective<Real>>(obj,parlist);
65  }
66  else {
67  ROL_TEST_FOR_EXCEPTION(true,std::invalid_argument,
68  "Invalid probability type " << prob << "!");
69  }
70  }
71  else if (type == "Risk Neutral") {
72  obj_ = obj;
73  }
74  else {
75  ROL_TEST_FOR_EXCEPTION(true,std::invalid_argument,
76  "Invalid stochastic component type " << type << "!");
77  }
78  }
79 
80  void setData(const Ptr<const Vector<Real>> &xbar,
81  const Ptr<const Vector<Real>> &w,
82  const Real penaltyParam) {
83  xbar_ = xbar;
84  w_ = w;
85  penaltyParam_ = penaltyParam;
86  }
87 
88  void update( const Vector<Real> &x, bool flag = true, int iter = -1 ) {
89  obj_->update(x,flag,iter);
90  }
91 
92  Real value( const Vector<Real> &x, Real &tol ) {
93  const Real half(0.5), one(1);
94  Real val = obj_->value(x,tol);
95  Real wx = x.dot(*w_);
96  xprimal_->set(x);
97  xprimal_->axpy(-one,*xbar_);
98  Real xx = xprimal_->dot(*xprimal_);
99  return val + wx + half*penaltyParam_*xx;
100  }
101 
102  void gradient( Vector<Real> &g, const Vector<Real> &x, Real &tol ) {
103  obj_->gradient(g,x,tol);
104  xprimal_->set(*w_);
105  xprimal_->axpy(penaltyParam_,x);
106  xprimal_->axpy(-penaltyParam_,*xbar_);
107  g.plus(xprimal_->dual());
108  }
109 
110  void hessVec( Vector<Real> &hv, const Vector<Real> &v, const Vector<Real> &x, Real &tol ) {
111  obj_->hessVec(hv,v,x,tol);
112  hv.axpy(penaltyParam_,v.dual());
113  }
114 
115  void setParameter(const std::vector<Real> &param) {
116  obj_->setParameter(param);
118  }
119 
120 };
121 
122 }
123 #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
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:119
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:46
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)