Commit a436328f authored by lu43jih's avatar lu43jih
Browse files

Merge branch 'development' of https://gitlab.lrz.de/dcdb/dcdb into development

parents 758b1b89 06c86146
......@@ -94,5 +94,35 @@ void computeQuantiles(const std::vector<reading_t> &data, std::vector<reading_t>
}
void computeQuantiles(const std::vector<reading_t> &data, std::vector<reading_t> &quantiles, unsigned int NUMBER_QUANTILES) {
std::vector<reading_t> cdf; //!< cumulative distribution function (cfd)
cdf.assign(data.begin(), data.end()); // we copy the vector to avoid changing the order to the original
std::sort(cdf.begin(), cdf.end(), [ ](const reading_t& lhs, const reading_t& rhs) { return lhs.value < rhs.value; });
if (cdf.empty()) {
return;
}
int elementNumber = cdf.size();
quantiles.resize(NUMBER_QUANTILES + 1); //+min
float factor = elementNumber/static_cast<float>(NUMBER_QUANTILES);
quantiles[0].value = cdf[0].value;
quantiles[NUMBER_QUANTILES].value = cdf[cdf.size() - 1].value;
for (unsigned int i = 1; i < NUMBER_QUANTILES; i++) {
if (elementNumber > 1) {
int idx = static_cast<int>(std::floor(i * factor));
float rest = (i * factor) - idx;
if(idx == 0){
quantiles[i].value = cdf[0].value;
quantiles[i].timestamp = cdf[0].timestamp;
} else {
quantiles[i].value = cdf[idx - 1].value + rest * (cdf[idx].value - cdf[idx - 1].value);
quantiles[i].timestamp = cdf[idx].timestamp;
}
} else { //optimization, we don't need to calculate all the quantiles
quantiles[i].value = cdf[0].value;
quantiles[i].value = cdf[0].timestamp;
}
}
}
#endif /* ANALYTICS_INCLUDES_COMMONSTATISTICS_H_ */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment