44 #ifndef ROL_STOCHASTICPROBLEM_HPP 45 #define ROL_STOCHASTICPROBLEM_HPP 64 #include "Teuchos_ParameterList.hpp" 78 Teuchos::RCP<Objective<Real> >
obj_;
79 Teuchos::RCP<Vector<Real> >
vec_;
80 Teuchos::RCP<BoundConstraint<Real> >
bnd_;
81 Teuchos::RCP<EqualityConstraint<Real> >
con_;
92 parlist_(Teuchos::null),
93 ORIGINAL_obj_(Teuchos::null), ORIGINAL_vec_(Teuchos::null),
94 ORIGINAL_bnd_(Teuchos::null), ORIGINAL_con_(Teuchos::null),
95 obj_(Teuchos::null), vec_(Teuchos::null),
96 bnd_(Teuchos::null), con_(Teuchos::null),
97 vsampler_(Teuchos::null), gsampler_(Teuchos::null), hsampler_(Teuchos::null),
102 ORIGINAL_obj_(Teuchos::null), ORIGINAL_vec_(Teuchos::null),
103 ORIGINAL_bnd_(Teuchos::null), ORIGINAL_con_(Teuchos::null),
104 obj_(Teuchos::null), vec_(Teuchos::null),
105 bnd_(Teuchos::null), con_(Teuchos::null),
106 vsampler_(Teuchos::null), gsampler_(Teuchos::null), hsampler_(Teuchos::null),
108 parlist_ = Teuchos::rcpFromRef(parlist);
116 ORIGINAL_obj_(obj), ORIGINAL_vec_(vec),
117 ORIGINAL_bnd_(Teuchos::null), ORIGINAL_con_(Teuchos::null),
118 obj_(Teuchos::null), vec_(Teuchos::null),
119 bnd_(Teuchos::null), con_(Teuchos::null),
120 vsampler_(sampler), gsampler_(sampler), hsampler_(sampler),
122 parlist_ = Teuchos::rcpFromRef(parlist);
135 ORIGINAL_obj_(obj), ORIGINAL_vec_(vec),
136 ORIGINAL_bnd_(Teuchos::null), ORIGINAL_con_(Teuchos::null),
137 obj_(Teuchos::null), vec_(Teuchos::null),
138 bnd_(Teuchos::null), con_(Teuchos::null),
139 vsampler_(vsampler), gsampler_(gsampler), hsampler_(gsampler),
141 parlist_ = Teuchos::rcpFromRef(parlist);
155 ORIGINAL_obj_(obj), ORIGINAL_vec_(vec),
156 ORIGINAL_bnd_(Teuchos::null), ORIGINAL_con_(Teuchos::null),
157 obj_(Teuchos::null), vec_(Teuchos::null),
158 bnd_(Teuchos::null), con_(Teuchos::null),
159 vsampler_(vsampler), gsampler_(gsampler), hsampler_(hsampler),
161 parlist_ = Teuchos::rcpFromRef(parlist);
174 ORIGINAL_obj_(obj), ORIGINAL_vec_(vec),
175 ORIGINAL_bnd_(bnd), ORIGINAL_con_(Teuchos::null),
176 obj_(Teuchos::null), vec_(Teuchos::null),
177 bnd_(Teuchos::null), con_(Teuchos::null),
178 vsampler_(sampler), gsampler_(sampler), hsampler_(sampler),
180 parlist_ = Teuchos::rcpFromRef(parlist);
194 ORIGINAL_obj_(obj), ORIGINAL_vec_(vec),
195 ORIGINAL_bnd_(bnd), ORIGINAL_con_(Teuchos::null),
196 obj_(Teuchos::null), vec_(Teuchos::null),
197 bnd_(Teuchos::null), con_(Teuchos::null),
198 vsampler_(vsampler), gsampler_(gsampler), hsampler_(gsampler),
200 parlist_ = Teuchos::rcpFromRef(parlist);
215 ORIGINAL_obj_(obj), ORIGINAL_vec_(vec),
216 ORIGINAL_bnd_(bnd), ORIGINAL_con_(Teuchos::null),
217 obj_(Teuchos::null), vec_(Teuchos::null),
218 bnd_(Teuchos::null), con_(Teuchos::null),
219 vsampler_(vsampler), gsampler_(gsampler), hsampler_(hsampler),
221 parlist_ = Teuchos::rcpFromRef(parlist);
234 ORIGINAL_obj_(obj), ORIGINAL_vec_(vec),
235 ORIGINAL_bnd_(Teuchos::null), ORIGINAL_con_(con),
236 obj_(Teuchos::null), vec_(Teuchos::null),
237 bnd_(Teuchos::null), con_(Teuchos::null),
238 vsampler_(sampler), gsampler_(sampler), hsampler_(sampler),
240 parlist_ = Teuchos::rcpFromRef(parlist);
254 ORIGINAL_obj_(obj), ORIGINAL_vec_(vec),
255 ORIGINAL_bnd_(Teuchos::null), ORIGINAL_con_(con),
256 obj_(Teuchos::null), vec_(Teuchos::null),
257 bnd_(Teuchos::null), con_(Teuchos::null),
258 vsampler_(vsampler), gsampler_(gsampler), hsampler_(gsampler),
260 parlist_ = Teuchos::rcpFromRef(parlist);
275 ORIGINAL_obj_(obj), ORIGINAL_vec_(vec),
276 ORIGINAL_bnd_(Teuchos::null), ORIGINAL_con_(con),
277 obj_(Teuchos::null), vec_(Teuchos::null),
278 bnd_(Teuchos::null), con_(Teuchos::null),
279 vsampler_(vsampler), gsampler_(gsampler), hsampler_(hsampler),
281 parlist_ = Teuchos::rcpFromRef(parlist);
295 ORIGINAL_obj_(obj), ORIGINAL_vec_(vec),
296 ORIGINAL_bnd_(bnd), ORIGINAL_con_(con),
297 obj_(Teuchos::null), vec_(Teuchos::null),
298 bnd_(Teuchos::null), con_(Teuchos::null),
299 vsampler_(sampler), gsampler_(sampler), hsampler_(sampler),
301 parlist_ = Teuchos::rcpFromRef(parlist);
316 ORIGINAL_obj_(obj), ORIGINAL_vec_(vec),
317 ORIGINAL_bnd_(bnd), ORIGINAL_con_(con),
318 obj_(Teuchos::null), vec_(Teuchos::null),
319 bnd_(Teuchos::null), con_(Teuchos::null),
320 vsampler_(vsampler), gsampler_(gsampler), hsampler_(gsampler),
322 parlist_ = Teuchos::rcpFromRef(parlist);
338 ORIGINAL_obj_(obj), ORIGINAL_vec_(vec),
339 ORIGINAL_bnd_(bnd), ORIGINAL_con_(con),
340 obj_(Teuchos::null), vec_(Teuchos::null),
341 bnd_(Teuchos::null), con_(Teuchos::null),
342 vsampler_(vsampler), gsampler_(gsampler), hsampler_(hsampler),
344 parlist_ = Teuchos::rcpFromRef(parlist);
352 parlist_ = Teuchos::rcpFromRef(parlist);
353 if (ORIGINAL_obj_ != Teuchos::null) {
356 if (ORIGINAL_vec_ != Teuchos::null) {
359 if (ORIGINAL_bnd_ != Teuchos::null) {
365 vsampler_ = vsampler;
366 if ( gsampler_ == Teuchos::null ) {
369 if ( hsampler_ == Teuchos::null ) {
375 gsampler_ = gsampler;
376 if ( hsampler_ == Teuchos::null ) {
382 hsampler_ = hsampler;
386 if ( parlist_ == Teuchos::null ) {
387 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::invalid_argument,
388 ">>> ERROR (ROL::StochasticProblem): parameter list not set!");
392 if ( vsampler_ == Teuchos::null ) {
393 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::invalid_argument,
394 ">>> ERROR (ROL::StochasticProblem): value sampler not set!");
398 std::string type = parlist_->sublist(
"SOL").get(
"Stochastic Optimization Type",
"Risk Neutral");
399 if ( type ==
"Risk Neutral" ) {
400 bool storage = parlist_->sublist(
"SOL").get(
"Store Sampled Value and Gradient",
true);
403 else if ( type ==
"Risk Averse" ) {
406 else if ( type ==
"BPOE" ) {
407 Real order = parlist_->sublist(
"SOL").sublist(
"BPOE").get(
"Moment Order",1.);
408 Real threshold = parlist_->sublist(
"SOL").sublist(
"BPOE").get(
"Threshold",0.);
409 obj_ = Teuchos::rcp(
new BPOEObjective<Real>(obj,order,threshold,vsampler_,gsampler_,hsampler_));
411 else if ( type ==
"Mean Value" ) {
413 obj->setParameter(mean);
417 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::logic_error,
418 "Invalid stochastic optimization type" << type);
427 if ( parlist_ == Teuchos::null ) {
428 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::invalid_argument,
429 ">>> ERROR (ROL::StochasticProblem): parameter list not set!");
434 std::string type = parlist_->sublist(
"SOL").get(
"Stochastic Optimization Type",
"Risk Neutral");
435 if ( type ==
"Risk Neutral" || type ==
"Mean Value" ) {
438 else if ( type ==
"Risk Averse" ) {
441 else if ( type ==
"BPOE" ) {
442 std::vector<Real> stat(1,1);
446 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::logic_error,
447 "Invalid stochastic optimization type" << type);
456 if ( parlist_ == Teuchos::null ) {
457 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::invalid_argument,
458 ">>> ERROR (ROL::StochasticProblem): parameter list not set!");
463 std::string type = parlist_->sublist(
"SOL").get(
"Stochastic Optimization Type",
"Risk Neutral");
464 if ( type ==
"Risk Averse" || type ==
"BPOE" ) {
475 if ( parlist_ == Teuchos::null ) {
476 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::invalid_argument,
477 ">>> ERROR (ROL::StochasticProblem): parameter list not set!");
482 std::string type = parlist_->sublist(
"SOL").get(
"Stochastic Optimization Type",
"Risk Neutral");
483 if ( type ==
"Risk Neutral" || type ==
"Mean Value" ) {
486 else if ( type ==
"Risk Averse" || type ==
"BPOE" ) {
490 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::logic_error,
491 "Invalid stochastic optimization type" << type);
499 if ( parlist_ == Teuchos::null ) {
500 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::invalid_argument,
501 ">>> ERROR (ROL::StochasticProblem): parameter list not set!");
505 if ( con != Teuchos::null ) {
507 std::string type = parlist_->sublist(
"SOL").get(
"Stochastic Optimization Type",
"Risk Neutral");
508 if ( type ==
"Risk Neutral" || type ==
"Mean Value" ) {
511 else if ( type ==
"Risk Averse" || type ==
"BPOE" ) {
515 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::logic_error,
516 "Invalid stochastic optimization type" << type);
538 if ( parlist_ == Teuchos::null ) {
539 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::invalid_argument,
540 ">>> ERROR (ROL::StochasticProblem): parameter list not set!");
546 std::string type = parlist_->sublist(
"SOL").get(
"Stochastic Optimization Type",
"Risk Neutral");
548 if ( type ==
"Risk Averse" ) {
549 Teuchos::ParameterList &list
550 = parlist_->sublist(
"SOL").sublist(
"Risk Measure");
551 std::string risk = list.get(
"Name",
"CVaR");
552 if ( risk ==
"Mixed-Quantile Quadrangle" ) {
553 Teuchos::ParameterList &MQQlist = list.sublist(
"Mixed-Quantile Quadrangle");
554 Teuchos::Array<Real> coeff
555 = Teuchos::getArrayFromStringParameter<Real>(MQQlist,
"Coefficient Array");
556 for (
int i = 0; i < coeff.size(); i++) {
560 else if ( risk ==
"Super Quantile Quadrangle" ) {
564 else if ( risk ==
"Chebyshev-Kusuoka" ) {
568 else if ( risk ==
"Spectral Risk" ) {
572 else if ( risk ==
"Quantile-Radius Quadrangle" ) {
585 catch (std::exception &e) {
592 const bool printToStream =
true,
593 std::ostream & outStream = std::cout,
595 const int order = 1 ) {
596 Teuchos::RCP<Vector<Real> > dp = d.
clone();
598 Real stat(5.1264386);
604 const bool printToStream =
true,
605 std::ostream & outStream = std::cout,
607 const int order = 1 ) {
608 Teuchos::RCP<Vector<Real> > vp = v.
clone();
610 Real stat(3.223468906);
618 Teuchos::RCP<SampleGenerator<Real> > samp = sampler;
619 if ( sampler == Teuchos::null ) {
623 int width = prec + 5 + 4;
624 std::stringstream name;
625 name << filename <<
"_" << samp->batchID() <<
".txt";
626 std::ofstream file(name.str().c_str());
627 if (file.is_open()) {
628 Real val(0), tol(ROL_EPSILON<Real>());
629 std::vector<Real> sample;
630 file << std::scientific << std::setprecision(prec);
631 for (
int i = 0; i < samp->numMySamples(); ++i) {
632 sample = samp->getMyPoint(i);
633 obj_->setParameter(sample);
634 val = ORIGINAL_obj_->value(*ORIGINAL_vec_,tol);
635 for (
int j = 0; j < static_cast<int>(sample.size()); ++j) {
636 file << std::setw(width) << std::left << sample[j];
638 file << std::setw(width) << std::left << val << std::endl;
643 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::invalid_argument,
644 ">>> (ROL::StochasticProblem::printObjectiveDistribution): Unable to open file!");
651 int dim = sampler->getMyPoint(0).size(), nsamp = sampler->numMySamples();
652 std::vector<Real> loc(dim), mean(dim), pt(dim);
654 for (
int i = 0; i < nsamp; i++) {
655 pt = sampler->getMyPoint(i);
656 wt = sampler->getMyWeight(i);
657 for (
int j = 0; j < dim; j++) {
661 sampler->sumAll(&loc[0],&mean[0],dim);
666 if ( parlist_ == Teuchos::null ) {
667 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::invalid_argument,
668 ">>> ERROR (ROL::StochasticProblem): parameter list not set!");
672 std::string type = parlist_->sublist(
"SOL").get(
"Stochastic Optimization Type",
"Risk Neutral");
673 if ( type ==
"Risk Neutral" || type ==
"Mean Value" ) {
676 else if ( type ==
"Risk Averse" ) {
679 else if ( type ==
"BPOE" ) {
680 std::vector<Real> statistic(1,stat);
684 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::logic_error,
685 "Invalid stochastic optimization type" << type);
Provides the interface to evaluate objective functions.
StochasticProblem(Teuchos::ParameterList &parlist, const Teuchos::RCP< Objective< Real > > &obj, const Teuchos::RCP< SampleGenerator< Real > > &vsampler, const Teuchos::RCP< SampleGenerator< Real > > &gsampler, const Teuchos::RCP< SampleGenerator< Real > > &hsampler, const Teuchos::RCP< Vector< Real > > &vec)
StochasticProblem(Teuchos::ParameterList &parlist, const Teuchos::RCP< Objective< Real > > &obj, const Teuchos::RCP< SampleGenerator< Real > > &sampler, const Teuchos::RCP< Vector< Real > > &vec, const Teuchos::RCP< EqualityConstraint< Real > > &con)
virtual std::vector< std::vector< Real > > checkObjectiveGradient(const Vector< Real > &d, const bool printToStream=true, std::ostream &outStream=std::cout, const int numSteps=ROL_NUM_CHECKDERIV_STEPS, const int order=1)
Teuchos::RCP< EqualityConstraint< Real > > con_
std::vector< Real > computeSampleMean(Teuchos::RCP< SampleGenerator< Real > > &sampler)
void setGradientSampleGenerator(const Teuchos::RCP< SampleGenerator< Real > > &gsampler)
virtual Teuchos::RCP< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
Real computeStatistic(const Vector< Real > &x) const
StochasticProblem(Teuchos::ParameterList &parlist, const Teuchos::RCP< Objective< Real > > &obj, const Teuchos::RCP< SampleGenerator< Real > > &vsampler, const Teuchos::RCP< SampleGenerator< Real > > &gsampler, const Teuchos::RCP< SampleGenerator< Real > > &hsampler, const Teuchos::RCP< Vector< Real > > &vec, const Teuchos::RCP< BoundConstraint< Real > > &bnd)
Teuchos::RCP< BoundConstraint< Real > > bnd_
Defines the linear algebra or vector space interface.
void setHessVecSampleGenerator(const Teuchos::RCP< SampleGenerator< Real > > &hsampler)
StochasticProblem(Teuchos::ParameterList &parlist, const Teuchos::RCP< Objective< Real > > &obj, const Teuchos::RCP< SampleGenerator< Real > > &sampler, const Teuchos::RCP< Vector< Real > > &vec)
Teuchos::RCP< SampleGenerator< Real > > vsampler_
StochasticProblem(Teuchos::ParameterList &parlist, const Teuchos::RCP< Objective< Real > > &obj, const Teuchos::RCP< SampleGenerator< Real > > &sampler, const Teuchos::RCP< Vector< Real > > &vec, const Teuchos::RCP< BoundConstraint< Real > > &bnd)
Teuchos::RCP< EqualityConstraint< Real > > ORIGINAL_con_
void setObjective(const Teuchos::RCP< Objective< Real > > &obj)
Teuchos::RCP< BoundConstraint< Real > > ORIGINAL_bnd_
void setObjective(const Teuchos::RCP< Objective< Real > > &obj)
Defines the equality constraint operator interface.
std::vector< std::vector< Real > > checkObjectiveGradient(const Vector< Real > &d, const bool printToStream=true, std::ostream &outStream=std::cout, const int numSteps=ROL_NUM_CHECKDERIV_STEPS, const int order=1)
void setSolutionVector(const Teuchos::RCP< Vector< Real > > &sol)
void setStatistic(const Real stat)
Teuchos::RCP< Vector< Real > > ORIGINAL_vec_
void setParameterList(Teuchos::ParameterList &parlist)
Provides an interface for the risk measure associated with the super quantile quadrangle.
Provides an interface for spectral risk measures.
std::vector< std::vector< Real > > checkObjectiveHessVec(const Vector< Real > &v, const bool printToStream=true, std::ostream &outStream=std::cout, const int numSteps=ROL_NUM_CHECKDERIV_STEPS, const int order=1)
StochasticProblem(Teuchos::ParameterList &parlist, const Teuchos::RCP< Objective< Real > > &obj, const Teuchos::RCP< SampleGenerator< Real > > &vsampler, const Teuchos::RCP< SampleGenerator< Real > > &gsampler, const Teuchos::RCP< Vector< Real > > &vec, const Teuchos::RCP< BoundConstraint< Real > > &bnd)
Provides the interface to apply upper and lower bound constraints.
Teuchos::RCP< SampleGenerator< Real > > gsampler_
Teuchos::RCP< Vector< Real > > vec_
#define ROL_NUM_CHECKDERIV_STEPS
Number of steps for derivative checks.
Teuchos::RCP< Objective< Real > > ORIGINAL_obj_
Teuchos::RCP< Teuchos::ParameterList > parlist_
void setEqualityConstraint(const Teuchos::RCP< EqualityConstraint< Real > > &con)
Teuchos::RCP< const StdVector< Real > > getStatistic(void) const
void setSolutionStatistic(const Real stat)
Teuchos::RCP< Vector< Real > > createVector(Teuchos::RCP< Vector< Real > > &vec, Real stat=1)
void setValueSampleGenerator(const Teuchos::RCP< SampleGenerator< Real > > &vsampler)
void setBoundConstraint(const Teuchos::RCP< BoundConstraint< Real > > &bnd)
StochasticProblem(Teuchos::ParameterList &parlist, const Teuchos::RCP< Objective< Real > > &obj, const Teuchos::RCP< SampleGenerator< Real > > &sampler, const Teuchos::RCP< Vector< Real > > &vec, const Teuchos::RCP< BoundConstraint< Real > > &bnd, const Teuchos::RCP< EqualityConstraint< Real > > &con)
StochasticProblem(Teuchos::ParameterList &parlist, const Teuchos::RCP< Objective< Real > > &obj, const Teuchos::RCP< SampleGenerator< Real > > &vsampler, const Teuchos::RCP< SampleGenerator< Real > > &gsampler, const Teuchos::RCP< SampleGenerator< Real > > &hsampler, const Teuchos::RCP< Vector< Real > > &vec, const Teuchos::RCP< BoundConstraint< Real > > &bnd, const Teuchos::RCP< EqualityConstraint< Real > > &con)
void setEqualityConstraint(const Teuchos::RCP< EqualityConstraint< Real > > &con)
void setBoundConstraint(const Teuchos::RCP< BoundConstraint< Real > > &bnd)
StochasticProblem(Teuchos::ParameterList &parlist)
void printObjectiveSamples(const std::string &filename="objectiveSamples", const int prec=12, const Teuchos::RCP< SampleGenerator< Real > > &sampler=Teuchos::null)
void setSolutionVector(const Teuchos::RCP< Vector< Real > > &vec)
StochasticProblem(Teuchos::ParameterList &parlist, const Teuchos::RCP< Objective< Real > > &obj, const Teuchos::RCP< SampleGenerator< Real > > &vsampler, const Teuchos::RCP< SampleGenerator< Real > > &gsampler, const Teuchos::RCP< SampleGenerator< Real > > &hsampler, const Teuchos::RCP< Vector< Real > > &vec, const Teuchos::RCP< EqualityConstraint< Real > > &con)
virtual std::vector< std::vector< Real > > checkObjectiveHessVec(const Vector< Real > &v, const bool printToStream=true, std::ostream &outStream=std::cout, const int numSteps=ROL_NUM_CHECKDERIV_STEPS, const int order=1)
Real getSolutionStatistic(void)
Teuchos::RCP< Objective< Real > > obj_
StochasticProblem(Teuchos::ParameterList &parlist, const Teuchos::RCP< Objective< Real > > &obj, const Teuchos::RCP< SampleGenerator< Real > > &vsampler, const Teuchos::RCP< SampleGenerator< Real > > &gsampler, const Teuchos::RCP< Vector< Real > > &vec, const Teuchos::RCP< EqualityConstraint< Real > > &con)
StochasticProblem(Teuchos::ParameterList &parlist, const Teuchos::RCP< Objective< Real > > &obj, const Teuchos::RCP< SampleGenerator< Real > > &vsampler, const Teuchos::RCP< SampleGenerator< Real > > &gsampler, const Teuchos::RCP< Vector< Real > > &vec)
StochasticProblem(Teuchos::ParameterList &parlist, const Teuchos::RCP< Objective< Real > > &obj, const Teuchos::RCP< SampleGenerator< Real > > &vsampler, const Teuchos::RCP< SampleGenerator< Real > > &gsampler, const Teuchos::RCP< Vector< Real > > &vec, const Teuchos::RCP< BoundConstraint< Real > > &bnd, const Teuchos::RCP< EqualityConstraint< Real > > &con)
Provides an interface for the Chebyshev-Kusuoka risk measure.
Teuchos::RCP< SampleGenerator< Real > > hsampler_