This example shows how to estimate the quantiles of the distribution of a figure of merit for digital nets.
#include "netbuilder/Task/MinimumObserver.h"
#include "netbuilder/Task/RandomSearch.h"
#include "netbuilder/FigureOfMerit/CoordUniformFigureOfMerit.h"
#include "latbuilder/Kernel/PAlphaPLR.h"
#include "latticetester/ProductWeights.h"
#include "latbuilder/TextStream.h"
using LatBuilder::TextStream::operator<<;
#include <boost/ref.hpp>
#include <boost/accumulators/accumulators.hpp>
#include <boost/accumulators/statistics/count.hpp>
#include <boost/accumulators/statistics/min.hpp>
#include <boost/accumulators/statistics/max.hpp>
#include <boost/accumulators/statistics/mean.hpp>
#include <boost/accumulators/statistics/tail_quantile.hpp>
template <NetConstruction NC>
{
public:
typedef accumulator_set<Real, features<tag::count, tag::min, tag::max, tag::mean, tag::tail_quantile<boost::accumulators::left>>> QuantilesAccumulator;
m_numSamples(0),
m_acc(tag::tail<boost::accumulators::left>::cache_size = m_numSamples)
{};
virtual void reset(bool hard = true) override
{
if (hard)
m_acc = QuantilesAccumulator(tag::tail<boost::accumulators::left>::cache_size = 0);
}
void setNumSamples(size_t numSamples)
{
m_numSamples = numSamples;
m_acc = QuantilesAccumulator(tag::tail<boost::accumulators::left>::cache_size = m_numSamples);
}
{
m_acc(merit);
}
const QuantilesAccumulator& accumulator()
{
return m_acc;
}
private:
size_t m_numSamples;
QuantilesAccumulator m_acc;
};
template <typename T1, typename T2>
void printTableRow(const T1& x1, const T2& x2)
{
cout << fixed << setprecision(3) << x1 << '\t'
<< scientific << setprecision(8) << x2 << std::endl;
}
int main(int argc, const char *argv[])
{
size_t numSamples = 1000;
unsigned int alpha = 2;
auto weights = std::make_unique<LatticeTester::ProductWeights>(.7);
auto figure = std::make_unique<FigureOfMerit::CoordUniformFigureOfMerit<LatBuilder::Kernel::PAlphaPLR, EmbeddingType::UNILEVEL>>(std::move(weights), kernel);
std::cout << figure->format() << std::endl;
task.observer().setNumSamples(numSamples);
task.execute();
const auto& acc = task.observer().accumulator();
unsigned int numBins = 20;
printTableRow("# mean:", mean(acc));
printTableRow("prob", "quantile");
printTableRow(0.0, boost::accumulators::min(acc));
for (unsigned int i = 1; i < numBins; i++) {
double p = double(i) / numBins;
Real q = quantile(acc, quantile_probability = p);
printTableRow(p, q);
}
printTableRow(1.0, boost::accumulators::max(acc));
return 0;
}