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 
34 namespace ROL {
35 
36 template<class Real>
38 private:
39  Ptr<PlusFunction<Real> > plusFunction_;
40  Real coeff_, target_;
41 
47 
50 
55 
56  void checkInputs(void) const {
57  const Real zero(0);
58  ROL_TEST_FOR_EXCEPTION((coeff_ < zero), std::invalid_argument,
59  ">>> ERROR (ROL::MeanPlusSemiDeviationFromTarget): Coefficient must be positive!");
60  ROL_TEST_FOR_EXCEPTION(plusFunction_ == nullPtr, std::invalid_argument,
61  ">>> ERROR (ROL::MeanSemiDeviation): PlusFunction pointer is null!");
62  }
63 
64 public:
65 
72  MeanSemiDeviationFromTarget( const Real coeff, const Real target,
73  const Ptr<PlusFunction<Real>> &pf )
74  : RandVarFunctional<Real>(), plusFunction_(pf), coeff_(coeff), target_(target) {
75  checkInputs();
76  }
77 
88  MeanSemiDeviationFromTarget( ROL::ParameterList &parlist )
89  : RandVarFunctional<Real>() {
90  ROL::ParameterList &list
91  = parlist.sublist("SOL").sublist("Risk Measure").sublist("Mean Plus Semi-Deviation From Target");
92  // Check inputs
93  coeff_ = list.get<Real>("Coefficient");
94  target_ = list.get<Real>("Target");
95  // Build (approximate) plus function
96  plusFunction_ = makePtr<PlusFunction<Real>>(list);
97  // Check Inputs
98  checkInputs();
99  }
100 
102  const Vector<Real> &x,
103  const std::vector<Real> &xstat,
104  Real &tol) {
105  Real val = computeValue(obj,x,tol);
106  Real pf = plusFunction_->evaluate(val-target_,0);
107  val_ += weight_ * (val + coeff_ * pf);
108  }
109 
110  Real getValue(const Vector<Real> &x,
111  const std::vector<Real> &xstat,
112  SampleGenerator<Real> &sampler) {
113  Real ev(0);
114  sampler.sumAll(&val_,&ev,1);
115  return ev;
116  }
117 
119  const Vector<Real> &x,
120  const std::vector<Real> &xstat,
121  Real &tol) {
122  const Real one(1);
123  Real val = computeValue(obj,x,tol);
124  Real pf = plusFunction_->evaluate(val-target_,1);
125  computeGradient(*dualVector_,obj,x,tol);
126  g_->axpy(weight_ * (one + coeff_ * pf), *dualVector_);
127  }
128 
130  std::vector<Real> &gstat,
131  const Vector<Real> &x,
132  const std::vector<Real> &xstat,
133  SampleGenerator<Real> &sampler) {
134  sampler.sumAll(*g_, g);
135  }
136 
138  const Vector<Real> &v,
139  const std::vector<Real> &vstat,
140  const Vector<Real> &x,
141  const std::vector<Real> &xstat,
142  Real &tol) {
143  const Real one(1);
144  Real val = computeValue(obj,x,tol);
145  Real pf1 = plusFunction_->evaluate(val-target_,1);
146  Real pf2 = plusFunction_->evaluate(val-target_,2);
147  Real gv = computeGradVec(*dualVector_,obj,v,x,tol);
148  hv_->axpy(weight_ * coeff_ * pf2 * gv, *dualVector_);
149  computeHessVec(*dualVector_,obj,v,x,tol);
150  hv_->axpy(weight_ * (one + coeff_ * pf1), *dualVector_);
151  }
152 
154  std::vector<Real> &hvstat,
155  const Vector<Real> &v,
156  const std::vector<Real> &vstat,
157  const Vector<Real> &x,
158  const std::vector<Real> &xstat,
159  SampleGenerator<Real> &sampler) {
160  sampler.sumAll(*hv_, hv);
161  }
162 };
163 
164 }
165 
166 #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.