44 #ifndef ROL_STOCHASTICPROBLEM_HPP 45 #define ROL_STOCHASTICPROBLEM_HPP 61 #include "Teuchos_ParameterList.hpp" 74 Teuchos::RCP<Objective<Real> >
obj_;
75 Teuchos::RCP<Vector<Real> >
vec_;
76 Teuchos::RCP<BoundConstraint<Real> >
bnd_;
86 : parlist_(Teuchos::null),
87 ORIGINAL_obj_(Teuchos::null), ORIGINAL_vec_(Teuchos::null), ORIGINAL_bnd_(Teuchos::null),
88 obj_(Teuchos::null), vec_(Teuchos::null), bnd_(Teuchos::null),
89 vsampler_(Teuchos::null), gsampler_(Teuchos::null), hsampler_(Teuchos::null),
93 : ORIGINAL_obj_(Teuchos::null), ORIGINAL_vec_(Teuchos::null), ORIGINAL_bnd_(Teuchos::null),
94 obj_(Teuchos::null), vec_(Teuchos::null), bnd_(Teuchos::null),
95 vsampler_(Teuchos::null), gsampler_(Teuchos::null), hsampler_(Teuchos::null),
97 parlist_ = Teuchos::rcp(&parlist,
false);
105 ORIGINAL_obj_(obj), ORIGINAL_vec_(vec), ORIGINAL_bnd_(Teuchos::null),
106 obj_(Teuchos::null), vec_(Teuchos::null), bnd_(Teuchos::null),
107 vsampler_(sampler), gsampler_(sampler), hsampler_(sampler),
109 parlist_ = Teuchos::rcp(&parlist,
false);
120 ORIGINAL_obj_(obj), ORIGINAL_vec_(vec), ORIGINAL_bnd_(Teuchos::null),
121 obj_(Teuchos::null), vec_(Teuchos::null), bnd_(Teuchos::null),
122 vsampler_(vsampler), gsampler_(gsampler), hsampler_(gsampler),
124 parlist_ = Teuchos::rcp(&parlist,
false);
136 ORIGINAL_obj_(obj), ORIGINAL_vec_(vec), ORIGINAL_bnd_(Teuchos::null),
137 obj_(Teuchos::null), vec_(Teuchos::null), bnd_(Teuchos::null),
138 vsampler_(vsampler), gsampler_(gsampler), hsampler_(hsampler),
140 parlist_ = Teuchos::rcp(&parlist,
false);
151 ORIGINAL_obj_(obj), ORIGINAL_vec_(vec), ORIGINAL_bnd_(bnd),
152 obj_(Teuchos::null), vec_(Teuchos::null), bnd_(Teuchos::null),
153 vsampler_(sampler), gsampler_(sampler), hsampler_(sampler),
155 parlist_ = Teuchos::rcp(&parlist,
false);
168 ORIGINAL_obj_(obj), ORIGINAL_vec_(vec), ORIGINAL_bnd_(bnd),
169 obj_(Teuchos::null), vec_(Teuchos::null), bnd_(Teuchos::null),
170 vsampler_(vsampler), gsampler_(gsampler), hsampler_(gsampler),
172 parlist_ = Teuchos::rcp(&parlist,
false);
186 ORIGINAL_obj_(obj), ORIGINAL_vec_(vec), ORIGINAL_bnd_(bnd),
187 obj_(Teuchos::null), vec_(Teuchos::null), bnd_(Teuchos::null),
188 vsampler_(vsampler), gsampler_(gsampler), hsampler_(hsampler),
190 parlist_ = Teuchos::rcp(&parlist,
false);
197 parlist_ = Teuchos::rcp(&parlist,
false);
198 if (ORIGINAL_obj_ != Teuchos::null) {
201 if (ORIGINAL_vec_ != Teuchos::null) {
204 if (ORIGINAL_bnd_ != Teuchos::null) {
210 vsampler_ = vsampler;
211 if ( gsampler_ == Teuchos::null ) {
214 if ( hsampler_ == Teuchos::null ) {
220 gsampler_ = gsampler;
221 if ( hsampler_ == Teuchos::null ) {
227 hsampler_ = hsampler;
231 if ( parlist_ == Teuchos::null ) {
232 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::invalid_argument,
233 ">>> ERROR (ROL::StochasticProblem): parameter list not set!");
237 if ( vsampler_ == Teuchos::null ) {
238 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::invalid_argument,
239 ">>> ERROR (ROL::StochasticProblem): value sampler not set!");
243 std::string type = parlist_->sublist(
"SOL").get(
"Stochastic Optimization Type",
"Risk Neutral");
244 if ( type ==
"Risk Neutral" ) {
245 bool storage = parlist_->sublist(
"SOL").get(
"Store Sampled Value and Gradient",
true);
248 else if ( type ==
"Risk Averse" ) {
251 else if ( type ==
"BPOE" ) {
252 Real order = parlist_->sublist(
"SOL").sublist(
"BPOE").get(
"Moment Order",1.);
253 Real threshold = parlist_->sublist(
"SOL").sublist(
"BPOE").get(
"Threshold",0.);
254 obj_ = Teuchos::rcp(
new BPOEObjective<Real>(obj,order,threshold,vsampler_,gsampler_,hsampler_));
256 else if ( type ==
"Mean Value" ) {
258 obj->setParameter(mean);
262 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::logic_error,
263 "Invalid stochastic optimization type" << type);
272 if ( parlist_ == Teuchos::null ) {
273 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::invalid_argument,
274 ">>> ERROR (ROL::StochasticProblem): parameter list not set!");
279 std::string type = parlist_->sublist(
"SOL").get(
"Stochastic Optimization Type",
"Risk Neutral");
280 if ( type ==
"Risk Neutral" || type ==
"Mean Value" ) {
283 else if ( type ==
"Risk Averse" ) {
286 else if ( type ==
"BPOE" ) {
287 std::vector<Real> stat(1,1.);
291 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::logic_error,
292 "Invalid stochastic optimization type" << type);
301 if ( parlist_ == Teuchos::null ) {
302 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::invalid_argument,
303 ">>> ERROR (ROL::StochasticProblem): parameter list not set!");
308 std::string type = parlist_->sublist(
"SOL").get(
"Stochastic Optimization Type",
"Risk Neutral");
309 if ( type ==
"Risk Averse" || type ==
"BPOE" ) {
320 if ( parlist_ == Teuchos::null ) {
321 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::invalid_argument,
322 ">>> ERROR (ROL::StochasticProblem): parameter list not set!");
327 std::string type = parlist_->sublist(
"SOL").get(
"Stochastic Optimization Type",
"Risk Neutral");
328 if ( type ==
"Risk Neutral" || type ==
"Mean Value" ) {
331 else if ( type ==
"Risk Averse" ) {
332 std::string name = parlist_->sublist(
"SOL").sublist(
"Risk Measure").get(
"Name",
"CVaR");
333 if ( name ==
"KL Divergence" ) {
340 else if ( type ==
"BPOE" ) {
344 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::logic_error,
345 "Invalid stochastic optimization type" << type);
363 if ( parlist_ == Teuchos::null ) {
364 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::invalid_argument,
365 ">>> ERROR (ROL::StochasticProblem): parameter list not set!");
371 std::string type = parlist_->sublist(
"SOL").get(
"Stochastic Optimization Type",
"Risk Neutral");
373 if ( type ==
"Risk Averse" ) {
374 Teuchos::ParameterList &list
375 = parlist_->sublist(
"SOL").sublist(
"Risk Measure");
376 std::string risk = list.get(
"Name",
"CVaR");
377 if ( risk ==
"Mixed-Quantile Quadrangle" ) {
378 Teuchos::ParameterList &MQQlist = list.sublist(
"Mixed-Quantile Quadrangle");
379 Teuchos::Array<Real> coeff
380 = Teuchos::getArrayFromStringParameter<Real>(MQQlist,
"Coefficient Array");
381 for (
int i = 0; i < coeff.size(); i++) {
385 else if ( risk ==
"Quantile-Radius Quadrangle" ) {
397 catch (std::exception &e) {
404 const bool printToStream =
true,
405 std::ostream & outStream = std::cout,
407 const int order = 1 ) {
408 Teuchos::RCP<Vector<Real> > dp = d.
clone();
415 const bool printToStream =
true,
416 std::ostream & outStream = std::cout,
418 const int order = 1 ) {
419 Teuchos::RCP<Vector<Real> > vp = v.
clone();
428 int dim = sampler->getMyPoint(0).size(), nsamp = sampler->numMySamples();
429 std::vector<Real> loc(dim,0.0), mean(dim,0.0), pt(dim,0.0);
431 for (
int i = 0; i < nsamp; i++) {
432 pt = sampler->getMyPoint(i);
433 wt = sampler->getMyWeight(i);
434 for (
int j = 0; j < dim; j++) {
438 sampler->sumAll(&loc[0],&mean[0],dim);
443 if ( parlist_ == Teuchos::null ) {
444 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::invalid_argument,
445 ">>> ERROR (ROL::StochasticProblem): parameter list not set!");
449 std::string type = parlist_->sublist(
"SOL").get(
"Stochastic Optimization Type",
"Risk Neutral");
450 if ( type ==
"Risk Neutral" || type ==
"Mean Value" ) {
453 else if ( type ==
"Risk Averse" ) {
456 else if ( type ==
"BPOE" ) {
457 std::vector<Real> stat(1,1.);
461 TEUCHOS_TEST_FOR_EXCEPTION(
true,std::logic_error,
462 "Invalid stochastic optimization type" << type);
void setObjective(const Teuchos::RCP< ParametrizedObjective< Real > > &obj)
StochasticProblem(Teuchos::ParameterList &parlist, const Teuchos::RCP< ParametrizedObjective< Real > > &obj, const Teuchos::RCP< SampleGenerator< Real > > &vsampler, const Teuchos::RCP< SampleGenerator< Real > > &gsampler, const Teuchos::RCP< Vector< Real > > &vec)
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)
StochasticProblem(Teuchos::ParameterList &parlist, const Teuchos::RCP< ParametrizedObjective< Real > > &obj, const Teuchos::RCP< SampleGenerator< Real > > &sampler, const Teuchos::RCP< Vector< Real > > &vec)
std::vector< Real > computeSampleMean(Teuchos::RCP< SampleGenerator< Real > > &sampler)
Teuchos::RCP< Vector< Real > > createVector(Teuchos::RCP< Vector< Real > > &vec)
void setGradientSampleGenerator(const Teuchos::RCP< SampleGenerator< Real > > &gsampler)
const Real getStatistic(const int i=0) const
virtual Teuchos::RCP< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
Teuchos::RCP< BoundConstraint< Real > > bnd_
Defines the linear algebra or vector space interface.
void setHessVecSampleGenerator(const Teuchos::RCP< SampleGenerator< Real > > &hsampler)
Teuchos::RCP< SampleGenerator< Real > > vsampler_
Teuchos::RCP< BoundConstraint< Real > > ORIGINAL_bnd_
void setObjective(const Teuchos::RCP< Objective< Real > > &obj)
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)
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< ParametrizedObjective< 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)
Provides the interface to apply upper and lower bound constraints.
Teuchos::RCP< SampleGenerator< Real > > gsampler_
Teuchos::RCP< ParametrizedObjective< Real > > ORIGINAL_obj_
Teuchos::RCP< Vector< Real > > vec_
#define ROL_NUM_CHECKDERIV_STEPS
Number of steps for derivative checks.
Teuchos::RCP< Teuchos::ParameterList > parlist_
StochasticProblem(Teuchos::ParameterList &parlist, const Teuchos::RCP< ParametrizedObjective< Real > > &obj, const Teuchos::RCP< SampleGenerator< Real > > &sampler, const Teuchos::RCP< Vector< Real > > &vec, const Teuchos::RCP< BoundConstraint< Real > > &bnd)
void setSolutionStatistic(const Real stat)
StochasticProblem(Teuchos::ParameterList &parlist, const Teuchos::RCP< ParametrizedObjective< 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)
void setValueSampleGenerator(const Teuchos::RCP< SampleGenerator< Real > > &vsampler)
void setBoundConstraint(const Teuchos::RCP< BoundConstraint< Real > > &bnd)
void setBoundConstraint(const Teuchos::RCP< BoundConstraint< Real > > &bnd)
StochasticProblem(Teuchos::ParameterList &parlist)
StochasticProblem(Teuchos::ParameterList &parlist, const Teuchos::RCP< ParametrizedObjective< 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)
void setSolutionVector(const Teuchos::RCP< Vector< Real > > &vec)
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_
Teuchos::RCP< SampleGenerator< Real > > hsampler_