44 #ifndef ROL_SROMGENERATOR_HPP 45 #define ROL_SROMGENERATOR_HPP 71 std::vector<Teuchos::RCP<Distribution<Real> > >
dist_;
86 std::vector<std::vector<Real> > pts;
87 std::vector<Real> wts;
90 pts.push_back(*(atom.
getAtom(i)));
100 pt = pts[i]; ind.clear();
104 err += std::pow(pt[d] - pts[j][d],2);
106 err = std::sqrt(err);
110 pts[i][d] += pts[j][d];
115 if ( ind.size() > 0 ) {
117 pts[i][d] /= (Real)(ind.size()+1);
119 for (
int k = ind.size()-1; k >= 0; k--) {
120 pts.erase(pts.begin()+ind[k]);
121 wts.erase(wts.begin()+ind[k]);
127 Real psum = 0.0, sum = 0.0;
148 Teuchos::ParameterList list = parlist.sublist(
"SOL").sublist(
"Sample Generator").sublist(
"SROM");
150 adaptive_ = list.get(
"Adaptive Sampling",
false);
151 numNewSamples_ = list.get(
"Number of New Samples Per Adaptation",0);
152 print_ = list.get(
"Output to Screen",
false);
153 ptol_ = list.get(
"Probability Tolerance",1.e2*std::sqrt(ROL_EPSILON<Real>()));
154 atol_ = list.get(
"Atom Tolerance",1.e2*std::sqrt(ROL_EPSILON<Real>()));
163 Teuchos::RCP<ProbabilityVector<Real> > prob, prob_lo, prob_hi, prob_eq;
164 Teuchos::RCP<AtomVector<Real> > atom, atom_lo, atom_hi, atom_eq;
165 Teuchos::RCP<Vector<Real> > x, x_lo, x_hi, x_eq;
166 initialize_vectors(prob,prob_lo,prob_hi,prob_eq,atom,atom_lo,atom_hi,atom_eq,x,x_lo,x_hi,x_eq,bman);
167 Teuchos::RCP<Vector<Real> > l
168 = Teuchos::rcp(
new StdVector<Real>(Teuchos::rcp(
new std::vector<Real>(1,0.))));
169 bool optProb =
false, optAtom =
true;
170 for (
int i = 0; i < 2; i++ ) {
171 if ( i == 0 ) { optProb =
false; optAtom =
true; }
172 if ( i == 1 ) { optProb =
true; optAtom =
true; }
174 std::vector<Teuchos::RCP<Objective<Real> > > obj_vec;
175 Teuchos::RCP<Objective<Real> > obj;
178 Teuchos::RCP<BoundConstraint<Real> > bnd
180 Teuchos::RCP<EqualityConstraint<Real> > con
183 if (
print_ ) { std::cout <<
"\nCheck derivatives of CDFObjective\n"; }
185 if (
print_ ) { std::cout <<
"\nCheck derivatives of MomentObjective\n"; }
187 if (
print_ ) { std::cout <<
"\nCheck derivatives of LinearCombinationObjective\n"; }
189 if (
print_ && optProb ) { std::cout <<
"\nCheck ScalarLinearEqualityConstraint\n"; }
192 Teuchos::RCP<Algorithm<Real> > algo;
195 std::string type = list.sublist(
"Step").get(
"Type",
"Trust Region");
196 Teuchos::RCP<Teuchos::ParameterList> plist = Teuchos::rcpFromRef(list);
197 Teuchos::RCP<OptimizationProblem<Real> > optProblem;
198 if (type ==
"Augmented Lagrangian") {
199 Teuchos::RCP<Objective<Real> > augLag
203 else if (type ==
"Moreau-Yosida Penalty") {
204 Teuchos::RCP<Objective<Real> > myPen
212 algo->run(*optProblem,
print_);
215 algo->run(*x,*obj,*bnd,
print_);
227 typw.clear(); typx.clear();
230 Real mean = 1, var = 1, one(1);
232 mean = std::abs(
dist_[j]->moment(1));
233 var =
dist_[j]->moment(2) - mean*mean;
234 mean = ((mean > ROL_EPSILON<Real>()) ? mean : std::sqrt(var));
235 mean = ((mean > ROL_EPSILON<Real>()) ? mean : one);
256 std::vector<Real> typx, typw;
263 Real lo = 0., hi = 0.;
266 lo =
dist_[j]->lowerBound();
267 hi =
dist_[j]->upperBound();
269 pt[i*
dimension_ + j] =
dist_[j]->invertCDF((Real)rand()/(Real)RAND_MAX);
277 Teuchos::rcp(
new std::vector<Real>(wt)),bman,
278 Teuchos::rcp(
new std::vector<Real>(typw))));
281 Teuchos::rcp(
new std::vector<Real>(typx))));
285 Teuchos::rcp(
new std::vector<Real>(wt_lo)),bman,
286 Teuchos::rcp(
new std::vector<Real>(typw))));
288 Teuchos::rcp(
new std::vector<Real>(wt_hi)),bman,
289 Teuchos::rcp(
new std::vector<Real>(typw))));
293 Teuchos::rcp(
new std::vector<Real>(typx))));
296 Teuchos::rcp(
new std::vector<Real>(typx))));
302 Teuchos::rcp(
new std::vector<Real>(wt_eq)),bman,
303 Teuchos::rcp(
new std::vector<Real>(typw))));
306 Teuchos::rcp(
new std::vector<Real>(typx))));
314 const bool optProb,
const bool optAtom,
315 Teuchos::ParameterList &list)
const {
317 Real scale = list.get(
"CDF Smoothing Parameter",1.e-2);
318 obj_vec.push_back(Teuchos::rcp(
new CDFObjective<Real>(dist,bman,scale,optProb,optAtom)));
320 Teuchos::Array<int> tmp_order
321 = Teuchos::getArrayFromStringParameter<int>(list,
"Moments");
322 std::vector<int> order(tmp_order.size(),0);
323 for (
int i = 0; i < tmp_order.size(); i++) {
324 order[i] =
static_cast<int>(tmp_order[i]);
328 Teuchos::Array<Real> tmp_coeff
329 = Teuchos::getArrayFromStringParameter<Real>(list,
"Coefficients");
330 std::vector<Real> coeff(2,0.);
331 coeff[0] = tmp_coeff[0]; coeff[1] = tmp_coeff[1];
336 Teuchos::ParameterList &parlist,
337 const bool optProb)
const {
338 std::string type = parlist.sublist(
"Step").get(
"Type",
"Trust Region");
340 if ( type ==
"Moreau-Yosida Penalty" ) {
341 algo = Teuchos::rcp(
new Algorithm<Real>(
"Moreau-Yosida Penalty",parlist,
false));
343 else if ( type ==
"Augmented Lagrangian" ) {
344 algo = Teuchos::rcp(
new Algorithm<Real>(
"Augmented Lagrangian",parlist,
false));
347 algo = Teuchos::rcp(
new Algorithm<Real>(
"Interior Point",parlist,
false));
351 algo = Teuchos::rcp(
new Algorithm<Real>(
"Trust Region",parlist,
false));
358 const bool optProb,
const bool optAtom) {
360 std::vector<Real> typx, typw;
365 wt[i] = (optProb ? (Real)rand()/(Real)RAND_MAX : 0);
367 pt[i*
dimension_ + j] = (optAtom ?
dist_[j]->invertCDF((Real)rand()/(Real)RAND_MAX) : 0);
370 Teuchos::RCP<ProbabilityVector<Real> > dprob
372 Teuchos::rcp(
new std::vector<Real>(wt)),bman,
373 Teuchos::rcp(
new std::vector<Real>(typw))));
374 Teuchos::RCP<AtomVector<Real> > datom
377 Teuchos::rcp(
new std::vector<Real>(typx))));
380 obj->checkGradient(x,d,
print_);
381 obj->checkHessVec(x,d,
print_);
387 const bool optProb) {
391 std::vector<Real> typx, typw;
396 wt[i] = (Real)rand()/(Real)RAND_MAX;
398 pt[i*
dimension_ + j] =
dist_[j]->invertCDF((Real)rand()/(Real)RAND_MAX);
401 Teuchos::RCP<ProbabilityVector<Real> > dprob
403 Teuchos::rcp(
new std::vector<Real>(wt)),bman,
404 Teuchos::rcp(
new std::vector<Real>(typw))));
405 Teuchos::RCP<AtomVector<Real> > datom
408 Teuchos::rcp(
new std::vector<Real>(typx))));
411 con->checkApplyJacobian(x,d,c,
print_);
412 con->checkAdjointConsistencyJacobian(c,d,x,
print_);
Provides the interface to evaluate objective functions.
Provides the interface to evaluate the augmented Lagrangian.
Provides the std::vector implementation of the ROL::Vector interface.
This equality constraint defines an affine hyperplane.
void check_objective(const Vector< Real > &x, const Teuchos::RCP< Objective< Real > > &obj, const Teuchos::RCP< BatchManager< Real > > &bman, const bool optProb, const bool optAtom)
void check_constraint(const Vector< Real > &x, const Teuchos::RCP< EqualityConstraint< Real > > &con, const Teuchos::RCP< BatchManager< Real > > &bman, const bool optProb)
void sumAll(Real *input, Real *output, int dim) const
void initialize_optimizer(Teuchos::RCP< Algorithm< Real > > &algo, Teuchos::ParameterList &parlist, const bool optProb) const
Defines the linear algebra or vector space interface.
void get_scaling_vectors(std::vector< Real > &typw, std::vector< Real > &typx) const
Defines the equality constraint operator interface.
void initialize_vectors(Teuchos::RCP< ProbabilityVector< Real > > &prob, Teuchos::RCP< ProbabilityVector< Real > > &prob_lo, Teuchos::RCP< ProbabilityVector< Real > > &prob_hi, Teuchos::RCP< ProbabilityVector< Real > > &prob_eq, Teuchos::RCP< AtomVector< Real > > &atom, Teuchos::RCP< AtomVector< Real > > &atom_lo, Teuchos::RCP< AtomVector< Real > > &atom_hi, Teuchos::RCP< AtomVector< Real > > &atom_eq, Teuchos::RCP< Vector< Real > > &vec, Teuchos::RCP< Vector< Real > > &vec_lo, Teuchos::RCP< Vector< Real > > &vec_hi, Teuchos::RCP< Vector< Real > > &vec_eq, const Teuchos::RCP< BatchManager< Real > > &bman) const
Provides an interface to run optimization algorithms.
Provides the interface to evaluate the Moreau-Yosida penalty function.
Teuchos::RCP< const std::vector< Real > > getAtom(const int i) const
Teuchos::ParameterList parlist_
Provides the std::vector implementation of the ROL::Vector interface.
void initialize_objective(std::vector< Teuchos::RCP< Objective< Real > > > &obj_vec, Teuchos::RCP< Objective< Real > > &obj, const std::vector< Teuchos::RCP< Distribution< Real > > > &dist, const Teuchos::RCP< BatchManager< Real > > &bman, const bool optProb, const bool optAtom, Teuchos::ParameterList &list) const
Provides the std::vector implementation of the ROL::Vector interface.
SROMGenerator(Teuchos::ParameterList &parlist, const Teuchos::RCP< BatchManager< Real > > &bman, const std::vector< Teuchos::RCP< Distribution< Real > > > &dist)
Provides the interface to apply upper and lower bound constraints.
const Real getProbability(const int i) const
std::vector< Teuchos::RCP< Distribution< Real > > > dist_
void setPoints(std::vector< std::vector< Real > > &p)
void setWeights(std::vector< Real > &w)
void pruneSamples(const ProbabilityVector< Real > &prob, const AtomVector< Real > &atom)