44 #ifndef ROL_MEANVARIANCE_HPP 45 #define ROL_MEANVARIANCE_HPP 52 #include "Teuchos_ParameterList.hpp" 53 #include "Teuchos_Array.hpp" 59 typedef typename std::vector<Real>::size_type
uint;
85 :
RiskMeasure<Real>(), positiveFunction_(pf), firstReset_(true) {
86 order_.clear(); coeff_.clear();
87 order_.push_back((order < 2.0) ? 2.0 : order);
88 coeff_.push_back((coeff < 0.0) ? 1.0 : coeff);
89 NumMoments_ = order_.size();
93 :
RiskMeasure<Real>(), positiveFunction_(pf), firstReset_(true) {
94 order_.clear(); coeff_.clear();
95 NumMoments_ = order.size();
96 if ( NumMoments_ != coeff.size() ) {
97 coeff.resize(NumMoments_,1.0);
100 order_.push_back((order[i] < 2.0) ? 2.0 : order[i]);
101 coeff_.push_back((coeff[i] < 0.0) ? 1.0 : coeff[i]);
106 Teuchos::ParameterList &list
107 = parlist.sublist(
"SOL").sublist(
"Risk Measure").sublist(
"Mean Plus Variance");
109 Teuchos::Array<Real> order
110 = Teuchos::getArrayFromStringParameter<double>(list,
"Orders");
111 Teuchos::Array<Real> coeff
112 = Teuchos::getArrayFromStringParameter<double>(list,
"Coefficients");
114 order_.clear(); coeff_.clear();
115 NumMoments_ = order.size();
116 if ( NumMoments_ != static_cast<uint>(coeff.size()) ) {
117 coeff.resize(NumMoments_,1.0);
120 order_.push_back((order[i] < 2.0) ? 2.0 : order[i]);
121 coeff_.push_back((coeff[i] < 0.0) ? 1.0 : coeff[i]);
124 if ( list.get(
"Deviation Type",
"Upper") ==
"Upper" ) {
135 dualVector1_ = (x0->dual()).clone();
136 dualVector2_ = (x0->dual()).clone();
137 dualVector3_ = (x0->dual()).clone();
138 dualVector4_ = (x0->dual()).clone();
141 dualVector1_->zero(); dualVector2_->zero();
142 dualVector3_->zero(); dualVector4_->zero();
143 value_storage_.clear();
144 gradient_storage_.clear();
145 gradvec_storage_.clear();
146 hessvec_storage_.clear();
157 void update(
const Real val,
const Real weight) {
159 value_storage_.push_back(val);
160 weights_.push_back(weight);
166 value_storage_.push_back(val);
167 gradient_storage_.push_back(g.
clone());
168 typename std::vector<Teuchos::RCP<Vector<Real> > >::iterator it = gradient_storage_.end();
171 weights_.push_back(weight);
180 value_storage_.push_back(val);
181 gradient_storage_.push_back(g.
clone());
182 typename std::vector<Teuchos::RCP<Vector<Real> > >::iterator it = gradient_storage_.end();
185 gradvec_storage_.push_back(gv);
186 hessvec_storage_.push_back(hv.
clone());
187 it = hessvec_storage_.end();
190 weights_.push_back(weight);
197 sampler.
sumAll(&val,&ev,1);
200 Real diff = 0.0, pf0 = 0.0, var = 0.0;
201 for ( uint i = 0; i < weights_.size(); i++ ) {
202 diff = value_storage_[i]-ev;
203 pf0 = positiveFunction_->evaluate(diff,0);
205 val += coeff_[p] * std::pow(pf0,order_[p]) * weights_[i];
208 sampler.
sumAll(&val,&var,1);
216 sampler.
sumAll(&val,&ev,1);
219 Real diff = 0.0, pf0 = 0.0, pf1 = 0.0, c = 0.0, ec = 0.0, ecs = 0.0;
220 for ( uint i = 0; i < weights_.size(); i++ ) {
222 diff = value_storage_[i]-ev;
223 pf0 = positiveFunction_->evaluate(diff,0);
224 pf1 = positiveFunction_->evaluate(diff,1);
226 c += coeff_[p]*order_[p]*std::pow(pf0,order_[p]-1.0)*pf1;
229 dualVector1_->axpy(weights_[i]*c,*(gradient_storage_[i]));
231 sampler.
sumAll(&ec,&ecs,1);
232 dualVector3_->scale(1.0-ecs);
233 sampler.
sumAll(*dualVector1_,*dualVector2_);
234 dualVector3_->plus(*dualVector2_);
243 sampler.
sumAll(&val,&ev,1);
245 sampler.
sumAll(&gv,&egv,1);
249 Real diff = 0.0, pf0 = 0.0, pf1 = 0.0, pf2 = 0.0;
250 Real cg = 0.0, ecg = 0.0, ecgs = 0.0, ch = 0.0, ech = 0.0, echs = 0.0;
251 for ( uint i = 0; i < weights_.size(); i++ ) {
254 diff = value_storage_[i]-ev;
255 pf0 = positiveFunction_->evaluate(diff,0);
256 pf1 = positiveFunction_->evaluate(diff,1);
257 pf2 = positiveFunction_->evaluate(diff,2);
259 cg += coeff_[p]*order_[p]*(gradvec_storage_[i]-egv)*
260 ((order_[p]-1.0)*std::pow(pf0,order_[p]-2.0)*pf1*pf1+
261 std::pow(pf0,order_[p]-1.0)*pf2);
262 ch += coeff_[p]*order_[p]*std::pow(pf0,order_[p]-1.0)*pf1;
264 ecg += weights_[i]*cg;
265 ech += weights_[i]*ch;
266 dualVector1_->axpy(weights_[i]*cg,*(gradient_storage_[i]));
267 dualVector1_->axpy(weights_[i]*ch,*(hessvec_storage_[i]));
269 sampler.
sumAll(&ech,&echs,1);
270 dualVector4_->scale(1.0-echs);
271 sampler.
sumAll(&ecg,&ecgs,1);
272 dualVector4_->axpy(-ecgs,*dualVector3_);
273 sampler.
sumAll(*dualVector1_,*dualVector2_);
274 dualVector4_->plus(*dualVector2_);
Real getValue(SampleGenerator< Real > &sampler)
std::vector< Teuchos::RCP< Vector< Real > > > gradient_storage_
MeanVariance(Real order, Real coeff, Teuchos::RCP< PositiveFunction< Real > > &pf)
std::vector< Real > gradvec_storage_
Teuchos::RCP< PositiveFunction< Real > > positiveFunction_
void reset(Teuchos::RCP< Vector< Real > > &x0, const Vector< Real > &x)
void update(const Real val, const Real weight)
Teuchos::RCP< Vector< Real > > dualVector4_
std::vector< Real > order_
virtual Teuchos::RCP< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
std::vector< Real > weights_
Teuchos::RCP< Vector< Real > > dualVector2_
MeanVariance(std::vector< Real > &order, std::vector< Real > &coeff, Teuchos::RCP< PositiveFunction< Real > > &pf)
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)
void sumAll(Real *input, Real *output, int dim) const
void update(const Real val, const Vector< Real > &g, const Real weight)
Teuchos::RCP< const Vector< Real > > getVector() const
MeanVariance(Teuchos::ParameterList &parlist)
void getGradient(Vector< Real > &g, SampleGenerator< Real > &sampler)
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)
virtual void reset(Teuchos::RCP< Vector< Real > > &x0, const Vector< Real > &x)
void reset(Teuchos::RCP< Vector< Real > > &x0, const Vector< Real > &x, Teuchos::RCP< Vector< Real > > &v0, const Vector< Real > &v)
std::vector< Real > value_storage_
Teuchos::RCP< Vector< Real > > dualVector1_