44 #ifndef ROL_SROMGENERATOR_HPP
45 #define ROL_SROMGENERATOR_HPP
66 std::vector<Ptr<Distribution<Real>>>
dist_;
80 std::vector<std::vector<Real>> pts;
81 std::vector<Real> wts;
84 pts.push_back(*(atom.
getAtom(i)));
88 numMySamples_ = wts.size();
94 pt = pts[i]; ind.clear();
98 err += std::pow(pt[d] - pts[j][d],2);
100 err = std::sqrt(err);
104 pts[i][d] += pts[j][d];
109 if ( ind.size() > 0 ) {
111 pts[i][d] /= (Real)(ind.size()+1);
113 for (
int k = ind.size()-1; k >= 0; k--) {
114 pts.erase(pts.begin()+ind[k]);
115 wts.erase(wts.begin()+ind[k]);
118 numMySamples_ = wts.size();
121 Real psum = 0.0, sum = 0.0;
139 std::ostream &outStream = std::cout)
143 ROL::ParameterList &list = parlist.sublist(
"SOL").sublist(
"Sample Generator").sublist(
"SROM");
145 adaptive_ = list.get(
"Adaptive Sampling",
false);
146 numNewSamples_ = list.get(
"Number of New Samples Per Adaptation",0);
147 ptol_ = list.get(
"Probability Tolerance",1.e2*std::sqrt(ROL_EPSILON<Real>()));
148 atol_ = list.get(
"Atom Tolerance",1.e2*std::sqrt(ROL_EPSILON<Real>()));
149 bool presolve = list.get(
"Presolve for Atom Locations",
false);
157 Ptr<ProbabilityVector<Real>> prob, prob_lo, prob_hi, prob_eq;
158 Ptr<AtomVector<Real>> atom, atom_lo, atom_hi, atom_eq;
159 Ptr<Vector<Real>> x, x_lo, x_hi, x_eq;
160 initialize_vectors(prob,prob_lo,prob_hi,prob_eq,atom,atom_lo,atom_hi,atom_eq,x,x_lo,x_hi,x_eq,bman);
161 Ptr<Vector<Real>> l = makePtr<SingletonVector<Real>>(0.0);
163 Ptr<BoundConstraint<Real>> bnd = makePtr<Bounds<Real>>(x_lo,x_hi);
164 Ptr<Constraint<Real>> con = makePtr<ScalarLinearConstraint<Real>>(x_eq,1.0);
166 ROL::ParameterList pslist(list);
167 pslist.sublist(
"Step").set(
"Type",
"Trust Region");
171 optSolver.
solve(outStream);
176 optProblem.
check(outStream);
178 optSolver.
solve(outStream);
188 typw.clear(); typx.clear();
191 Real mean = 1, var = 1, one(1);
193 mean = std::abs(
dist_[j]->moment(1));
194 var =
dist_[j]->moment(2) - mean*mean;
195 mean = ((mean > ROL_EPSILON<Real>()) ? mean : std::sqrt(var));
196 mean = ((mean > ROL_EPSILON<Real>()) ? mean : one);
198 typx[i*dimension_ + j] = one/(mean*mean);
217 std::vector<Real> typx, typw;
222 std::vector<Real> wt_lo(numMySamples_,0.), wt_hi(numMySamples_,1.);
223 std::vector<Real> pt_eq(
dimension_*numMySamples_,0.), wt_eq(numMySamples_,1.);
224 Real lo = 0., hi = 0.;
227 lo =
dist_[j]->lowerBound();
228 hi =
dist_[j]->upperBound();
230 pt[i*dimension_ + j] =
dist_[j]->invertCDF((Real)rand()/(Real)RAND_MAX);
232 pt_lo[i*dimension_ + j] = lo;
233 pt_hi[i*dimension_ + j] = hi;
237 prob = makePtr<PrimalProbabilityVector<Real>>(
238 makePtr<std::vector<Real>>(wt),bman,
239 makePtr<std::vector<Real>>(typw));
240 atom = makePtr<PrimalAtomVector<Real>>(
241 makePtr<std::vector<Real>>(pt),bman,numMySamples_,dimension_,
242 makePtr<std::vector<Real>>(typx));
243 vec = makePtr<SROMVector<Real>>(prob,atom);
245 prob_lo = makePtr<PrimalProbabilityVector<Real>>(
246 makePtr<std::vector<Real>>(wt_lo),bman,
247 makePtr<std::vector<Real>>(typw));
248 prob_hi = makePtr<PrimalProbabilityVector<Real>>(
249 makePtr<std::vector<Real>>(wt_hi),bman,
250 makePtr<std::vector<Real>>(typw));
252 atom_lo = makePtr<PrimalAtomVector<Real>>(
253 makePtr<std::vector<Real>>(pt_lo),bman,numMySamples_,dimension_,
254 makePtr<std::vector<Real>>(typx));
255 atom_hi = makePtr<PrimalAtomVector<Real>>(
256 makePtr<std::vector<Real>>(pt_hi),bman,numMySamples_,dimension_,
257 makePtr<std::vector<Real>>(typx));
259 vec_lo = makePtr<SROMVector<Real>>(prob_lo,atom_lo);
260 vec_hi = makePtr<SROMVector<Real>>(prob_hi,atom_hi);
262 prob_eq = makePtr<DualProbabilityVector<Real>>(
263 makePtr<std::vector<Real>>(wt_eq),bman,
264 makePtr<std::vector<Real>>(typw));
265 atom_eq = makePtr<DualAtomVector<Real>>(
266 makePtr<std::vector<Real>>(pt_eq),bman,numMySamples_,dimension_,
267 makePtr<std::vector<Real>>(typx));
268 vec_eq = makePtr<SROMVector<Real>>(prob_eq,atom_eq);
273 const bool optProb,
const bool optAtom,
274 ROL::ParameterList &list)
const {
275 std::vector<Ptr<Objective<Real>>> obj_vec;
277 Real scale = list.get(
"CDF Smoothing Parameter",1.e-2);
280 std::vector<int> tmp_order
281 = ROL::getArrayFromStringParameter<int>(list,
"Moments");
282 std::vector<int> order(tmp_order.size(),0);
283 for (
unsigned int i = 0; i < tmp_order.size(); i++) {
284 order[i] =
static_cast<int>(tmp_order[i]);
288 std::vector<Real> tmp_coeff
289 = ROL::getArrayFromStringParameter<Real>(list,
"Coefficients");
290 std::vector<Real> coeff(2,0.);
291 coeff[0] = tmp_coeff[0]; coeff[1] = tmp_coeff[1];
292 return makePtr<LinearCombinationObjective<Real>>(coeff,obj_vec);
Provides the std::vector implementation of the ROL::Vector interface.
const Real getProbability(const int i) const
ROL::Ptr< const std::vector< Real > > getAtom(const int i) const
int numGlobalSamples(void) const
Defines the linear algebra or vector space interface.
void initialize_vectors(Ptr< ProbabilityVector< Real >> &prob, Ptr< ProbabilityVector< Real >> &prob_lo, Ptr< ProbabilityVector< Real >> &prob_hi, Ptr< ProbabilityVector< Real >> &prob_eq, Ptr< AtomVector< Real >> &atom, Ptr< AtomVector< Real >> &atom_lo, Ptr< AtomVector< Real >> &atom_hi, Ptr< AtomVector< Real >> &atom_eq, Ptr< Vector< Real >> &vec, Ptr< Vector< Real >> &vec_lo, Ptr< Vector< Real >> &vec_hi, Ptr< Vector< Real >> &vec_eq, const Ptr< BatchManager< Real >> &bman) const
void sumAll(Real *input, Real *output, int dim) const
SROMGenerator(ROL::ParameterList &parlist, const Ptr< BatchManager< Real >> &bman, const std::vector< Ptr< Distribution< Real >>> &dist, std::ostream &outStream=std::cout)
ROL::ParameterList parlist_
void get_scaling_vectors(std::vector< Real > &typw, std::vector< Real > &typx) const
Provides the std::vector implementation of the ROL::Vector interface.
Provides a simplified interface for solving a wide range of optimization problems.
std::vector< Ptr< Distribution< Real > > > dist_
Ptr< Objective< Real > > initialize_objective(const std::vector< Ptr< Distribution< Real >>> &dist, const Ptr< BatchManager< Real >> &bman, const bool optProb, const bool optAtom, ROL::ParameterList &list) const
void check(std::ostream &outStream=std::cout, const int numSteps=ROL_NUM_CHECKDERIV_STEPS, const int order=1)
void setPoints(std::vector< std::vector< Real > > &p)
int solve(const ROL::Ptr< StatusTest< Real > > &status=ROL::nullPtr, const bool combineStatus=true)
Solve optimization problem with no iteration output.
void setWeights(std::vector< Real > &w)
void pruneSamples(const ProbabilityVector< Real > &prob, const AtomVector< Real > &atom)