squiggle.c

Self-contained Monte Carlo estimation in C99
Log | Files | Refs | README

commit 99179410481f20df2e5ba31fd51cbbe343ea7426
parent d2db239a1d2cb812a85ad06449ab94a48ea6ac66
Author: NunoSempere <nuno.sempere@protonmail.com>
Date:   Tue,  6 Feb 2024 13:28:28 +0100

tweak 90% histogram display

- also show bar
- fix padding

Diffstat:
Mexamples/more/00_example_template/example | 0
Mexamples/more/02_ci_beta/example | 0
Mexamples/more/03_ci_beta_parallel/example | 0
Mexamples/more/04_nuclear_war/example | 0
Mexamples/more/05_burn_10kg_fat/example | 0
Mexamples/more/06_nuclear_recovery/example | 0
Mexamples/more/07_algebra/example | 0
Mexamples/more/08_algebra_and_conversion/example | 0
Mexamples/more/09_ergonomic_algebra/example | 0
Mexamples/more/10_twitter_thread_example/example | 0
Mexamples/more/11_billion_lognormals_paralell/example | 0
Mexamples/more/12_time_to_botec_parallel/example | 0
Mexamples/more/13_parallelize_min/example | 0
Mexamples/more/14_check_confidence_interval/example | 0
Msquiggle_more.c | 16+++++++++++++---
15 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/examples/more/00_example_template/example b/examples/more/00_example_template/example Binary files differ. diff --git a/examples/more/02_ci_beta/example b/examples/more/02_ci_beta/example Binary files differ. diff --git a/examples/more/03_ci_beta_parallel/example b/examples/more/03_ci_beta_parallel/example Binary files differ. diff --git a/examples/more/04_nuclear_war/example b/examples/more/04_nuclear_war/example Binary files differ. diff --git a/examples/more/05_burn_10kg_fat/example b/examples/more/05_burn_10kg_fat/example Binary files differ. diff --git a/examples/more/06_nuclear_recovery/example b/examples/more/06_nuclear_recovery/example Binary files differ. diff --git a/examples/more/07_algebra/example b/examples/more/07_algebra/example Binary files differ. diff --git a/examples/more/08_algebra_and_conversion/example b/examples/more/08_algebra_and_conversion/example Binary files differ. diff --git a/examples/more/09_ergonomic_algebra/example b/examples/more/09_ergonomic_algebra/example Binary files differ. diff --git a/examples/more/10_twitter_thread_example/example b/examples/more/10_twitter_thread_example/example Binary files differ. diff --git a/examples/more/11_billion_lognormals_paralell/example b/examples/more/11_billion_lognormals_paralell/example Binary files differ. diff --git a/examples/more/12_time_to_botec_parallel/example b/examples/more/12_time_to_botec_parallel/example Binary files differ. diff --git a/examples/more/13_parallelize_min/example b/examples/more/13_parallelize_min/example Binary files differ. diff --git a/examples/more/14_check_confidence_interval/example b/examples/more/14_check_confidence_interval/example Binary files differ. diff --git a/squiggle_more.c b/squiggle_more.c @@ -364,7 +364,7 @@ void array_print_90_ci_histogram(double* xs, int n_samples, int n_bins) max_bin_count = bins[i]; } } - const int MAX_WIDTH = 50; // Adjust this to your terminal width + const int MAX_WIDTH = 40; // Adjust this to your terminal width double scale = max_bin_count > MAX_WIDTH ? (double)MAX_WIDTH / max_bin_count : 1.0; // Print the histogram @@ -374,7 +374,12 @@ void array_print_90_ci_histogram(double* xs, int n_samples, int n_bins) decimalPlaces = -magnitude; decimalPlaces = decimalPlaces > 10 ? 10 : decimalPlaces; } - printf("(-∞, %*.*f): %d\n", 4 + decimalPlaces, decimalPlaces, min_value, below_min); + printf("(%*s, %*.*f): ", 6 + decimalPlaces, "-∞", 4 + decimalPlaces, decimalPlaces, min_value); + int marks_below_min = (int)(below_min * scale); + for (int j = 0; j < marks_below_min; j++) { + printf("█"); + } + printf(" %d\n", 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; @@ -392,7 +397,12 @@ void array_print_90_ci_histogram(double* xs, int n_samples, int n_bins) } printf(" %d\n", bins[i]); } - printf("(%*.*f, +∞): %d\n", 4 + decimalPlaces, decimalPlaces, max_value, above_max); + printf("(%*.*f, %*s): ", 4 + decimalPlaces, decimalPlaces, min_value, 6 + decimalPlaces, "+∞"); + int marks_above_max = (int)(above_max * scale); + for (int j = 0; j < marks_above_max; j++) { + printf("█"); + } + printf(" %d\n", above_max); // Free the allocated memory for bins free(bins);