B-Spline Combigrids
In this example the mean and variance of an objective function are calculated with B-Spline Stochastic Collocation. The objective function is \( f(x) = x \) on \([a,b] = [-1,3] \) to the unit cube via \(\tilde{f}(x) = a + (b-a) x = 4x-1\). The moments are calculated assuming a normal probability density function is used as a weight function \( w(x)\) in the integration. This means
\(E(f) = \int f(x) w(x) dx \\ V(f) = E(f^2) - E(f)^2 \)
size_t numDimensions = 1;
size_t degree = 5;
intialize the probability density functions for our input.
auto probabilityDensityFunction =
std::make_shared<sgpp::combigrid::ProbabilityDensityFunction1D>(pdf_config);
probabilityDensityFunction->getWeightFunction();
for (size_t d = 0; d < numDimensions; d++) {
weightFunctionsCollection.
push_back(oneDimensionsalWeightFunction);
}
After that we create a B-Spline stochastic collocation surrogate. We initialize an empty storage that will later contain the coefficients of the B spline interpolation
std::shared_ptr<sgpp::combigrid::AbstractCombigridStorage> storage;
set up the configuration for the B spline Stochastic Collocation
config.
levelManager = std::make_shared<sgpp::combigrid::RegularLevelManager>();
create a B spline interpolation operation with a regular level manager to create the level structure and calculate the interpolation coefficients
std::shared_ptr<sgpp::combigrid::LevelManager> regularLevelManager(
bool exploitNesting = false;
auto Operation = std::make_shared<sgpp::combigrid::CombigridMultiOperation>(
pointHierarchies, Evaluators, regularLevelManager, gf, exploitNesting,
auxiliarySummationStrategyType);
Now we can add some levels to the combigrid,
Operation->getLevelManager()->addRegularLevels(1);
update the surrogate accordingly
config.
levelStructure = Operation->getLevelManager()->getLevelStructure();
bsc.updateConfig(config);
and calculate mean and variance of the objective function.
double variance = bsc.variance();
double mean = bsc.mean();
std::cout << "# grid points: " << Operation->getLevelManager()->numGridPoints() << std::endl;
std::cout << "mean: " << mean << " variance: " << variance << std::endl;
return 0;
}