ROL
ROL_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_MEANSEMIDEVIATIONFROMTARGET_HPP
45#define ROL_MEANSEMIDEVIATIONFROMTARGET_HPP
46
48#include "ROL_PlusFunction.hpp"
49
69namespace ROL {
70
71template<class Real>
73private:
74 Ptr<PlusFunction<Real> > plusFunction_;
76
77 using RandVarFunctional<Real>::val_;
78 using RandVarFunctional<Real>::gv_;
79 using RandVarFunctional<Real>::g_;
80 using RandVarFunctional<Real>::hv_;
82
83 using RandVarFunctional<Real>::point_;
85
90
91 void checkInputs(void) const {
92 const Real zero(0);
93 ROL_TEST_FOR_EXCEPTION((coeff_ < zero), std::invalid_argument,
94 ">>> ERROR (ROL::MeanPlusSemiDeviationFromTarget): Coefficient must be positive!");
95 ROL_TEST_FOR_EXCEPTION(plusFunction_ == nullPtr, std::invalid_argument,
96 ">>> ERROR (ROL::MeanSemiDeviation): PlusFunction pointer is null!");
97 }
98
99public:
100
107 MeanSemiDeviationFromTarget( const Real coeff, const Real target,
108 const Ptr<PlusFunction<Real>> &pf )
109 : RandVarFunctional<Real>(), plusFunction_(pf), coeff_(coeff), target_(target) {
110 checkInputs();
111 }
112
123 MeanSemiDeviationFromTarget( ROL::ParameterList &parlist )
124 : RandVarFunctional<Real>() {
125 ROL::ParameterList &list
126 = parlist.sublist("SOL").sublist("Risk Measure").sublist("Mean Plus Semi-Deviation From Target");
127 // Check inputs
128 coeff_ = list.get<Real>("Coefficient");
129 target_ = list.get<Real>("Target");
130 // Build (approximate) plus function
131 plusFunction_ = makePtr<PlusFunction<Real>>(list);
132 // Check Inputs
133 checkInputs();
134 }
135
137 const Vector<Real> &x,
138 const std::vector<Real> &xstat,
139 Real &tol) {
140 Real val = computeValue(obj,x,tol);
141 Real pf = plusFunction_->evaluate(val-target_,0);
142 val_ += weight_ * (val + coeff_ * pf);
143 }
144
145 Real getValue(const Vector<Real> &x,
146 const std::vector<Real> &xstat,
147 SampleGenerator<Real> &sampler) {
148 Real ev(0);
149 sampler.sumAll(&val_,&ev,1);
150 return ev;
151 }
152
154 const Vector<Real> &x,
155 const std::vector<Real> &xstat,
156 Real &tol) {
157 const Real one(1);
158 Real val = computeValue(obj,x,tol);
159 Real pf = plusFunction_->evaluate(val-target_,1);
160 computeGradient(*dualVector_,obj,x,tol);
161 g_->axpy(weight_ * (one + coeff_ * pf), *dualVector_);
162 }
163
165 std::vector<Real> &gstat,
166 const Vector<Real> &x,
167 const std::vector<Real> &xstat,
168 SampleGenerator<Real> &sampler) {
169 sampler.sumAll(*g_, g);
170 }
171
173 const Vector<Real> &v,
174 const std::vector<Real> &vstat,
175 const Vector<Real> &x,
176 const std::vector<Real> &xstat,
177 Real &tol) {
178 const Real one(1);
179 Real val = computeValue(obj,x,tol);
180 Real pf1 = plusFunction_->evaluate(val-target_,1);
181 Real pf2 = plusFunction_->evaluate(val-target_,2);
182 Real gv = computeGradVec(*dualVector_,obj,v,x,tol);
183 hv_->axpy(weight_ * coeff_ * pf2 * gv, *dualVector_);
184 computeHessVec(*dualVector_,obj,v,x,tol);
185 hv_->axpy(weight_ * (one + coeff_ * pf1), *dualVector_);
186 }
187
189 std::vector<Real> &hvstat,
190 const Vector<Real> &v,
191 const std::vector<Real> &vstat,
192 const Vector<Real> &x,
193 const std::vector<Real> &xstat,
194 SampleGenerator<Real> &sampler) {
195 sampler.sumAll(*hv_, hv);
196 }
197};
198
199}
200
201#endif
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.
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.
Real getValue(const Vector< Real > &x, const std::vector< Real > &xstat, SampleGenerator< Real > &sampler)
Return risk measure value.
MeanSemiDeviationFromTarget(const Real coeff, const Real target, const Ptr< PlusFunction< Real > > &pf)
Constructor.
MeanSemiDeviationFromTarget(ROL::ParameterList &parlist)
Constructor.
void updateValue(Objective< Real > &obj, const Vector< Real > &x, const std::vector< Real > &xstat, Real &tol)
Update internal storage for value computation.
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 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.
Provides the interface to evaluate objective functions.
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)
Ptr< Vector< Real > > g_
void computeHessVec(Vector< Real > &hv, Objective< Real > &obj, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Ptr< Vector< Real > > hv_
void computeGradient(Vector< Real > &g, Objective< Real > &obj, const Vector< Real > &x, Real &tol)
Ptr< Vector< Real > > dualVector_
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.
Definition: ROL_Vector.hpp:84