Compare commits

..

2 Commits

Author SHA1 Message Date
6010d99cba fix typo and remake 2024-01-30 13:28:17 +01:00
90555bf3b3 add a few stats functions 2024-01-30 13:27:54 +01:00
17 changed files with 32 additions and 1 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -189,6 +189,33 @@ ci array_get_90_ci(double xs[], int n)
return array_get_ci((ci) { .low = 0.05, .high = 0.95 }, xs, n); return array_get_ci((ci) { .low = 0.05, .high = 0.95 }, xs, n);
} }
double array_get_median(double xs[], int n){
int median_k = (int)floor(0.5 * n);
return quickselect(median_k, xs, n);
}
void array_print_stats(double xs[], int n){
ci ci_90 = array_get_ci((ci) { .low = 0.05, .high = 0.95 }, xs, n);
ci ci_80 = array_get_ci((ci) { .low = 0.1, .high = 0.9 }, xs, n);
ci ci_50 = array_get_ci((ci) { .low = 0.25, .high = 0.75 }, xs, n);
double median = array_get_median(xs, n);
double mean = array_mean(xs, n);
double std = array_std(xs, n);
printf("Mean: %lf\n"
" Std: %lf\n"
" 5%%: %lf\n"
" 10%%: %lf\n"
" 25%%: %lf\n"
" 50%%: %lf\n"
" 75%%: %lf\n"
" 90%%: %lf\n"
" 95%%: %lf\n",
mean, std, ci_90.low, ci_80.low, ci_50.low, median, ci_50.high, ci_80.high, ci_90.high);
}
// Replicate some of the above functions over samplers
// However, in the future I'll delete this
// There should be a clear boundary between working with samplers and working with an array of samples
ci sampler_get_ci(ci interval, double (*sampler)(uint64_t*), int n, uint64_t* seed) ci sampler_get_ci(ci interval, double (*sampler)(uint64_t*), int n, uint64_t* seed)
{ {
UNUSED(seed); // don't want to use it right now, but want to preserve ability to do so (e.g., remove parallelism from internals). Also nicer for consistency. UNUSED(seed); // don't want to use it right now, but want to preserve ability to do so (e.g., remove parallelism from internals). Also nicer for consistency.

View File

@ -4,13 +4,17 @@
/* Parallel sampling */ /* Parallel sampling */
void sampler_parallel(double (*sampler)(uint64_t* seed), double* results, int n_threads, int n_samples); void sampler_parallel(double (*sampler)(uint64_t* seed), double* results, int n_threads, int n_samples);
/* Get 90% confidence interval */ /* Get median and confidence intervals */
double array_get_median(double xs[], int n);
typedef struct ci_t { typedef struct ci_t {
double low; double low;
double high; double high;
} ci; } ci;
ci array_get_ci(ci interval, double* xs, int n); ci array_get_ci(ci interval, double* xs, int n);
ci array_get_90_ci(double xs[], int n); ci array_get_90_ci(double xs[], int n);
void array_print_stats(double xs[], int n);
// Deprecated: get confidence intervals directly from samplers
ci sampler_get_ci(ci interval, double (*sampler)(uint64_t*), int n, uint64_t* seed); ci sampler_get_ci(ci interval, double (*sampler)(uint64_t*), int n, uint64_t* seed);
ci sampler_get_90_ci(double (*sampler)(uint64_t*), int n, uint64_t* seed); ci sampler_get_90_ci(double (*sampler)(uint64_t*), int n, uint64_t* seed);