forked from personal/squiggle.c
look through histogram function to convince myself of correctness
This commit is contained in:
parent
ab97e6ce3e
commit
19367b04cd
|
@ -242,9 +242,8 @@ void array_print_histogram(double* xs, int n_samples, int n_bins) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
double min_value = xs[0], max_value = xs[0];
|
|
||||||
|
|
||||||
// Find the minimum and maximum values from the samples
|
// Find the minimum and maximum values from the samples
|
||||||
|
double min_value = xs[0], max_value = xs[0];
|
||||||
for (int i = 0; i < n_samples; i++) {
|
for (int i = 0; i < n_samples; i++) {
|
||||||
if (xs[i] < min_value) {
|
if (xs[i] < min_value) {
|
||||||
min_value = xs[i];
|
min_value = xs[i];
|
||||||
|
@ -260,8 +259,7 @@ void array_print_histogram(double* xs, int n_samples, int n_bins) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate bin width
|
// Calculate bin width
|
||||||
double range = max_value - min_value;
|
double bin_width = (max_value - min_value) / n_bins;
|
||||||
double bin_width = range / n_bins;
|
|
||||||
|
|
||||||
// Fill the bins with sample counts
|
// Fill the bins with sample counts
|
||||||
for (int i = 0; i < n_samples; i++) {
|
for (int i = 0; i < n_samples; i++) {
|
||||||
|
@ -339,10 +337,7 @@ void array_print_90_ci_histogram(double* xs, int n_samples, int n_bins){
|
||||||
if (min_value == max_value) {
|
if (min_value == max_value) {
|
||||||
max_value++;
|
max_value++;
|
||||||
}
|
}
|
||||||
|
double bin_width = (max_value - min_value) / n_bins;
|
||||||
// Calculate bin width
|
|
||||||
double range = max_value - min_value;
|
|
||||||
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;
|
int below_min = 0, above_max = 0;
|
||||||
|
@ -399,7 +394,6 @@ void array_print_90_ci_histogram(double* xs, int n_samples, int n_bins){
|
||||||
|
|
||||||
// Free the allocated memory for bins
|
// Free the allocated memory for bins
|
||||||
free(bins);
|
free(bins);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Algebra manipulations */
|
/* Algebra manipulations */
|
||||||
|
|
Loading…
Reference in New Issue
Block a user