Commit c338b12f authored by Alessio Netti's avatar Alessio Netti
Browse files

Analytics: minor fix to percentile computation

parent 7f514bfb
......@@ -97,8 +97,8 @@ void computePercentiles(std::vector<reading_t> &data, const std::vector<size_t>
// Sorting the sensor reading buffer to extract quantiles
std::sort(data.begin(), data.end(), [ ](const reading_t& lhs, const reading_t& rhs) { return lhs.value < rhs.value; });
for(const auto& q : percentilePositions) {
idx = (data.size() * q) / 100;
mod = (data.size() * q) % 100;
idx = ((data.size()-1) * q) / 100;
mod = ((data.size()-1) * q) % 100;
percentiles.push_back((mod==0 || idx==data.size()-1) ? data[idx].value : (data[idx].value + data[idx+1].value)/2);
}
}
......
......@@ -233,15 +233,13 @@ bool RegressorOperator::computeFeatureVector(U_Ptr unit) {
std::sort(_buffer.begin(), _buffer.end(),
[](const reading_t &lhs, const reading_t &rhs) { return lhs.value < rhs.value; });
// Computing 25th PERCENTILE
qId = (_buffer.size() * 25) / 100;
qMod = (_buffer.size() * 25) % 100;
_qtl25 = (qMod == 0 || qId == _buffer.size() - 1) ? _buffer[qId].value :
(_buffer[qId].value + _buffer[qId + 1].value) / 2;
qId = ((_buffer.size()-1) * 25) / 100;
qMod = ((_buffer.size()-1) * 25) % 100;
_qtl25 = (qMod == 0 || qId == _buffer.size() - 1) ? _buffer[qId].value : (_buffer[qId].value + _buffer[qId + 1].value) / 2;
// Computing 75th PERCENTILE
qId = (_buffer.size() * 75) / 100;
qMod = (_buffer.size() * 75) % 100;
_qtl75 = (qMod == 0 || qId == _buffer.size() - 1) ? _buffer[qId].value :
(_buffer[qId].value + _buffer[qId + 1].value) / 2;
qId = ((_buffer.size()-1) * 75) / 100;
qMod = ((_buffer.size()-1) * 75) % 100;
_qtl75 = (qMod == 0 || qId == _buffer.size() - 1) ? _buffer[qId].value : (_buffer[qId].value + _buffer[qId + 1].value) / 2;
fIdx = idx * REG_NUMFEATURES;
// Casting and storing the statistical features
......
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