Commit 66319fdc authored by Florian Fischer's avatar Florian Fischer
Browse files

calculate lower/upper percentiles and whiskers for future boxplots

parent 5e90091e
Pipeline #66583 failed with stage
in 1 minute and 27 seconds
......@@ -40,6 +40,39 @@ uint64_t calc_var(const uint64_t* data, size_t size, uint64_t mean) {
return sum / size;
}
// Using nearest rank
// https://en.wikipedia.org/wiki/Percentile#The_nearest-rank_method
uint64_t get_percentile(const uint64_t* data, size_t size, float prctl) {
check_saple_size(size);
if (prctl < 0 || prctl > 1) errx(EXIT_FAILURE, "prctl must be in [0,1]");
size_t n = prctl * size;
return data[n];
}
uint64_t get_upper_whisker(const uint64_t* data, size_t size, uintptr_t iqr) {
check_saple_size(size);
const float upper_prctl = 0.75;
size_t n = upper_prctl * size;
const uint64_t threshold = data[n] + (1.5 * iqr);
while (data[n] < threshold && n < size) {
++n;
}
return data[n];
}
uint64_t get_lower_whisker(const uint64_t* data, size_t size, uintptr_t iqr) {
check_saple_size(size);
const float lower_prctl = 0.25;
size_t n = lower_prctl * size;
const uint64_t threshold = data[n] - (1.5 * iqr);
while (data[n] > threshold && n > 0) {
--n;
}
return data[n];
}
static int compare_uint64_t(const void* v1, const void* v2) {
const uint64_t x1 = *(uint64_t*)v1;
const uint64_t x2 = *(uint64_t*)v2;
......@@ -62,6 +95,13 @@ void print_desc_stats(const char* name, const char* indentation, const uint64_t*
const uint64_t var = calc_var(data, size, mean);
const uint64_t std = (uint64_t)sqrt((double)var);
const uint64_t prctl_25 = get_percentile(data, size, 0.25);
const uint64_t prctl_75 = get_percentile(data, size, 0.75);
const uint64_t iqr = prctl_75 - prctl_25;
const uint64_t lower_whisker = get_lower_whisker(data, size, iqr);
const uint64_t upper_whisker = get_upper_whisker(data, size, iqr);
printf("%s%s:\n", indentation, name);
printf("%s%smin: %lu\n", indentation, indentation, min);
printf("%s%smax: %lu\n", indentation, indentation, max);
......@@ -69,4 +109,8 @@ void print_desc_stats(const char* name, const char* indentation, const uint64_t*
printf("%s%smean: %lu\n", indentation, indentation, mean);
printf("%s%svar: %lu\n", indentation, indentation, var);
printf("%s%sstd: %lu\n", indentation, indentation, std);
printf("%s%sprctl_25: %lu\n", indentation, indentation, prctl_25);
printf("%s%sprctl_75: %lu\n", indentation, indentation, prctl_75);
printf("%s%slower_whisker: %lu\n", indentation, indentation, lower_whisker);
printf("%s%supper_whisker: %lu\n", indentation, indentation, upper_whisker);
}
Supports Markdown
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