Compare commits

...

3 Commits

Author SHA1 Message Date
1e061095d9 remake 2024-01-31 15:27:36 +01:00
e971d6e1e2 fix: x[i] -> xs[i] bug 2024-01-31 15:27:03 +01:00
3e2eb69e3a display # of values above and below 90% confidence interval 2024-01-31 15:26:20 +01:00
16 changed files with 14 additions and 7 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -334,8 +334,13 @@ void array_print_90_ci_histogram(double* xs, int n_samples, int n_bins){
double bin_width = range / n_bins; double bin_width = range / n_bins;
// Fill the bins with sample counts // Fill the bins with sample counts
int below_min = 0, above_max = 0;
for (int i = 0; i < n_samples; i++) { for (int i = 0; i < n_samples; i++) {
if((x[i] > min_value) && (x[i] < max_value)){ if(xs[i] < min_value){
below_min++;
}else if (xs[i] > max_value){
above_max++;
}else{
int bin_index = (int)((xs[i] - min_value) / bin_width); int bin_index = (int)((xs[i] - min_value) / bin_width);
if (bin_index == n_bins) { if (bin_index == n_bins) {
bin_index--; // Last bin includes max_value bin_index--; // Last bin includes max_value
@ -355,16 +360,17 @@ void array_print_90_ci_histogram(double* xs, int n_samples, int n_bins){
double scale = max_bin_count > MAX_WIDTH ? (double)MAX_WIDTH / max_bin_count : 1.0; double scale = max_bin_count > MAX_WIDTH ? (double)MAX_WIDTH / max_bin_count : 1.0;
// Print the histogram // Print the histogram
for (int i = 0; i < n_bins; i++) {
double bin_start = min_value + i * bin_width;
double bin_end = bin_start + bin_width;
int decimalPlaces = 1; int decimalPlaces = 1;
if((0 < bin_width) && (bin_width < 1)){ if((0 < bin_width) && (bin_width < 1)){
int magnitude = (int) floor(log10(bin_width)); int magnitude = (int) floor(log10(bin_width));
decimalPlaces = -magnitude; decimalPlaces = -magnitude;
decimalPlaces = decimalPlaces > 10 ? 10 : decimalPlaces; decimalPlaces = decimalPlaces > 10 ? 10 : decimalPlaces;
} }
printf( " (-∞, %*.*f): %d\n", 4+decimalPlaces, decimalPlaces, min_value, below_min);
for (int i = 0; i < n_bins; i++) {
double bin_start = min_value + i * bin_width;
double bin_end = bin_start + bin_width;
printf(" [%*.*f, %*.*f", 4+decimalPlaces, decimalPlaces, bin_start, 4+decimalPlaces, decimalPlaces, bin_end); printf(" [%*.*f, %*.*f", 4+decimalPlaces, decimalPlaces, bin_start, 4+decimalPlaces, decimalPlaces, bin_end);
char interval_delimiter = ')'; char interval_delimiter = ')';
if(i == (n_bins-1)){ if(i == (n_bins-1)){
@ -378,6 +384,7 @@ void array_print_90_ci_histogram(double* xs, int n_samples, int n_bins){
} }
printf(" %d\n", bins[i]); printf(" %d\n", bins[i]);
} }
printf( " (%*.*f, +∞): %d\n", 4+decimalPlaces, decimalPlaces, max_value, above_max);
// Free the allocated memory for bins // Free the allocated memory for bins
free(bins); free(bins);