10#ifndef ROL_MEANDEVIATION_HPP
11#define ROL_MEANDEVIATION_HPP
14#include "ROL_ParameterList.hpp"
47 typedef typename std::vector<Real>::size_type
uint;
108 values_ = makePtr<ScalarController<Real>>();
109 gradvecs_ = makePtr<ScalarController<Real>>();
110 gradients_ = makePtr<VectorController<Real>>();
111 hessvecs_ = makePtr<VectorController<Real>>();
135 ROL_TEST_FOR_EXCEPTION((oSize!=cSize),std::invalid_argument,
136 ">>> ERROR (ROL::MeanDeviation): Order and coefficient arrays have different sizes!");
137 Real
zero(0), two(2);
138 for (
int i = 0; i < oSize; i++) {
139 ROL_TEST_FOR_EXCEPTION((
order_[i] < two), std::invalid_argument,
140 ">>> ERROR (ROL::MeanDeviation): Element of order array out of range!");
141 ROL_TEST_FOR_EXCEPTION((
coeff_[i] <
zero), std::invalid_argument,
142 ">>> ERROR (ROL::MeanDeviation): Element of coefficient array out of range!");
145 ">>> ERROR (ROL::MeanDeviation): PositiveFunction pointer is null!");
177 const std::vector<Real> &coeff,
181 for (
uint i = 0; i < order.size(); i++ ) {
182 order_.push_back(order[i]);
184 for (
uint i = 0; i < coeff.size(); i++ ) {
185 coeff_.push_back(coeff[i]);
203 ROL::ParameterList &list
204 = parlist.sublist(
"SOL").sublist(
"Risk Measure").sublist(
"Mean Plus Deviation");
207 order_ = ROL::getArrayFromStringParameter<double>(list,
"Orders");
209 coeff_ = ROL::getArrayFromStringParameter<double>(list,
"Coefficients");
212 std::string type = list.get<std::string>(
"Deviation Type");
213 if ( type ==
"Upper" ) {
216 else if ( type ==
"Absolute" ) {
220 ROL_TEST_FOR_EXCEPTION(
true, std::invalid_argument,
221 ">>> (ROL::MeanDeviation): Deviation type is not recoginized!");
248 const std::vector<Real> &xstat,
250 Real val = computeValue(obj,x,tol);
251 val_ += weight_ * val;
256 const std::vector<Real> &xstat,
258 Real val = computeValue(obj,x,tol);
259 val_ += weight_ * val;
260 computeGradient(*dualVector_,obj,x,tol);
261 g_->axpy(weight_,*dualVector_);
266 const std::vector<Real> &vstat,
268 const std::vector<Real> &xstat,
270 Real val = computeValue(obj,x,tol);
271 val_ += weight_ * val;
272 Real gv = computeGradVec(*dualVector_,obj,v,x,tol);
275 computeHessVec(*dualVector_,obj,v,x,tol);
280 const std::vector<Real> &xstat,
284 sampler.
sumAll(&val_,&ev,1);
286 Real diff(0), pf0(0), dev(0), one(1), weight(0);
305 std::vector<Real> &gstat,
307 const std::vector<Real> &xstat,
311 sampler.
sumAll(&val_,&ev,1);
313 Real diff(0), pf0(0), pf1(0), c(0), one(1),
zero(0), weight(0);
322 dev1_[p] += weight * std::pow(pf0,
order_[p]-one) * pf1;
345 g_->axpy(weight*c,*dualVector_);
351 std::vector<Real> &hvstat,
353 const std::vector<Real> &vstat,
355 const std::vector<Real> &xstat,
358 std::vector<Real> myval(2), val(2);
361 sampler.
sumAll(&myval[0],&val[0],2);
362 Real ev = val[0], egv = val[1];
364 Real diff(0), pf0(0), pf1(0), pf2(0),
zero(0), one(1), two(2);
365 Real cg(0), ch(0), diff1(0), diff2(0), diff3(0), weight(0), gv(0);
375 dev1_[p] += weight * std::pow(pf0,
order_[p]-one) * pf1;
376 dev2_[p] += weight * std::pow(pf0,
order_[p]-two) * pf1 * pf1;
377 dev3_[p] += weight * std::pow(pf0,
order_[p]-one) * pf2;
423 diff2 = std::pow(pf0,
order_[p]-two)*pf1*pf1*(gv-egv)-
gvs2_[p];
424 diff3 = std::pow(pf0,
order_[p]-one)*pf2*(gv-egv)-
gvs3_[p];
431 dualVector_->axpy(weight*ch,*g_);
433 dualVector_->axpy(weight*cg,*hv_);
435 sampler.
sumAll(*dualVector_,hv);
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0 zero)()
MeanDeviation(const Real order, const Real coeff, const Ptr< PositiveFunction< Real > > &pf)
Constructor.
std::vector< Real > gvs2_
std::vector< Real > des0_
void getGradient(Vector< Real > &g, std::vector< Real > &gstat, const Vector< Real > &x, const std::vector< Real > &xstat, SampleGenerator< Real > &sampler)
void initialize(const Vector< Real > &x)
MeanDeviation(ROL::ParameterList &parlist)
Constructor.
Ptr< ScalarController< Real > > gradvecs_
std::vector< Real > gvp2_
Ptr< PositiveFunction< Real > > positiveFunction_
std::vector< Real > coeff_
std::vector< Real > dev0_
void setHessVecStorage(const Ptr< ScalarController< Real > > &gradvec_storage, const Ptr< VectorController< Real > > &hessvec_storage)
void updateValue(Objective< Real > &obj, const Vector< Real > &x, const std::vector< Real > &xstat, Real &tol)
Ptr< ScalarController< Real > > values_
std::vector< Real > des1_
std::vector< Real > des3_
std::vector< Real > gvs1_
void setStorage(const Ptr< ScalarController< Real > > &value_storage, const Ptr< VectorController< Real > > &gradient_storage)
std::vector< Real > gvp3_
std::vector< Real >::size_type uint
Ptr< VectorController< Real > > gradients_
std::vector< Real > dev2_
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)
std::vector< Real > gvp1_
std::vector< Real > dev1_
void initializeStorage(void)
Real getValue(const Vector< Real > &x, const std::vector< Real > &xstat, SampleGenerator< Real > &sampler)
std::vector< Real > order_
MeanDeviation(const std::vector< Real > &order, const std::vector< Real > &coeff, const Ptr< PositiveFunction< Real > > &pf)
Constructor.
std::vector< Real > gvs3_
std::vector< Real > devp_
void updateGradient(Objective< Real > &obj, const Vector< Real > &x, const std::vector< Real > &xstat, Real &tol)
Ptr< VectorController< Real > > hessvecs_
std::vector< Real > dev3_
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)
std::vector< Real > des2_
Provides the interface to evaluate objective functions.
Provides the interface to implement any functional that maps a random variable to a (extended) real n...
virtual int numMySamples(void) const
virtual std::vector< Real > getMyPoint(const int i) const
void sumAll(Real *input, Real *output, int dim) const
virtual Real getMyWeight(const int i) const
Defines the linear algebra or vector space interface.