#include <iostream>
#include <iterator>
#include <algorithm>
#include <random>
#include <vector>
void printLine() {
std::cout << "----------------------------------------"
"----------------------------------------\n";
}
void randn(DataVector& rvar, std::mt19937& generator) {
std::normal_distribution<double> distribution(0.5, 0.02);
for (
size_t j = 0;
j < rvar.getSize(); ++
j) {
rvar[
j] = distribution(generator);
}
}
void randn(DataMatrix& rvar, std::uint64_t seedValue = std::mt19937_64::default_seed) {
size_t nsamples = rvar.getNrows(), ndim = rvar.getNcols();
std::mt19937 generator(seedValue);
DataVector sample(ndim);
for (
size_t i = 0; i < nsamples; ++
i) {
randn(sample, generator);
rvar.setRow(i, sample);
}
}
int main(
int argc,
const char* argv[]) {
(void)argc;
(void)argv;
std::cout << "sgpp::optimization kde bandwidth optimization.\n\n";
const size_t d = 1;
DataVector bandwidths(d);
randn(samples);
KernelDensityEstimator kdeRot(samples, KernelType::GAUSSIAN,
BandwidthOptimizationType::SILVERMANSRULE);
kdeRot.getBandwidths(bandwidths);
std::cout << "h_rot = " << bandwidths.toString() << " -> " << kdeRot.crossEntropy(samples)
<< std::endl;
KernelDensityEstimator kdeOpt(samples, KernelType::GAUSSIAN,
BandwidthOptimizationType::MAXIMUMLIKELIHOOD);
kdeOpt.getBandwidths(bandwidths);
std::cout << "h_opt = " << bandwidths.toString() << " -> " << kdeOpt.crossEntropy(samples)
<< std::endl;
return 0;
}