SG++-Doxygen-Documentation
Stochastic Collocation with Combigrids

This simple example shows how to create a Stochastic Collocation surrogate from a regular combigrid.

First we create an analytical model for comparison

and define the corresponding probability density functions.

config.pdfParameters.lowerBound_ = model.bounds[0];
config.pdfParameters.upperBound_ = model.bounds[1];
config.pdfParameters.alpha_ = model.alpha1;
config.pdfParameters.beta_ = model.beta1;
auto pdf1 = std::make_shared<sgpp::combigrid::ProbabilityDensityFunction1D>(config);
config.pdfParameters.lowerBound_ = model.bounds[0];
config.pdfParameters.upperBound_ = model.bounds[1];
config.pdfParameters.alpha_ = model.alpha2;
config.pdfParameters.beta_ = model.beta2;
auto pdf2 = std::make_shared<sgpp::combigrid::ProbabilityDensityFunction1D>(config);
weightFunctions.push_back(pdf1->getWeightFunction());
weightFunctions.push_back(pdf2->getWeightFunction());

Then we create a combigrid for our model

std::shared_ptr<sgpp::combigrid::LevelManager> levelManager =
std::make_shared<sgpp::combigrid::AveragingLevelManager>();
auto op = std::make_shared<sgpp::combigrid::CombigridOperation>(grids, evaluators, levelManager,
func, false);
auto op_levelManager = op->getLevelManager();

and from that initialize a Stochastic Collocation surrogate.

// initialize the surrogate model
std::vector<double> bounds{pdf1->lowerBound(), pdf1->upperBound(), pdf2->lowerBound(),
pdf2->upperBound()};
sc_config.weightFunctions = weightFunctions;
sc_config.bounds = sgpp::base::DataVector(bounds);
// config used for updating surrogate in loop

Finally levels are added to the combigrid and subsequently the collocation surrogate is updated and the model's mean and variance error is printed.

for (size_t q = 0; q < 8; ++q) {
// add levels to combigrid
op_levelManager->addRegularLevels(q);
std::cout << "---------------------------------------------------------" << std::endl;
std::cout << "compute mean and variance of stochastic collocation" << std::endl;
std::cout << "#gp = " << op_levelManager->numGridPoints() << std::endl;
stopwatch.start();
// update surrogate
update_config.levelStructure = op_levelManager->getLevelStructure();
sc->updateConfig(update_config);
// compute mean and variance
double mean = sc->mean();
double variance = sc->variance();
stopwatch.log();
std::cout << "|mu - E(u)| = " << std::abs(model.mean - mean) << std::endl;
std::cout << "|sigma^2 - Var(u)| = " << std::abs(model.variance - variance) << std::endl;
}
}