44 #ifndef ROL_MEANVARIANCE_HPP
45 #define ROL_MEANVARIANCE_HPP
52 #include "ROL_ParameterList.hpp"
106 values_ = makePtr<SampledScalar<Real>>();
107 gradvecs_ = makePtr<SampledScalar<Real>>();
109 hessvecs_ = makePtr<SampledVector<Real>>();
117 ROL_TEST_FOR_EXCEPTION((oSize!=cSize),std::invalid_argument,
118 ">>> ERROR (ROL::MeanVariance): Order and coefficient arrays have different sizes!");
119 Real
zero(0), two(2);
120 for (
int i = 0; i < oSize; i++) {
121 ROL_TEST_FOR_EXCEPTION((
order_[i] < two), std::invalid_argument,
122 ">>> ERROR (ROL::MeanVariance): Element of order array out of range!");
123 ROL_TEST_FOR_EXCEPTION((
coeff_[i] <
zero), std::invalid_argument,
124 ">>> ERROR (ROL::MeanVariance): Element of coefficient array out of range!");
127 ">>> ERROR (ROL::MeanVariance): PositiveFunction pointer is null!");
160 const std::vector<Real> &coeff,
164 for (
uint i = 0; i < order.size(); i++ ) {
165 order_.push_back(order[i]);
167 for (
uint i = 0; i < coeff.size(); i++ ) {
168 coeff_.push_back(coeff[i]);
187 ROL::ParameterList &list
188 = parlist.sublist(
"SOL").sublist(
"Risk Measure").sublist(
"Mean Plus Variance");
190 order_ = ROL::getArrayFromStringParameter<double>(list,
"Orders");
191 coeff_ = ROL::getArrayFromStringParameter<double>(list,
"Coefficients");
193 std::string type = list.get<std::string>(
"Deviation Type");
194 if ( type ==
"Upper" ) {
197 else if ( type ==
"Absolute" ) {
201 ROL_TEST_FOR_EXCEPTION(
true, std::invalid_argument,
202 ">>> (ROL::MeanVariance): Variance type is not recoginized!");
225 const std::vector<Real> &xstat,
232 const std::vector<Real> &xstat,
238 Real val(0), diff(0), pf0(0), var(0), weight(0);
248 sampler.
sumAll(&val,&var,1);
255 const std::vector<Real> &xstat,
264 std::vector<Real> &gstat,
266 const std::vector<Real> &xstat,
269 Real ev(0),
zero(0), one(1);
274 Real diff(0), pf0(0), pf1(0), c(0), ec(0), ecs(0), weight(0);
290 sampler.
sumAll(&ec,&ecs,1);
298 const std::vector<Real> &vstat,
300 const std::vector<Real> &xstat,
312 std::vector<Real> &hvstat,
314 const std::vector<Real> &vstat,
316 const std::vector<Real> &xstat,
319 std::vector<Real> myval(2), val(2);
322 sampler.
sumAll(&myval[0],&val[0],2);
323 Real ev = myval[0], egv = myval[1];
328 g_->zero();
hv_->zero();
329 Real diff(0), pf0(0), pf1(0), pf2(0),
zero(0), one(1), two(2);
330 Real cg(0), ecg(0), ecgs(0), ch(0), ech(0), echs(0), weight(0), gv(0);
344 std::pow(pf0,
order_[p]-one)*pf2);
350 g_->axpy(weight*cg,*
hv_);
352 g_->axpy(weight*ch,*
hv_);
354 sampler.
sumAll(&ech,&echs,1);
356 sampler.
sumAll(&ecg,&ecgs,1);
virtual void setHessVecStorage(const Ptr< SampledScalar< Real >> &gradvec_storage, const Ptr< SampledVector< Real >> &hessvec_storage)
void updateValue(Objective< Real > &obj, const Vector< Real > &x, const std::vector< Real > &xstat, Real &tol)
Update internal storage for value computation.
Provides the interface to evaluate objective functions.
MeanVariance(const Real order, const Real coeff, const Ptr< PositiveFunction< Real > > &pf)
Constructor.
void computeHessVec(Vector< Real > &hv, Objective< Real > &obj, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Ptr< SampledScalar< Real > > gradvecs_
typename PV< Real >::size_type size_type
virtual void scale(const Real alpha)=0
Compute where .
Real getValue(const Vector< Real > &x, const std::vector< Real > &xstat, SampleGenerator< Real > &sampler)
Return risk measure value.
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 computeValue(Objective< Real > &obj, const Vector< Real > &x, Real &tol)
virtual void plus(const Vector &x)=0
Compute , where .
Ptr< SampledVector< Real > > gradients_
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
Ptr< Vector< Real > > hv_
std::vector< Real > order_
Ptr< SampledVector< Real > > hessvecs_
Ptr< SampledScalar< Real > > values_
virtual std::vector< Real > getMyPoint(const int i) const
virtual Real getMyWeight(const int i) const
Ptr< Vector< Real > > dualVector_
std::vector< Real > coeff_
Defines the linear algebra or vector space interface.
virtual int numMySamples(void) const
void sumAll(Real *input, Real *output, int dim) const
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0_ zero()
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.
MeanVariance(ROL::ParameterList &parlist)
Constructor.
virtual void setStorage(const Ptr< SampledScalar< Real >> &value_storage, const Ptr< SampledVector< Real >> &gradient_storage)
void setHessVecStorage(const Ptr< SampledScalar< Real >> &gradvec_storage, const Ptr< SampledVector< Real >> &hessvec_storage)
void computeGradient(Vector< Real > &g, Objective< Real > &obj, const Vector< Real > &x, Real &tol)
std::vector< Real >::size_type uint
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...
Provides an interface for the mean plus a sum of arbitrary order variances.
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 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.
MeanVariance(const std::vector< Real > &order, const std::vector< Real > &coeff, const Ptr< PositiveFunction< Real > > &pf)
Constructor.
void setStorage(const Ptr< SampledScalar< Real >> &value_storage, const Ptr< SampledVector< Real >> &gradient_storage)
Ptr< PositiveFunction< Real > > positiveFunction_