44 #ifndef ROL_MEANDEVIATIONFROMTARGET_HPP 45 #define ROL_MEANDEVIATIONFROMTARGET_HPP 52 #include "Teuchos_ParameterList.hpp" 53 #include "Teuchos_Array.hpp" 79 typedef typename std::vector<Real>::size_type
uint;
96 std::vector<Teuchos::RCP<Vector<Real> > >
pg0_;
97 std::vector<Teuchos::RCP<Vector<Real> > >
pg_;
98 std::vector<Teuchos::RCP<Vector<Real> > >
phv_;
114 TEUCHOS_TEST_FOR_EXCEPTION((oSize!=cSize),std::invalid_argument,
115 ">>> ERROR (ROL::MeanDeviationFromTarget): Order and coefficient arrays have different sizes!");
116 TEUCHOS_TEST_FOR_EXCEPTION((oSize!=tSize),std::invalid_argument,
117 ">>> ERROR (ROL::MeanDeviationFromTarget): Order and target arrays have different sizes!");
118 Real zero(0), two(2);
119 for (
int i = 0; i < oSize; i++) {
120 TEUCHOS_TEST_FOR_EXCEPTION((
order_[i] < two), std::invalid_argument,
121 ">>> ERROR (ROL::MeanDeviationFromTarget): Element of order array out of range!");
122 TEUCHOS_TEST_FOR_EXCEPTION((
coeff_[i] < zero), std::invalid_argument,
123 ">>> ERROR (ROL::MeanDeviationFromTarget): Element of coefficient array out of range!");
125 TEUCHOS_TEST_FOR_EXCEPTION(
positiveFunction_ == Teuchos::null, std::invalid_argument,
126 ">>> ERROR (ROL::MeanDeviationFromTarget): PositiveFunction pointer is null!");
162 const std::vector<Real> &order,
163 const std::vector<Real> &coeff,
167 for (
uint i = 0; i < target.size(); i++ ) {
170 for (
uint i = 0; i < order.size(); i++ ) {
171 order_.push_back(order[i]);
173 for (
uint i = 0; i < coeff.size(); i++ ) {
174 coeff_.push_back(coeff[i]);
195 Teuchos::ParameterList &list
196 = parlist.sublist(
"SOL").sublist(
"Risk Measure").sublist(
"Mean Plus Deviation From Target");
198 Teuchos::Array<Real> target
199 = Teuchos::getArrayFromStringParameter<double>(list,
"Targets");
201 Teuchos::Array<Real> order
202 = Teuchos::getArrayFromStringParameter<double>(list,
"Orders");
203 order_ = order.toVector();
204 Teuchos::Array<Real> coeff
205 = Teuchos::getArrayFromStringParameter<double>(list,
"Coefficients");
206 coeff_ = coeff.toVector();
208 std::string type = list.get<std::string>(
"Deviation Type");
209 if ( type ==
"Upper" ) {
212 else if ( type ==
"Absolute" ) {
216 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::invalid_argument,
217 ">>> (ROL::MeanDeviation): Deviation type is not recoginized!");
230 pg0_[p] = (x0->dual()).clone();
231 pg_[p] = (x0->dual()).clone();
232 phv_[p] = (x0->dual()).clone();
255 void update(
const Real val,
const Real weight) {
256 Real diff(0), pf0(0);
266 Real diff(0), pf0(0), pf1(0), c(0), one(1);
271 c = std::pow(pf0,
order_[p]-one) * pf1;
272 (
pg_[p])->axpy(weight * c,g);
280 Real diff(0), pf0(0), pf1(0), pf2(0), p0(0), p1(0), p2(0), c(0), one(1), two(2);
286 p0 = std::pow(pf0,
order_[p]);
287 p1 = std::pow(pf0,
order_[p]-one);
288 p2 = std::pow(pf0,
order_[p]-two);
289 c = -(
order_[p]-one)*p1*pf1;
290 pg0_[p]->axpy(weight*c,g);
291 c = gv*((
order_[p]-one)*p2*pf1*pf1 + p1*pf2);
292 pg_[p]->axpy(weight*c,g);
294 phv_[p]->axpy(weight*c,hv);
295 pval_[p] += weight*p0;
296 pgv_[p] += weight*p1*pf1*gv;
303 sampler.
sumAll(&val,&dev,1);
313 Real zero(0), one(1);
317 Teuchos::RCP<Vector<Real> > pg;
319 if ( pval_sum[p] > zero ) {
320 pg = (
pg_[p])->clone();
330 Real zero(0), one(1), two(2);
338 if ( pval_sum[p] > zero ) {
342 c =
coeff_[p]*(pgv_sum[p]/std::pow(pval_sum[p],two-one/
order_[p]));
void reset(Teuchos::RCP< Vector< Real > > &x0, const Vector< Real > &x)
Reset internal risk measure storage. Called for value and gradient computation.
std::vector< Real > target_
void getGradient(Vector< Real > &g, SampleGenerator< Real > &sampler)
Return risk measure (sub)gradient.
void sumAll(Real *input, Real *output, int dim) const
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.
Provides an interface for the mean plus a sum of arbitrary order deviations from targets.
Defines the linear algebra or vector space interface.
Teuchos::RCP< const Vector< Real > > getVector(void) const
std::vector< Real > coeff_
std::vector< Real >::size_type uint
Teuchos::RCP< Vector< Real > > dualVector1_
MeanDeviationFromTarget(const Real target, const Real order, const Real coeff, const Teuchos::RCP< PositiveFunction< Real > > &pf)
Constructor.
std::vector< Real > pval_
Real getValue(SampleGenerator< Real > &sampler)
Return risk measure value.
std::vector< Teuchos::RCP< Vector< Real > > > phv_
void update(const Real val, const Real weight)
Update internal risk measure storage for value computation.
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)
Reset internal risk measure storage. Called for Hessian-times-a-vector computation.
virtual void reset(Teuchos::RCP< Vector< Real > > &x0, const Vector< Real > &x)
Reset internal risk measure storage. Called for value and gradient computation.
MeanDeviationFromTarget(Teuchos::ParameterList &parlist)
Constructor.
void checkInputs(void) const
MeanDeviationFromTarget(const std::vector< Real > &target, const std::vector< Real > &order, const std::vector< Real > &coeff, const Teuchos::RCP< PositiveFunction< Real > > &pf)
Constructor.
std::vector< Real > order_
Teuchos::RCP< Vector< Real > > dualVector3_
std::vector< Teuchos::RCP< Vector< Real > > > pg_
std::vector< Teuchos::RCP< Vector< Real > > > pg0_
Provides the interface to implement risk measures.
void getHessVec(Vector< Real > &hv, SampleGenerator< Real > &sampler)
Return risk measure Hessian-times-a-vector.
void update(const Real val, const Vector< Real > &g, const Real weight)
Update internal risk measure storage for gradient computation.