44 #ifndef ROL_MEANVARIANCE_HPP 45 #define ROL_MEANVARIANCE_HPP 52 #include "Teuchos_ParameterList.hpp" 53 #include "Teuchos_Array.hpp" 80 typedef typename std::vector<Real>::size_type
uint;
104 TEUCHOS_TEST_FOR_EXCEPTION((oSize!=cSize),std::invalid_argument,
105 ">>> ERROR (ROL::MeanVariance): Order and coefficient arrays have different sizes!");
106 Real zero(0), two(2);
107 for (
int i = 0; i < oSize; i++) {
108 TEUCHOS_TEST_FOR_EXCEPTION((
order_[i] < two), std::invalid_argument,
109 ">>> ERROR (ROL::MeanVariance): Element of order array out of range!");
110 TEUCHOS_TEST_FOR_EXCEPTION((
coeff_[i] < zero), std::invalid_argument,
111 ">>> ERROR (ROL::MeanVariance): Element of coefficient array out of range!");
113 TEUCHOS_TEST_FOR_EXCEPTION(
positiveFunction_ == Teuchos::null, std::invalid_argument,
114 ">>> ERROR (ROL::MeanVariance): PositiveFunction pointer is null!");
146 const std::vector<Real> &coeff,
150 for (
uint i = 0; i < order.size(); i++ ) {
151 order_.push_back(order[i]);
153 for (
uint i = 0; i < coeff.size(); i++ ) {
154 coeff_.push_back(coeff[i]);
173 Teuchos::ParameterList &list
174 = parlist.sublist(
"SOL").sublist(
"Risk Measure").sublist(
"Mean Plus Variance");
176 Teuchos::Array<Real> order
177 = Teuchos::getArrayFromStringParameter<double>(list,
"Orders");
178 order_ = order.toVector();
179 Teuchos::Array<Real> coeff
180 = Teuchos::getArrayFromStringParameter<double>(list,
"Coefficients");
181 coeff_ = coeff.toVector();
183 std::string type = list.get<std::string>(
"Deviation Type");
184 if ( type ==
"Upper" ) {
187 else if ( type ==
"Absolute" ) {
191 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::invalid_argument,
192 ">>> (ROL::MeanDeviation): Deviation type is not recoginized!");
224 void update(
const Real val,
const Real weight) {
233 sampler.
sumAll(&val,&ev,1);
236 Real diff(0), pf0(0), var(0);
244 sampler.
sumAll(&val,&var,1);
254 typename std::vector<Teuchos::RCP<Vector<Real> > >::iterator it =
gradient_storage_.end();
263 sampler.
sumAll(&val,&ev,1);
266 Real diff(0), pf0(0), pf1(0), c(0), ec(0), ecs(0);
278 sampler.
sumAll(&ec,&ecs,1);
294 typename std::vector<Teuchos::RCP<Vector<Real> > >::iterator it =
gradient_storage_.end();
308 std::vector<Real> myval(2), val(2);
311 sampler.
sumAll(&myval[0],&val[0],2);
312 Real ev = myval[0], egv = myval[1];
316 Real diff(0), pf0(0), pf1(0), pf2(0), zero(0), one(1), two(2);
317 Real cg(0), ecg(0), ecgs(0), ch(0), ech(0), echs(0);
328 std::pow(pf0,
order_[p]-one)*pf2);
336 sampler.
sumAll(&ech,&echs,1);
338 sampler.
sumAll(&ecg,&ecgs,1);
Real getValue(SampleGenerator< Real > &sampler)
Return risk measure value.
std::vector< Teuchos::RCP< Vector< Real > > > gradient_storage_
std::vector< Real > gradvec_storage_
Teuchos::RCP< PositiveFunction< Real > > positiveFunction_
void reset(Teuchos::RCP< Vector< Real > > &x0, const Vector< Real > &x)
Reset internal risk measure storage. Called for value and gradient computation.
void update(const Real val, const Real weight)
Update internal risk measure storage for value computation.
Teuchos::RCP< Vector< Real > > dualVector4_
std::vector< Real > order_
void sumAll(Real *input, Real *output, int dim) const
virtual Teuchos::RCP< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
std::vector< Real > weights_
Teuchos::RCP< Vector< Real > > dualVector2_
virtual void zero()
Set to zero vector.
std::vector< Real > coeff_
Defines the linear algebra or vector space interface.
void update(const Real val, const Vector< Real > &g, const Real gv, const Vector< Real > &hv, const Real weight)
Update internal risk measure storage for Hessian-time-a-vector computation.
Teuchos::RCP< const Vector< Real > > getVector(void) const
void update(const Real val, const Vector< Real > &g, const Real weight)
Update internal risk measure storage for gradient computation.
MeanVariance(Teuchos::ParameterList &parlist)
Constructor.
void getGradient(Vector< Real > &g, SampleGenerator< Real > &sampler)
Return risk measure (sub)gradient.
MeanVariance(const Real order, const Real coeff, const Teuchos::RCP< PositiveFunction< Real > > &pf)
Constructor.
void checkInputs(void) const
MeanVariance(const std::vector< Real > &order, const std::vector< Real > &coeff, const Teuchos::RCP< PositiveFunction< Real > > &pf)
Constructor.
Teuchos::RCP< Vector< Real > > dualVector3_
std::vector< Real >::size_type uint
std::vector< Teuchos::RCP< Vector< Real > > > hessvec_storage_
void getHessVec(Vector< Real > &hv, SampleGenerator< Real > &sampler)
Return risk measure Hessian-times-a-vector.
virtual void reset(Teuchos::RCP< Vector< Real > > &x0, const Vector< Real > &x)
Reset internal risk measure storage. Called for value and gradient computation.
void reset(Teuchos::RCP< Vector< Real > > &x0, const Vector< Real > &x, Teuchos::RCP< Vector< Real > > &v0, const Vector< Real > &v)
Reset internal risk measure storage. Called for Hessian-times-a-vector computation.
Provides an interface for the mean plus a sum of arbitrary order variances.
Provides the interface to implement risk measures.
std::vector< Real > value_storage_
Teuchos::RCP< Vector< Real > > dualVector1_