Skip to content

Commit

Permalink
fixup! refactor: simplify MovingInterquartileMean
Browse files Browse the repository at this point in the history
  • Loading branch information
Swiftb0y committed Oct 8, 2024
1 parent c35a86c commit 1bc2bb1
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/util/movinginterquartilemean.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <qlogging.h>

#include <algorithm>
#include <cstddef>
#include <iterator>
#include <numeric>

Expand Down Expand Up @@ -59,21 +60,21 @@ double MovingInterquartileMean::mean() {
if (listSize <= 4) {
m_dMean = simpleMean(m_list.cbegin(), m_list.cend());
} else if (listSize % 4 == 0) {
int quartileSize = listSize / 4;
std::size_t quartileSize = listSize / 4;
auto start = m_list.cbegin() + quartileSize;
auto end = m_list.cend() - quartileSize;
m_dMean = simpleMean(start, end);
} else {
// http://en.wikipedia.org/wiki/Interquartile_mean#Dataset_not_divisible_by_four
double quartileSize = listSize / 4.0;
double interQuartileRange = 2 * quartileSize;
int nFullValues = listSize - 2 * static_cast<int>(quartileSize) - 2;
std::size_t nFullValues = listSize - 2 * static_cast<std::size_t>(quartileSize) - 2;
double quartileWeight = (interQuartileRange - nFullValues) / 2;
auto it = m_list.begin();
std::advance(it, static_cast<int>(quartileSize));
std::advance(it, static_cast<std::size_t>(quartileSize));
double d_sum = *it * quartileWeight;
++it;
for (int k = 0; k < nFullValues; ++k, ++it) {
for (std::size_t k = 0; k < nFullValues; ++k, ++it) {
d_sum += *it;
}
d_sum += *it * quartileWeight;
Expand Down

0 comments on commit 1bc2bb1

Please sign in to comment.