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
49namespace ROL {
50
51template<class Real>
53private:
54 Real coeff_;
55 Real target_;
56
57 Ptr<ScalarController<Real>> values_;
58 Ptr<ScalarController<Real>> gradvecs_;
59 Ptr<VectorController<Real>> gradients_;
60 Ptr<VectorController<Real>> hessvecs_;
61
62 using RandVarFunctional<Real>::val_;
63 using RandVarFunctional<Real>::g_;
64 using RandVarFunctional<Real>::gv_;
65 using RandVarFunctional<Real>::hv_;
67
68 using RandVarFunctional<Real>::point_;
70
75
79 using PD_RandVarFunctional<Real>::ppf;
80
81 void initializeStorage(void) {
82 values_ = makePtr<ScalarController<Real>>();
83 gradvecs_ = makePtr<ScalarController<Real>>();
84 gradients_ = makePtr<VectorController<Real>>();
85 hessvecs_ = makePtr<VectorController<Real>>();
86
89 }
90
91 void clear(void) {
92 gradvecs_->reset();
93 hessvecs_->reset();
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
103public:
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<ScalarController<Real>> &value_storage,
110 const Ptr<VectorController<Real>> &gradient_storage) {
111 values_ = value_storage;
112 gradients_ = gradient_storage;
114 }
115
116 void setHessVecStorage(const Ptr<ScalarController<Real>> &gradvec_storage,
117 const Ptr<VectorController<Real>> &hessvec_storage) {
118 gradvecs_ = gradvec_storage;
119 hessvecs_ = hessvec_storage;
121 }
122
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
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0 zero)()
Provides the interface to evaluate objective functions.
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 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.
PD_MeanSemiDeviationFromTarget(const Real coeff, const Real target)
void setStorage(const Ptr< ScalarController< Real > > &value_storage, const Ptr< VectorController< 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.
void updateGradient(Objective< Real > &obj, const Vector< Real > &x, const std::vector< Real > &xstat, Real &tol)
Update internal risk measure storage for gradient computation.
Real getValue(const Vector< Real > &x, const std::vector< Real > &xstat, SampleGenerator< Real > &sampler)
Return risk measure value.
void setHessVecStorage(const Ptr< ScalarController< Real > > &gradvec_storage, const Ptr< VectorController< Real > > &hessvec_storage)
void initialize(const Vector< Real > &x)
Initialize temporary variables.
void getMultiplier(Real &lam, const std::vector< Real > &pt) const
Real ppf(const Real x, const Real t, const Real r, const int deriv=0) const
virtual void setHessVecStorage(const Ptr< ScalarController< Real > > &gradvec_storage, const Ptr< VectorController< Real > > &hessvec_storage)
void setValue(const Real val, const std::vector< Real > &pt)
virtual void initialize(const Vector< Real > &x)
Initialize temporary variables.
virtual void setStorage(const Ptr< ScalarController< Real > > &value_storage, const Ptr< VectorController< Real > > &gradient_storage)
Provides the interface to implement any functional that maps a random variable to a (extended) real n...
Real computeValue(Objective< Real > &obj, const Vector< Real > &x, Real &tol)
void computeHessVec(Vector< Real > &hv, Objective< Real > &obj, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
virtual void setStorage(const Ptr< ScalarController< Real > > &value_storage, const Ptr< VectorController< Real > > &gradient_storage)
void computeGradient(Vector< Real > &g, Objective< Real > &obj, const Vector< Real > &x, Real &tol)
Ptr< Vector< Real > > dualVector_
virtual void setHessVecStorage(const Ptr< ScalarController< Real > > &gradvec_storage, const Ptr< VectorController< Real > > &hessvec_storage)
Real computeGradVec(Vector< Real > &g, Objective< Real > &obj, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
void sumAll(Real *input, Real *output, int dim) const
Defines the linear algebra or vector space interface.