简体   繁体   English

Boost ::累加器的百分位数给出错误的值

[英]Boost::accumulator's percentile giving wrong values

I am using boost::accumulators::tag::extended_p_square_quantile for calculating percentile. 我正在使用boost::accumulators::tag::extended_p_square_quantile计算百分位数。 In this, I also need to feed probabilities to the accumulator so I did this m_acc = AccumulatorType(boost::accumulators::extended_p_square_probabilities = probs); 在这种情况下,我还需要将概率提供给累加器,所以我这样做了m_acc = AccumulatorType(boost::accumulators::extended_p_square_probabilities = probs); where probs is a vector containing the probabilities. 其中,概率是包含概率的向量。

Values in the prob vector are {0.5,0.3,0.9,0.7} 概率向量中的{0.5,0.3,0.9,0.7}

I provided some sample values to accumulator. 我向累加器提供了一些样本值。

But when I try to get the percentile using boost::accumulators::quantile(m_acc, boost::accumulators::quantile_probability = probs[0]); 但是当我尝试使用boost::accumulators::quantile(m_acc, boost::accumulators::quantile_probability = probs[0]);来获取百分boost::accumulators::quantile(m_acc, boost::accumulators::quantile_probability = probs[0]); it returns incorrect values and even nan sometimes. 它返回错误的值,有时甚至返回nan。

What is wrong here? 怎么了

I ran into this problem and wasted lot of time to figured out the problem and therefore want to answer this. 我遇到了这个问题,浪费了很多时间找出问题,因此想回答这个问题。

Problem is with the vector. 问题出在向量上。 Vector should be shorted in increasing order of its values. 向量应按其值的升序排列。

Change the vector values to this {0.3,0.5,0.7,0.9} and it will work as expected. 将向量值更改为此{0.3,0.5,0.7,0.9} ,它将按预期工作。

So if someone is using tag::extended_p_square_quantile for percentile(which supports multiple probabilities) then (s)he needs to give probabilities(vector/array/list) in sorted order. 因此,如果有人使用tag::extended_p_square_quantile作为百分位数(支持多个概率),则他需要按排序顺序给出概率(向量/数组/列表)。

This isn't the case with tag::p_square_quantile because we can give only one value(probability) in it. tag::p_square_quantile不是这种情况,因为我们只能在其中给出一个值(概率)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM