How to set rounding policy to an empirical distribution accumulator in the quantile function?

106 Views Asked by At

I'm trying to change the default rounding parameter value integer_round_outwards to integer_round_inwards for an accumulator which contains an empirical discrete distribution (Discrete Quantile Policies).

I've calculated the quantity from an empirical distribution with the default rounding policy:

#include <boost/math/policies/policy.hpp>
#include <boost/accumulators/accumulators.hpp>
#include <boost/accumulators/statistics.hpp>
#include <boost/accumulators/statistics/stats.hpp>
#include <boost/accumulators/statistics/tail_quantile.hpp>

using namespace boost::accumulators;

typedef accumulator_set< double, stats< tag::tail_quantile<right> > > accumulator_t;

double myQuantile(double level, std::vector<double>& values){

    accumulator_t acc(boost::accumulators::tag::tail<right>::cache_size = values.size());

    for (const auto& sample : values) // Vector 'values' containing empirical measures
        acc(sample);                  // My accumulator 'acc' with the empirical discrete distribution

    double myResult = quantile(acc, quantile_probability = level);

    return myResult;                  // This result is under the integer_round_outwards rounding policy
};

However, I want to try other types of rounding policies. Boost documentation shows the following example for a Negative Binomial distribution:

#include <boost/math/distributions/negative_binomial.hpp>

using boost::math::negative_binomial_distribution;
using namespace boost::math::policies;

typedef negative_binomial_distribution< double, policy<discrete_quantile<integer_round_nearest> > > dist_type;

// Lower quantile rounded (down) to nearest:
double x = quantile(dist_type(20, 0.3), 0.05); // 27

How can I do this for my custom accumulator which contains the empirical discrete distribution?

I'm using Boost 1.63

0

There are 0 best solutions below