ROL
ROL_MeanSemiDeviationFromTarget.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 ROL_MEANSEMIDEVIATIONFROMTARGET_HPP
11 #define ROL_MEANSEMIDEVIATIONFROMTARGET_HPP
12 
14 #include "ROL_PlusFunction.hpp"
15 
35 namespace ROL {
36 
37 template<class Real>
39 private:
40  Ptr<PlusFunction<Real> > plusFunction_;
41  Real coeff_, target_;
42 
48 
51 
56 
57  void checkInputs(void) const {
58  const Real zero(0);
59  ROL_TEST_FOR_EXCEPTION((coeff_ < zero), std::invalid_argument,
60  ">>> ERROR (ROL::MeanPlusSemiDeviationFromTarget): Coefficient must be positive!");
61  ROL_TEST_FOR_EXCEPTION(plusFunction_ == nullPtr, std::invalid_argument,
62  ">>> ERROR (ROL::MeanSemiDeviation): PlusFunction pointer is null!");
63  }
64 
65 public:
66 
73  MeanSemiDeviationFromTarget( const Real coeff, const Real target,
74  const Ptr<PlusFunction<Real>> &pf )
75  : RandVarFunctional<Real>(), plusFunction_(pf), coeff_(coeff), target_(target) {
76  checkInputs();
77  }
78 
89  MeanSemiDeviationFromTarget( ROL::ParameterList &parlist )
90  : RandVarFunctional<Real>() {
91  ROL::ParameterList &list
92  = parlist.sublist("SOL").sublist("Risk Measure").sublist("Mean Plus Semi-Deviation From Target");
93  // Check inputs
94  coeff_ = list.get<Real>("Coefficient");
95  target_ = list.get<Real>("Target");
96  // Build (approximate) plus function
97  plusFunction_ = makePtr<PlusFunction<Real>>(list);
98  // Check Inputs
99  checkInputs();
100  }
101 
103  const Vector<Real> &x,
104  const std::vector<Real> &xstat,
105  Real &tol) {
106  Real val = computeValue(obj,x,tol);
107  Real pf = plusFunction_->evaluate(val-target_,0);
108  val_ += weight_ * (val + coeff_ * pf);
109  }
110 
111  Real getValue(const Vector<Real> &x,
112  const std::vector<Real> &xstat,
113  SampleGenerator<Real> &sampler) {
114  Real ev(0);
115  sampler.sumAll(&val_,&ev,1);
116  return ev;
117  }
118 
120  const Vector<Real> &x,
121  const std::vector<Real> &xstat,
122  Real &tol) {
123  const Real one(1);
124  Real val = computeValue(obj,x,tol);
125  Real pf = plusFunction_->evaluate(val-target_,1);
126  computeGradient(*dualVector_,obj,x,tol);
127  g_->axpy(weight_ * (one + coeff_ * pf), *dualVector_);
128  }
129 
131  std::vector<Real> &gstat,
132  const Vector<Real> &x,
133  const std::vector<Real> &xstat,
134  SampleGenerator<Real> &sampler) {
135  sampler.sumAll(*g_, g);
136  }
137 
139  const Vector<Real> &v,
140  const std::vector<Real> &vstat,
141  const Vector<Real> &x,
142  const std::vector<Real> &xstat,
143  Real &tol) {
144  const Real one(1);
145  Real val = computeValue(obj,x,tol);
146  Real pf1 = plusFunction_->evaluate(val-target_,1);
147  Real pf2 = plusFunction_->evaluate(val-target_,2);
148  Real gv = computeGradVec(*dualVector_,obj,v,x,tol);
149  hv_->axpy(weight_ * coeff_ * pf2 * gv, *dualVector_);
150  computeHessVec(*dualVector_,obj,v,x,tol);
151  hv_->axpy(weight_ * (one + coeff_ * pf1), *dualVector_);
152  }
153 
155  std::vector<Real> &hvstat,
156  const Vector<Real> &v,
157  const std::vector<Real> &vstat,
158  const Vector<Real> &x,
159  const std::vector<Real> &xstat,
160  SampleGenerator<Real> &sampler) {
161  sampler.sumAll(*hv_, hv);
162  }
163 };
164 
165 }
166 
167 #endif
Provides the interface to evaluate objective functions.
void computeHessVec(Vector< Real > &hv, Objective< Real > &obj, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Ptr< Vector< Real > > g_
Real computeValue(Objective< Real > &obj, const Vector< Real > &x, Real &tol)
Ptr< Vector< Real > > hv_
void updateHessVec(Objective< Real > &obj, const Vector< Real > &v, const std::vector< Real > &vstat, const Vector< Real > &x, const std::vector< Real > &xstat, Real &tol)
Update internal risk measure storage for Hessian-time-a-vector computation.
Ptr< Vector< Real > > dualVector_
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:46
Real getValue(const Vector< Real > &x, const std::vector< Real > &xstat, SampleGenerator< Real > &sampler)
Return risk measure value.
void sumAll(Real *input, Real *output, int dim) const
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0_ zero()
void updateGradient(Objective< Real > &obj, const Vector< Real > &x, const std::vector< Real > &xstat, Real &tol)
Update internal risk measure storage for gradient computation.
MeanSemiDeviationFromTarget(ROL::ParameterList &parlist)
Constructor.
void getGradient(Vector< Real > &g, std::vector< Real > &gstat, const Vector< Real > &x, const std::vector< Real > &xstat, SampleGenerator< Real > &sampler)
Return risk measure (sub)gradient.
void updateValue(Objective< Real > &obj, const Vector< Real > &x, const std::vector< Real > &xstat, Real &tol)
Update internal storage for value computation.
void getHessVec(Vector< Real > &hv, std::vector< Real > &hvstat, const Vector< Real > &v, const std::vector< Real > &vstat, const Vector< Real > &x, const std::vector< Real > &xstat, SampleGenerator< Real > &sampler)
Return risk measure Hessian-times-a-vector.
void computeGradient(Vector< Real > &g, Objective< Real > &obj, const Vector< Real > &x, Real &tol)
Real computeGradVec(Vector< Real > &g, Objective< Real > &obj, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Provides the interface to implement any functional that maps a random variable to a (extended) real n...
MeanSemiDeviationFromTarget(const Real coeff, const Real target, const Ptr< PlusFunction< Real >> &pf)
Constructor.