44 #ifndef ROL_MEANDEVIATIONFROMTARGET_HPP 45 #define ROL_MEANDEVIATIONFROMTARGET_HPP 52 #include "Teuchos_ParameterList.hpp" 53 #include "Teuchos_Array.hpp" 59 typedef typename std::vector<Real>::size_type
uint;
76 std::vector<Teuchos::RCP<Vector<Real> > >
pg0_;
77 std::vector<Teuchos::RCP<Vector<Real> > >
pg_;
78 std::vector<Teuchos::RCP<Vector<Real> > >
phv_;
84 pg_.clear(); pg0_.clear(); phv_.clear(); pval_.clear(); pgv_.clear();
85 pg_.resize(NumMoments_);
86 pg0_.resize(NumMoments_);
87 phv_.resize(NumMoments_);
88 pval_.resize(NumMoments_,0.0);
89 pgv_.resize(NumMoments_,0.0);
96 :
RiskMeasure<Real>(), positiveFunction_(pf), firstReset_(true) {
98 target_.clear(); order_.clear(); coeff_.clear();
99 target_.push_back(target);
100 order_.push_back((order < 2.0) ? 2.0 : order);
101 coeff_.push_back((coeff < 0.0) ? 1.0 : coeff);
102 NumMoments_ = order_.size();
108 :
RiskMeasure<Real>(), positiveFunction_(pf), firstReset_(true) {
110 NumMoments_ = order.size();
111 target_.clear(); order_.clear(); coeff_.clear();
112 if ( NumMoments_ != target.size() ) {
113 target.resize(NumMoments_,0.0);
115 if ( NumMoments_ != coeff.size() ) {
116 coeff.resize(NumMoments_,1.0);
119 target_.push_back(target[i]);
120 order_.push_back((order[i] < 2.0) ? 2.0 : order[i]);
121 coeff_.push_back((coeff[i] < 0.0) ? 1.0 : coeff[i]);
128 Teuchos::ParameterList &list
129 = parlist.sublist(
"SOL").sublist(
"Risk Measure").sublist(
"Mean Plus Deviation From Target");
131 Teuchos::Array<Real> target
132 = Teuchos::getArrayFromStringParameter<double>(list,
"Targets");
133 Teuchos::Array<Real> order
134 = Teuchos::getArrayFromStringParameter<double>(list,
"Orders");
135 Teuchos::Array<Real> coeff
136 = Teuchos::getArrayFromStringParameter<double>(list,
"Coefficients");
138 NumMoments_ = order.size();
139 target_.clear(); order_.clear(); coeff_.clear();
140 if ( NumMoments_ != static_cast<uint>(target.size()) ) {
141 target.resize(NumMoments_,0.0);
143 if ( NumMoments_ != static_cast<uint>(coeff.size()) ) {
144 coeff.resize(NumMoments_,1.0);
147 target_.push_back(target[i]);
148 order_.push_back((order[i] < 2.0) ? 2.0 : order[i]);
149 coeff_.push_back((coeff[i] < 0.0) ? 1.0 : coeff[i]);
153 if ( list.get(
"Deviation Type",
"Upper") ==
"Upper" ) {
165 pg0_[p] = (x0->dual()).clone();
166 pg_[p] = (x0->dual()).clone();
167 phv_[p] = (x0->dual()).clone();
169 dualVector1_ = (x0->dual()).clone();
170 dualVector2_ = (x0->dual()).clone();
171 dualVector3_ = (x0->dual()).clone();
172 dualVector4_ = (x0->dual()).clone();
176 pg0_[p]->zero(); pg_[p]->zero(); phv_[p]->zero();
177 pval_[p] = 0.0; pgv_[p] = 0.0;
179 dualVector1_->zero(); dualVector2_->zero();
180 dualVector3_->zero(); dualVector4_->zero();
190 void update(
const Real val,
const Real weight) {
191 Real diff = 0.0, pf0 = 0.0;
194 diff = val-target_[p];
195 pf0 = positiveFunction_->evaluate(diff,0);
196 pval_[p] += weight * std::pow(pf0,order_[p]);
201 Real diff = 0.0, pf0 = 0.0, pf1 = 0.0, c = 0.0;
203 diff = val-target_[p];
204 pf0 = positiveFunction_->evaluate(diff,0);
205 pf1 = positiveFunction_->evaluate(diff,1);
206 c = std::pow(pf0,order_[p]-1.0) * pf1;
207 (pg_[p])->axpy(weight * c,g);
208 pval_[p] += weight * std::pow(pf0,order_[p]);
215 Real diff = 0.0, pf0 = 0.0, pf1 = 0.0, pf2 = 0.0, p0 = 0.0, p1 = 0.0, p2 = 0.0, c = 0.0;
217 diff = val - target_[p];
218 pf0 = positiveFunction_->evaluate(diff,0);
219 pf1 = positiveFunction_->evaluate(diff,1);
220 pf2 = positiveFunction_->evaluate(diff,2);
221 p0 = std::pow(pf0,order_[p]);
222 p1 = std::pow(pf0,order_[p]-1.0);
223 p2 = std::pow(pf0,order_[p]-2.0);
224 c = -(order_[p]-1.0)*p1*pf1;
225 pg0_[p]->axpy(weight*c,g);
226 c = gv*((order_[p]-1.0)*p2*pf1*pf1 + p1*pf2);
227 pg_[p]->axpy(weight*c,g);
229 phv_[p]->axpy(weight*c,hv);
230 pval_[p] += weight*p0;
231 pgv_[p] += weight*p1*pf1*gv;
239 sampler.
sumAll(&val,&dev,1);
240 std::vector<Real> pval_sum(NumMoments_);
241 sampler.
sumAll(&(pval_)[0],&pval_sum[0],NumMoments_);
243 dev += coeff_[p] * std::pow(pval_sum[p],1.0/order_[p]);
250 std::vector<Real> pval_sum(NumMoments_);
251 sampler.
sumAll(&(pval_)[0],&pval_sum[0],NumMoments_);
252 Teuchos::RCP<Vector<Real> > pg;
254 if ( pval_sum[p] > 0.0 ) {
255 pg = (pg_[p])->clone();
256 sampler.
sumAll(*(pg_[p]),*pg);
257 dualVector1_->axpy(coeff_[p]/std::pow(pval_sum[p],1.0-1.0/order_[p]),*pg);
266 std::vector<Real> pval_sum(NumMoments_);
267 sampler.
sumAll(&(pval_)[0],&pval_sum[0],NumMoments_);
268 std::vector<Real> pgv_sum(NumMoments_);
269 sampler.
sumAll(&(pgv_)[0],&pgv_sum[0],NumMoments_);
272 if ( pval_sum[p] > 0.0 ) {
273 sampler.
sumAll(*(pg_[p]),*dualVector2_);
274 sampler.
sumAll(*(pg0_[p]),*dualVector3_);
275 sampler.
sumAll(*(phv_[p]),*dualVector4_);
276 c = coeff_[p]*(pgv_sum[p]/std::pow(pval_sum[p],2.0-1.0/order_[p]));
277 dualVector1_->axpy(c,*dualVector3_);
278 c = coeff_[p]/std::pow(pval_sum[p],1.0-1.0/order_[p]);
279 dualVector1_->axpy(c,*dualVector2_);
280 dualVector1_->axpy(c,*dualVector4_);
void reset(Teuchos::RCP< Vector< Real > > &x0, const Vector< Real > &x)
MeanDeviationFromTarget(std::vector< Real > &target, std::vector< Real > &order, std::vector< Real > &coeff, Teuchos::RCP< PositiveFunction< Real > > &pf)
std::vector< Real > target_
void getGradient(Vector< Real > &g, SampleGenerator< Real > &sampler)
void update(const Real val, const Vector< Real > &g, const Real gv, const Vector< Real > &hv, const Real weight)
Defines the linear algebra or vector space interface.
void sumAll(Real *input, Real *output, int dim) const
Teuchos::RCP< const Vector< Real > > getVector() const
std::vector< Real > coeff_
std::vector< Real >::size_type uint
Teuchos::RCP< Vector< Real > > dualVector1_
MeanDeviationFromTarget(Real target, Real order, Real coeff, Teuchos::RCP< PositiveFunction< Real > > &pf)
std::vector< Real > pval_
Real getValue(SampleGenerator< Real > &sampler)
std::vector< Teuchos::RCP< Vector< Real > > > phv_
void update(const Real val, const Real weight)
Teuchos::RCP< Vector< Real > > dualVector2_
Teuchos::RCP< PositiveFunction< Real > > positiveFunction_
Teuchos::RCP< Vector< Real > > dualVector4_
void reset(Teuchos::RCP< Vector< Real > > &x0, const Vector< Real > &x, Teuchos::RCP< Vector< Real > > &v0, const Vector< Real > &v)
virtual void reset(Teuchos::RCP< Vector< Real > > &x0, const Vector< Real > &x)
MeanDeviationFromTarget(Teuchos::ParameterList &parlist)
std::vector< Real > order_
Teuchos::RCP< Vector< Real > > dualVector3_
std::vector< Teuchos::RCP< Vector< Real > > > pg_
std::vector< Teuchos::RCP< Vector< Real > > > pg0_
void getHessVec(Vector< Real > &hv, SampleGenerator< Real > &sampler)
void update(const Real val, const Vector< Real > &g, const Real weight)