ROL
ROL_MeanVarianceFromTarget.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_MEANVARIANCEFROMTARGET_HPP
45#define ROL_MEANVARIANCEFROMTARGET_HPP
46
49#include "ROL_PlusFunction.hpp"
50#include "ROL_AbsoluteValue.hpp"
51
52#include "ROL_ParameterList.hpp"
53
74namespace ROL {
75
76template<class Real>
78 typedef typename std::vector<Real>::size_type uint;
79private:
80 ROL::Ptr<PositiveFunction<Real> > positiveFunction_;
81 std::vector<Real> target_;
82 std::vector<Real> order_;
83 std::vector<Real> coeff_;
85
86 using RandVarFunctional<Real>::val_;
87 using RandVarFunctional<Real>::gv_;
88 using RandVarFunctional<Real>::g_;
89 using RandVarFunctional<Real>::hv_;
91
92 using RandVarFunctional<Real>::point_;
94
99
100 void checkInputs(void) const {
101 int oSize = order_.size(), cSize = coeff_.size();
102 ROL_TEST_FOR_EXCEPTION((oSize!=cSize),std::invalid_argument,
103 ">>> ERROR (ROL::MeanVarianceFromTarget): Order and coefficient arrays have different sizes!");
104 Real zero(0), two(2);
105 for (int i = 0; i < oSize; i++) {
106 ROL_TEST_FOR_EXCEPTION((order_[i] < two), std::invalid_argument,
107 ">>> ERROR (ROL::MeanVarianceFromTarget): Element of order array out of range!");
108 ROL_TEST_FOR_EXCEPTION((coeff_[i] < zero), std::invalid_argument,
109 ">>> ERROR (ROL::MeanVarianceFromTarget): Element of coefficient array out of range!");
110 }
111 ROL_TEST_FOR_EXCEPTION(positiveFunction_ == ROL::nullPtr, std::invalid_argument,
112 ">>> ERROR (ROL::MeanVarianceFromTarget): PositiveFunction pointer is null!");
113 }
114
115public:
126 MeanVarianceFromTarget( const Real target, const Real order, const Real coeff,
127 const ROL::Ptr<PositiveFunction<Real> > &pf )
128 : RandVarFunctional<Real>(), positiveFunction_(pf) {
129 target_.clear(); target_.push_back(target);
130 order_.clear(); order_.push_back(order);
131 coeff_.clear(); coeff_.push_back(coeff);
132 checkInputs();
133 NumMoments_ = order_.size();
134 }
135
146 MeanVarianceFromTarget( const std::vector<Real> &target,
147 const std::vector<Real> &order,
148 const std::vector<Real> &coeff,
149 const ROL::Ptr<PositiveFunction<Real> > &pf )
150 : RandVarFunctional<Real>(), positiveFunction_(pf) {
151 target_.clear(); order_.clear(); coeff_.clear();
152 for ( uint i = 0; i < target.size(); i++ ) {
153 target_.push_back(target[i]);
154 }
155 for ( uint i = 0; i < order.size(); i++ ) {
156 order_.push_back(order[i]);
157 }
158 for ( uint i = 0; i < coeff.size(); i++ ) {
159 coeff_.push_back(coeff[i]);
160 }
161 checkInputs();
162 NumMoments_ = order_.size();
163 }
164
177 MeanVarianceFromTarget( ROL::ParameterList &parlist )
178 : RandVarFunctional<Real>() {
179 ROL::ParameterList &list
180 = parlist.sublist("SOL").sublist("Risk Measure").sublist("Mean Plus Variance From Target");
181 // Get data from parameter list
182 target_ = ROL::getArrayFromStringParameter<double>(list,"Targets");
183 order_ = ROL::getArrayFromStringParameter<double>(list,"Orders");
184 coeff_ = ROL::getArrayFromStringParameter<double>(list,"Coefficients");
185
186 // Build (approximate) positive function
187 std::string type = list.get<std::string>("Deviation Type");
188 if ( type == "Upper" ) {
189 positiveFunction_ = ROL::makePtr<PlusFunction<Real>>(list);
190 }
191 else if ( type == "Absolute" ) {
192 positiveFunction_ = ROL::makePtr<AbsoluteValue<Real>>(list);
193 }
194 else {
195 ROL_TEST_FOR_EXCEPTION(true, std::invalid_argument,
196 ">>> (ROL::MeanDeviation): Deviation type is not recoginized!");
197 }
198 // Check inputs
199 checkInputs();
200 NumMoments_ = order_.size();
201 }
202
204 const Vector<Real> &x,
205 const std::vector<Real> &xstat,
206 Real &tol) {
207 Real diff(0), pf0(0);
208 Real val = computeValue(obj,x,tol);
209 val_ += weight_ * val;
210 for ( uint p = 0; p < NumMoments_; p++ ) {
211 diff = val-target_[p];
212 pf0 = positiveFunction_->evaluate(diff,0);
213 val_ += weight_ * coeff_[p] * std::pow(pf0,order_[p]);
214 }
215 }
216
218 const Vector<Real> &x,
219 const std::vector<Real> &xstat,
220 Real &tol) {
221 Real diff(0), pf0(0), pf1(0), c(1), one(1);
222 Real val = computeValue(obj,x,tol);
223 for ( uint p = 0; p < NumMoments_; p++ ) {
224 diff = val-target_[p];
225 pf0 = positiveFunction_->evaluate(diff,0);
226 pf1 = positiveFunction_->evaluate(diff,1);
227 c += order_[p]*coeff_[p]*std::pow(pf0,order_[p]-one)*pf1;
228 }
229 computeGradient(*dualVector_,obj,x,tol);
230 g_->axpy(weight_ * c,*dualVector_);
231 }
232
234 const Vector<Real> &v,
235 const std::vector<Real> &vstat,
236 const Vector<Real> &x,
237 const std::vector<Real> &xstat,
238 Real &tol) {
239 Real diff(0), pf0(0), pf1(0), pf2(0), p1(0), p2(0), ch(1), cg(0), one(1), two(2);
240 Real val = computeValue(obj,x,tol);
241 Real gv = computeGradVec(*dualVector_,obj,v,x,tol);
242 for ( uint p = 0; p < NumMoments_; p++ ) {
243 diff = val - target_[p];
244 pf0 = positiveFunction_->evaluate(diff,0);
245 pf1 = positiveFunction_->evaluate(diff,1);
246 pf2 = positiveFunction_->evaluate(diff,2);
247 //p0 = std::pow(pf0,order_[p]);
248 p1 = std::pow(pf0,order_[p]-one);
249 p2 = std::pow(pf0,order_[p]-two);
250 cg += order_[p]*coeff_[p]*gv*( (order_[p]-one)*p2*pf1*pf1 + p1*pf2 );
251 ch += order_[p]*coeff_[p]*p1*pf1;
252 }
253 hv_->axpy(weight_*cg,*dualVector_);
254 computeHessVec(*dualVector_,obj,v,x,tol);
255 hv_->axpy(weight_*ch,*dualVector_);
256 }
257};
258
259}
260
261#endif
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0 zero)()
Provides an interface for the mean plus a sum of arbitrary order variances from targets.
MeanVarianceFromTarget(ROL::ParameterList &parlist)
Constructor.
ROL::Ptr< PositiveFunction< Real > > positiveFunction_
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.
std::vector< Real >::size_type uint
void updateGradient(Objective< Real > &obj, const Vector< Real > &x, const std::vector< Real > &xstat, Real &tol)
Update internal risk measure storage for gradient computation.
MeanVarianceFromTarget(const Real target, const Real order, const Real coeff, const ROL::Ptr< PositiveFunction< Real > > &pf)
Constructor.
void updateValue(Objective< Real > &obj, const Vector< Real > &x, const std::vector< Real > &xstat, Real &tol)
Update internal storage for value computation.
MeanVarianceFromTarget(const std::vector< Real > &target, const std::vector< Real > &order, const std::vector< Real > &coeff, const ROL::Ptr< PositiveFunction< Real > > &pf)
Constructor.
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)
void computeHessVec(Vector< Real > &hv, Objective< Real > &obj, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
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)
Defines the linear algebra or vector space interface.