1

我正在尝试将默认舍入参数值integer_round_outwards更改integer_round_inwards为包含经验离散分布(离散分位数策略)的累加器。

我已经使用默认舍入策略从经验分布中计算了数量:

#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
};

但是,我想尝试其他类型的舍入策略。Boost 文档显示了负二项分布的以下示例:

#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

如何为包含经验离散分布的自定义累加器执行此操作?

我正在使用 Boost 1.63

4

0 回答 0