10 #ifndef ROL_SROMGENERATOR_HPP
11 #define ROL_SROMGENERATOR_HPP
32 std::vector<Ptr<Distribution<Real>>>
dist_;
46 std::vector<std::vector<Real>> pts;
47 std::vector<Real> wts;
50 pts.push_back(*(atom.
getAtom(i)));
54 numMySamples_ = wts.size();
60 pt = pts[i]; ind.clear();
64 err += std::pow(pt[d] - pts[j][d],2);
70 pts[i][d] += pts[j][d];
75 if ( ind.size() > 0 ) {
77 pts[i][d] /= (Real)(ind.size()+1);
79 for (
int k = ind.size()-1; k >= 0; k--) {
80 pts.erase(pts.begin()+ind[k]);
81 wts.erase(wts.begin()+ind[k]);
84 numMySamples_ = wts.size();
87 Real psum = 0.0, sum = 0.0;
105 std::ostream &outStream = std::cout)
109 ROL::ParameterList &list = parlist.sublist(
"SOL").sublist(
"Sample Generator").sublist(
"SROM");
111 adaptive_ = list.get(
"Adaptive Sampling",
false);
112 numNewSamples_ = list.get(
"Number of New Samples Per Adaptation",0);
113 ptol_ = list.get(
"Probability Tolerance",1.e2*std::sqrt(ROL_EPSILON<Real>()));
114 atol_ = list.get(
"Atom Tolerance",1.e2*std::sqrt(ROL_EPSILON<Real>()));
115 bool presolve = list.get(
"Presolve for Atom Locations",
false);
123 Ptr<ProbabilityVector<Real>> prob, prob_lo, prob_hi, prob_eq;
124 Ptr<AtomVector<Real>> atom, atom_lo, atom_hi, atom_eq;
125 Ptr<Vector<Real>> x, x_lo, x_hi, x_eq;
126 initialize_vectors(prob,prob_lo,prob_hi,prob_eq,atom,atom_lo,atom_hi,atom_eq,x,x_lo,x_hi,x_eq,bman);
127 Ptr<Vector<Real>> l = makePtr<SingletonVector<Real>>(0.0);
129 Ptr<BoundConstraint<Real>> bnd = makePtr<Bounds<Real>>(x_lo,x_hi);
130 Ptr<Constraint<Real>> con = makePtr<ScalarLinearConstraint<Real>>(x_eq,1.0);
132 ROL::ParameterList pslist(list);
133 pslist.sublist(
"Step").set(
"Type",
"Trust Region");
137 optSolver.
solve(outStream);
142 optProblem.
check(outStream);
144 optSolver.
solve(outStream);
154 typw.clear(); typx.clear();
157 Real mean = 1, var = 1, one(1);
159 mean = std::abs(
dist_[j]->moment(1));
160 var =
dist_[j]->moment(2) - mean*mean;
161 mean = ((mean > ROL_EPSILON<Real>()) ? mean : std::sqrt(var));
162 mean = ((mean > ROL_EPSILON<Real>()) ? mean : one);
164 typx[i*dimension_ + j] = one/(mean*mean);
183 std::vector<Real> typx, typw;
188 std::vector<Real> wt_lo(numMySamples_,0.), wt_hi(numMySamples_,1.);
189 std::vector<Real> pt_eq(
dimension_*numMySamples_,0.), wt_eq(numMySamples_,1.);
190 Real lo = 0., hi = 0.;
193 lo =
dist_[j]->lowerBound();
194 hi =
dist_[j]->upperBound();
196 pt[i*dimension_ + j] =
dist_[j]->invertCDF((Real)rand()/(Real)RAND_MAX);
198 pt_lo[i*dimension_ + j] = lo;
199 pt_hi[i*dimension_ + j] = hi;
203 prob = makePtr<PrimalProbabilityVector<Real>>(
204 makePtr<std::vector<Real>>(wt),bman,
205 makePtr<std::vector<Real>>(typw));
206 atom = makePtr<PrimalAtomVector<Real>>(
207 makePtr<std::vector<Real>>(pt),bman,numMySamples_,dimension_,
208 makePtr<std::vector<Real>>(typx));
209 vec = makePtr<SROMVector<Real>>(prob,atom);
211 prob_lo = makePtr<PrimalProbabilityVector<Real>>(
212 makePtr<std::vector<Real>>(wt_lo),bman,
213 makePtr<std::vector<Real>>(typw));
214 prob_hi = makePtr<PrimalProbabilityVector<Real>>(
215 makePtr<std::vector<Real>>(wt_hi),bman,
216 makePtr<std::vector<Real>>(typw));
218 atom_lo = makePtr<PrimalAtomVector<Real>>(
219 makePtr<std::vector<Real>>(pt_lo),bman,numMySamples_,dimension_,
220 makePtr<std::vector<Real>>(typx));
221 atom_hi = makePtr<PrimalAtomVector<Real>>(
222 makePtr<std::vector<Real>>(pt_hi),bman,numMySamples_,dimension_,
223 makePtr<std::vector<Real>>(typx));
225 vec_lo = makePtr<SROMVector<Real>>(prob_lo,atom_lo);
226 vec_hi = makePtr<SROMVector<Real>>(prob_hi,atom_hi);
228 prob_eq = makePtr<DualProbabilityVector<Real>>(
229 makePtr<std::vector<Real>>(wt_eq),bman,
230 makePtr<std::vector<Real>>(typw));
231 atom_eq = makePtr<DualAtomVector<Real>>(
232 makePtr<std::vector<Real>>(pt_eq),bman,numMySamples_,dimension_,
233 makePtr<std::vector<Real>>(typx));
234 vec_eq = makePtr<SROMVector<Real>>(prob_eq,atom_eq);
239 const bool optProb,
const bool optAtom,
240 ROL::ParameterList &list)
const {
241 std::vector<Ptr<Objective<Real>>> obj_vec;
243 Real scale = list.get(
"CDF Smoothing Parameter",1.e-2);
246 std::vector<int> tmp_order
247 = ROL::getArrayFromStringParameter<int>(list,
"Moments");
248 std::vector<int> order(tmp_order.size(),0);
249 for (
unsigned int i = 0; i < tmp_order.size(); i++) {
250 order[i] =
static_cast<int>(tmp_order[i]);
254 std::vector<Real> tmp_coeff
255 = ROL::getArrayFromStringParameter<Real>(list,
"Coefficients");
256 std::vector<Real> coeff(2,0.);
257 coeff[0] = tmp_coeff[0]; coeff[1] = tmp_coeff[1];
258 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)