ROL
ROL_PD_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_PD_MEANSEMIDEVIATIONFROMTARGET_HPP
11 #define ROL_PD_MEANSEMIDEVIATIONFROMTARGET_HPP
12 
14 
15 namespace ROL {
16 
17 template<class Real>
19 private:
20  Real coeff_;
21  Real target_;
22 
23  Ptr<ScalarController<Real>> values_;
24  Ptr<ScalarController<Real>> gradvecs_;
25  Ptr<VectorController<Real>> gradients_;
26  Ptr<VectorController<Real>> hessvecs_;
27 
33 
36 
41 
46 
47  void initializeStorage(void) {
48  values_ = makePtr<ScalarController<Real>>();
49  gradvecs_ = makePtr<ScalarController<Real>>();
50  gradients_ = makePtr<VectorController<Real>>();
51  hessvecs_ = makePtr<VectorController<Real>>();
52 
54  RandVarFunctional<Real>::setHessVecStorage(gradvecs_,hessvecs_);
55  }
56 
57  void clear(void) {
58  gradvecs_->reset();
59  hessvecs_->reset();
60  }
61 
62  void checkInputs(void) {
63  Real zero(0);
64  ROL_TEST_FOR_EXCEPTION((coeff_ < zero), std::invalid_argument,
65  ">>> ERROR (ROL::PD_MeanSemiDeviation): Element of coefficient array out of range!");
67  }
68 
69 public:
70  PD_MeanSemiDeviationFromTarget(const Real coeff, const Real target)
71  : PD_RandVarFunctional<Real>(), coeff_(coeff), target_(target) {
72  checkInputs();
73  }
74 
75  void setStorage(const Ptr<ScalarController<Real>> &value_storage,
76  const Ptr<VectorController<Real>> &gradient_storage) {
77  values_ = value_storage;
78  gradients_ = gradient_storage;
80  }
81 
82  void setHessVecStorage(const Ptr<ScalarController<Real>> &gradvec_storage,
83  const Ptr<VectorController<Real>> &hessvec_storage) {
84  gradvecs_ = gradvec_storage;
85  hessvecs_ = hessvec_storage;
87  }
88 
89  void initialize(const Vector<Real> &x) {
91  clear();
92  }
93 
95  const Vector<Real> &x,
96  const std::vector<Real> &xstat,
97  Real &tol) {
98  Real lam(0);
99  getMultiplier(lam, point_);
100  Real val = computeValue(obj,x,tol);
101  Real arg = coeff_ * (val - target_);
102  Real pf = ppf(arg, lam, getPenaltyParameter(), 0);
103  val_ += weight_ * (val + pf);
104  setValue(arg, point_);
105  }
106 
107  Real getValue(const Vector<Real> &x,
108  const std::vector<Real> &xstat,
109  SampleGenerator<Real> &sampler) {
110  Real ev(0);
111  sampler.sumAll(&val_,&ev,1);
112  return ev;
113  }
114 
116  const Vector<Real> &x,
117  const std::vector<Real> &xstat,
118  Real &tol) {
119  const Real one(1);
120  Real lam(0);
121  getMultiplier(lam, point_);
122  Real val = computeValue(obj,x,tol);
123  Real arg = coeff_ * (val - target_);
124  Real pf = ppf(arg, lam, getPenaltyParameter(), 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 zero(0), one(1);
144  Real lam(0);
145  getMultiplier(lam, point_);
146  Real val = computeValue(obj,x,tol);
147  Real arg = coeff_ * (val - target_);
148  Real pf1 = ppf(arg, lam, getPenaltyParameter(), 1);
149  Real pf2 = ppf(arg, lam, getPenaltyParameter(), 2);
150  computeHessVec(*dualVector_, obj, v, x, tol);
151  hv_->axpy(weight_ * (one + pf1 * coeff_), *dualVector_);
152  if ( pf2 > zero ) {
153  Real gv = computeGradVec(*dualVector_, obj, v, x, tol);
154  hv_->axpy(weight_ * pf2 * coeff_ * coeff_ * gv, *dualVector_);
155  }
156  }
157 
159  std::vector<Real> &hvstat,
160  const Vector<Real> &v,
161  const std::vector<Real> &vstat,
162  const Vector<Real> &x,
163  const std::vector<Real> &xstat,
164  SampleGenerator<Real> &sampler) {
165  sampler.sumAll(*hv_,hv);
166  }
167 };
168 
169 }
170 
171 #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_
virtual void setHessVecStorage(const Ptr< ScalarController< Real >> &gradvec_storage, const Ptr< VectorController< Real >> &hessvec_storage)
Real computeValue(Objective< Real > &obj, const Vector< Real > &x, Real &tol)
Ptr< Vector< Real > > hv_
Real ppf(const Real x, const Real t, const Real r, const int deriv=0) const
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 setHessVecStorage(const Ptr< ScalarController< Real >> &gradvec_storage, const Ptr< VectorController< Real >> &hessvec_storage)
Ptr< Vector< Real > > dualVector_
virtual void setStorage(const Ptr< ScalarController< Real >> &value_storage, const Ptr< VectorController< Real >> &gradient_storage)
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:46
void sumAll(Real *input, Real *output, int dim) const
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0_ zero()
void setStorage(const Ptr< ScalarController< Real >> &value_storage, const Ptr< VectorController< Real >> &gradient_storage)
void updateGradient(Objective< Real > &obj, const Vector< Real > &x, const std::vector< Real > &xstat, Real &tol)
Update internal risk measure storage for gradient computation.
void updateValue(Objective< Real > &obj, const Vector< Real > &x, const std::vector< Real > &xstat, Real &tol)
Update internal storage for value computation.
virtual void setStorage(const Ptr< ScalarController< Real >> &value_storage, const Ptr< VectorController< Real >> &gradient_storage)
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 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.
void initialize(const Vector< Real > &x)
Initialize temporary variables.
void getMultiplier(Real &lam, const std::vector< Real > &pt) const
void computeGradient(Vector< Real > &g, Objective< Real > &obj, const Vector< Real > &x, Real &tol)
virtual void initialize(const Vector< Real > &x)
Initialize temporary variables.
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...
void setValue(const Real val, const std::vector< Real > &pt)
Real getValue(const Vector< Real > &x, const std::vector< Real > &xstat, SampleGenerator< Real > &sampler)
Return risk measure value.
PD_MeanSemiDeviationFromTarget(const Real coeff, const Real target)
virtual void setHessVecStorage(const Ptr< ScalarController< Real >> &gradvec_storage, const Ptr< VectorController< Real >> &hessvec_storage)