44 #ifndef ROL_MONTECARLOGENERATOR_HPP
45 #define ROL_MONTECARLOGENERATOR_HPP
60 std::vector<std::vector<Real> >
data_;
68 std::vector<Teuchos::RCP<ROL::Distribution<Real> > >
dist_;
71 std::vector<Real> coeff;
73 Real tmp = c * (std::sqrt(M_PI)/2.0 * input);
77 while (std::abs(tmp) > 1.e-4*std::abs(val)) {
79 for (
unsigned i = 0; i < coeff.size(); i++ ) {
80 c += coeff[i]*coeff[coeff.size()-1-i]/((i+1)*(2*i+1));
82 tmp = c/(2.0*(Real)cnt+1.0) * std::pow(std::sqrt(M_PI)/2.0 * input,2.0*(Real)cnt+1.0);
95 int frac = this->
nSamp_ / nProc;
96 int rem = this->
nSamp_ % nProc;
102 std::vector<std::vector<Real> > pts;
105 for (
unsigned i = 0; i < N; i++ ) {
106 srand(123456*(rank*N + (i+1)));
108 p.resize(this->
data_.size(),0.0);
109 for (
unsigned j = 0; j < this->
data_.size(); j++ ) {
111 p[j] = std::sqrt(2.0*(this->
data_[j])[1])*this->
ierf(2.0*((Real)rand())/((Real)RAND_MAX)-1.0) +
115 p[j] = ((this->
data_[j])[1]-(this->
data_[j])[0])*((Real)rand())/((Real)RAND_MAX)+(this->
data_[j])[0];
120 p.resize(
dist_.size(),0.0);
121 for (
unsigned j = 0; j <
dist_.size(); j++ ) {
122 p[j] = (
dist_[j])->invcdf((Real)rand()/(Real)RAND_MAX);
124 p[j] = (
dist_[j])->invcdf((Real)rand()/(Real)RAND_MAX);
130 std::vector<Real> wts(N,1.0/((Real)this->
nSamp_));
135 std::vector<std::vector<Real> >
sample(
int nSamp,
bool store =
true) {
140 int frac = nSamp / nProc;
141 int rem = nSamp % nProc;
147 std::vector<std::vector<Real> > pts;
150 for (
unsigned i = 0; i < N; i++ ) {
151 srand(123456*(rank*N + (i+1)));
153 p.resize(this->
data_.size(),0.0);
154 for (
unsigned j = 0; j < this->
data_.size(); j++ ) {
156 p[j] = std::sqrt(2.0*(this->
data_[j])[1])*this->
ierf(2.0*((Real)rand())/((Real)RAND_MAX)-1.0) +
160 p[j] = ((this->
data_[j])[1]-(this->
data_[j])[0])*((Real)rand())/((Real)RAND_MAX)+(this->
data_[j])[0];
165 p.resize(
dist_.size(),0.0);
166 for (
unsigned j = 0; j <
dist_.size(); j++ ) {
167 p[j] = (
dist_[j])->invcdf((Real)rand()/(Real)RAND_MAX);
169 p[j] = (
dist_[j])->invcdf((Real)rand()/(Real)RAND_MAX);
176 std::vector<Real> wts(N,1.0/((Real)nSamp));
186 bool use_SA =
false,
bool adaptive =
false,
int numNewSamps = 0 )
195 bool use_SA =
false,
bool adaptive =
false,
int numNewSamps = 0 )
199 unsigned dim = bounds.size();
202 for (
unsigned j = 0; j < dim; j++ ) {
203 if ( (bounds[j])[0] > (bounds[j])[1] ) {
204 tmp = (bounds[j])[0];
205 (bounds[j])[0] = (bounds[j])[1];
206 (bounds[j])[1] = tmp;
207 data_.push_back(bounds[j]);
209 data_.push_back(bounds[j]);
216 bool use_SA =
false,
bool adaptive =
false,
int numNewSamps = 0 )
220 unsigned dim = mean.size();
222 std::vector<Real> tmp(2,0.0);
223 for (
unsigned j = 0; j < dim; j++ ) {
226 data_.push_back(tmp);
260 return std::sqrt(var/(this->
nSamp_))*1.e-8;
274 ng = (vals[cnt])->norm();
288 return std::sqrt(var/(this->
nSamp_))*1.e-4;
298 std::vector<std::vector<Real> > pts;
299 std::vector<Real> pt(this->
data_.size(),0.0);
300 for (
int i = 0; i < SampleGenerator<Real>::numMySamples(); i++ ) {
305 pts.insert(pts.end(),pts_new.begin(),pts_new.end());
307 std::vector<Real> wts(pts.size(),1.0/((Real)this->
nSamp_));
virtual void update(const Vector< Real > &x)
virtual std::vector< Real > getMyPoint(const int i) const
Real computeError(std::vector< Teuchos::RCP< Vector< Real > > > &vals, const Vector< Real > &x)
Defines the linear algebra or vector space interface.
void sumAll(Real *input, Real *output, int dim) const
Real computeError(std::vector< Real > &vals)
std::vector< std::vector< Real > > sample(int nSamp, bool store=true)
virtual void refine(void)
MonteCarloGenerator(int nSamp, std::vector< std::vector< Real > > &bounds, Teuchos::RCP< BatchManager< Real > > &bman, bool use_SA=false, bool adaptive=false, int numNewSamps=0)
std::vector< Teuchos::RCP< ROL::Distribution< Real > > > dist_
MonteCarloGenerator(int nSamp, std::vector< Teuchos::RCP< Distribution< Real > > > &dist, Teuchos::RCP< BatchManager< Real > > &bman, bool use_SA=false, bool adaptive=false, int numNewSamps=0)
int numBatches(void) const
MonteCarloGenerator(int nSamp, std::vector< Real > mean, std::vector< Real > std, Teuchos::RCP< BatchManager< Real > > &bman, bool use_SA=false, bool adaptive=false, int numNewSamps=0)
void setPoints(std::vector< std::vector< Real > > &p)
static const double ROL_OVERFLOW
Platform-dependent maximum double.
void update(const Vector< Real > &x)
void setWeights(std::vector< Real > &w)
std::vector< std::vector< Real > > data_