ROL
ROL_PD_MeanSemiDeviationFromTarget.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 ROL_PD_MEANSEMIDEVIATIONFROMTARGET_HPP
45 #define ROL_PD_MEANSEMIDEVIATIONFROMTARGET_HPP
46 
48 
49 namespace ROL {
50 
51 template<class Real>
53 private:
54  Real coeff_;
55  Real target_;
56 
57  Ptr<SampledScalar<Real>> values_;
58  Ptr<SampledScalar<Real>> gradvecs_;
59  Ptr<SampledVector<Real>> gradients_;
60  Ptr<SampledVector<Real>> hessvecs_;
61 
67 
70 
75 
80 
81  void initializeStorage(void) {
82  values_ = makePtr<SampledScalar<Real>>();
83  gradvecs_ = makePtr<SampledScalar<Real>>();
84  gradients_ = makePtr<SampledVector<Real>>();
85  hessvecs_ = makePtr<SampledVector<Real>>();
86 
88  RandVarFunctional<Real>::setHessVecStorage(gradvecs_,hessvecs_);
89  }
90 
91  void clear(void) {
92  gradvecs_->update();
93  hessvecs_->update();
94  }
95 
96  void checkInputs(void) {
97  Real zero(0);
98  ROL_TEST_FOR_EXCEPTION((coeff_ < zero), std::invalid_argument,
99  ">>> ERROR (ROL::PD_MeanSemiDeviation): Element of coefficient array out of range!");
101  }
102 
103 public:
104  PD_MeanSemiDeviationFromTarget(const Real coeff, const Real target)
105  : PD_RandVarFunctional<Real>(), coeff_(coeff), target_(target) {
106  checkInputs();
107  }
108 
109  void setStorage(const Ptr<SampledScalar<Real>> &value_storage,
110  const Ptr<SampledVector<Real>> &gradient_storage) {
111  values_ = value_storage;
112  gradients_ = gradient_storage;
114  }
115 
116  void setHessVecStorage(const Ptr<SampledScalar<Real>> &gradvec_storage,
117  const Ptr<SampledVector<Real>> &hessvec_storage) {
118  gradvecs_ = gradvec_storage;
119  hessvecs_ = hessvec_storage;
121  }
122 
123  void initialize(const Vector<Real> &x) {
125  clear();
126  }
127 
129  const Vector<Real> &x,
130  const std::vector<Real> &xstat,
131  Real &tol) {
132  Real lam(0);
133  getMultiplier(lam, point_);
134  Real val = computeValue(obj,x,tol);
135  Real arg = coeff_ * (val - target_);
136  Real pf = ppf(arg, lam, getPenaltyParameter(), 0);
137  val_ += weight_ * (val + pf);
138  setValue(arg, point_);
139  }
140 
141  Real getValue(const Vector<Real> &x,
142  const std::vector<Real> &xstat,
143  SampleGenerator<Real> &sampler) {
144  Real ev(0);
145  sampler.sumAll(&val_,&ev,1);
146  return ev;
147  }
148 
150  const Vector<Real> &x,
151  const std::vector<Real> &xstat,
152  Real &tol) {
153  const Real one(1);
154  Real lam(0);
155  getMultiplier(lam, point_);
156  Real val = computeValue(obj,x,tol);
157  Real arg = coeff_ * (val - target_);
158  Real pf = ppf(arg, lam, getPenaltyParameter(), 1);
159  computeGradient(*dualVector_,obj,x,tol);
160  g_->axpy(weight_ * (one + coeff_ * pf), *dualVector_);
161  }
162 
164  std::vector<Real> &gstat,
165  const Vector<Real> &x,
166  const std::vector<Real> &xstat,
167  SampleGenerator<Real> &sampler) {
168  sampler.sumAll(*g_,g);
169  }
170 
172  const Vector<Real> &v,
173  const std::vector<Real> &vstat,
174  const Vector<Real> &x,
175  const std::vector<Real> &xstat,
176  Real &tol) {
177  const Real zero(0), one(1);
178  Real lam(0);
179  getMultiplier(lam, point_);
180  Real val = computeValue(obj,x,tol);
181  Real arg = coeff_ * (val - target_);
182  Real pf1 = ppf(arg, lam, getPenaltyParameter(), 1);
183  Real pf2 = ppf(arg, lam, getPenaltyParameter(), 2);
184  computeHessVec(*dualVector_, obj, v, x, tol);
185  hv_->axpy(weight_ * (one + pf1 * coeff_), *dualVector_);
186  if ( pf2 > zero ) {
187  Real gv = computeGradVec(*dualVector_, obj, v, x, tol);
188  hv_->axpy(weight_ * pf2 * coeff_ * coeff_ * gv, *dualVector_);
189  }
190  }
191 
193  std::vector<Real> &hvstat,
194  const Vector<Real> &v,
195  const std::vector<Real> &vstat,
196  const Vector<Real> &x,
197  const std::vector<Real> &xstat,
198  SampleGenerator<Real> &sampler) {
199  sampler.sumAll(*hv_,hv);
200  }
201 };
202 
203 }
204 
205 #endif
virtual void setHessVecStorage(const Ptr< SampledScalar< Real >> &gradvec_storage, const Ptr< SampledVector< Real >> &hessvec_storage)
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_
Real ppf(const Real x, const Real t, const Real r, const int deriv=0) const
void setStorage(const Ptr< SampledScalar< Real >> &value_storage, const Ptr< SampledVector< Real >> &gradient_storage)
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.
Ptr< Vector< Real > > dualVector_
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:80
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.
virtual void setStorage(const Ptr< SampledScalar< Real >> &value_storage, const Ptr< SampledVector< Real >> &gradient_storage)
void updateValue(Objective< Real > &obj, const Vector< Real > &x, const std::vector< Real > &xstat, Real &tol)
Update internal storage for value computation.
void setHessVecStorage(const Ptr< SampledScalar< Real >> &gradvec_storage, const Ptr< SampledVector< Real >> &hessvec_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.
virtual void setStorage(const Ptr< SampledScalar< Real >> &value_storage, const Ptr< SampledVector< Real >> &gradient_storage)
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< SampledScalar< Real >> &gradvec_storage, const Ptr< SampledVector< Real >> &hessvec_storage)