SG++
iCholConvergence.cpp

This example can be found under datadriven/examples/iCholConvergence.cpp.

/*
* iCholConvergece.cpp
*
* Created on: Apr 25, 2017
* Author: milettri
*/
// Copyright (C) 2008-today The SG++ project
// This file is part of the SG++ project. For conditions of distribution and
// use, please see the copyright notice provided with SG++ or at
// sgpp.sparsegrids.org
#ifdef USE_GSL
#include <omp.h>
#include <chrono>
#include <string>
#endif /* USE_GSL */
int main() {
#ifdef USE_GSL
// ###################################################################################
gridConfig.dim_ = 4;
gridConfig.level_ = 5;
regularizationConfig.lambda_ = 10e-4;
sgpp::datadriven::DBMatOfflineChol fullOffline(gridConfig, adaptConfig,
regularizationConfig, fullDensityEstimationConfig);
fullOffline.buildMatrix();
fullOffline.decomposeMatrix();
auto& fullMat = fullOffline.getDecomposedMatrix();
for (auto i = 0u; i < fullMat.getNrows(); i++) {
for (auto j = i + 1; j < fullMat.getNcols(); j++) {
fullMat.set(i, j, 0.0);
}
}
// ###################################################################################
sgpp::datadriven::DensityEstimationConfiguration exactIConfig = fullDensityEstimationConfig;
fullDensityEstimationConfig.decomposition_ =
exactIConfig.iCholSweepsDecompose_ = 1;
sgpp::datadriven::DBMatOfflineDenseIChol exactIOffline(gridConfig, adaptConfig,
regularizationConfig, exactIConfig);
exactIOffline.buildMatrix();
auto numThreads = 0;
#pragma omp parallel
{
#pragma omp single
{ numThreads = omp_get_num_threads(); }
}
omp_set_num_threads(1);
exactIOffline.decomposeMatrix();
omp_set_num_threads(numThreads);
auto& exactIMat = exactIOffline.getDecomposedMatrix();
for (auto i = 0u; i < exactIMat.getNrows(); i++) {
for (auto j = i + 1; j < exactIMat.getNcols(); j++) {
exactIMat.set(i, j, 0.0);
}
}
// ###################################################################################
for (auto i = 1u; i < 10; i++) {
sgpp::datadriven::DensityEstimationConfiguration densityEstimationConfig = exactIConfig;
densityEstimationConfig.iCholSweepsDecompose_ = i;
sgpp::datadriven::DBMatOfflineDenseIChol offline(gridConfig, adaptConfig,
regularizationConfig, densityEstimationConfig);
offline.buildMatrix();
offline.decomposeMatrix();
auto& iMat = offline.getDecomposedMatrix();
for (auto i = 0u; i < iMat.getNrows(); i++) {
for (auto j = i + 1; j < iMat.getNcols(); j++) {
iMat.set(i, j, 0.0);
}
}
auto tmpIMat(iMat);
tmpIMat.sub(exactIMat);
tmpIMat.abs();
tmpIMat.sqr();
std::cout << " ||iichol - ichol|| with " << densityEstimationConfig.iCholSweepsDecompose_
<< " sweeps is: " << std::scientific << std::setprecision(10) << sqrt(tmpIMat.sum())
<< "\n";
auto tmpIMat2(iMat);
tmpIMat2.sub(fullMat);
tmpIMat2.abs();
tmpIMat2.sqr();
std::cout << " ||iichol - chol|| with " << densityEstimationConfig.iCholSweepsDecompose_
<< " sweeps is: " << std::scientific << std::setprecision(10) << sqrt(tmpIMat2.sum())
<< "\n";
}
#endif /* USE_GSL */
}