diff --git a/examples/more/03_ci_beta/example b/examples/more/03_ci_beta/example
index 42c5ef3..655d461 100755
Binary files a/examples/more/03_ci_beta/example and b/examples/more/03_ci_beta/example differ
diff --git a/examples/more/03_ci_beta/example.c b/examples/more/03_ci_beta/example.c
index 6bb75ef..78019f2 100644
--- a/examples/more/03_ci_beta/example.c
+++ b/examples/more/03_ci_beta/example.c
@@ -17,6 +17,7 @@ int main()
ci beta_1_2_ci_90 = sampler_get_90_ci(beta_1_2_sampler, 1000000, seed);
printf("90%% confidence interval of beta(1,2) is [%f, %f]\n", beta_1_2_ci_90.low, beta_1_2_ci_90.high);
+ printf("You can check this in \n");
free(seed);
}
diff --git a/examples/more/04_nuclear_war/example b/examples/more/04_nuclear_war/example
index 6e51fd6..96f98a7 100755
Binary files a/examples/more/04_nuclear_war/example and b/examples/more/04_nuclear_war/example differ
diff --git a/examples/more/05_burn_10kg_fat/example b/examples/more/05_burn_10kg_fat/example
index 40efb9a..cd93c3f 100755
Binary files a/examples/more/05_burn_10kg_fat/example and b/examples/more/05_burn_10kg_fat/example differ
diff --git a/examples/more/06_nuclear_recovery/example b/examples/more/06_nuclear_recovery/example
index 3cef207..1449164 100755
Binary files a/examples/more/06_nuclear_recovery/example and b/examples/more/06_nuclear_recovery/example differ
diff --git a/examples/more/08_algebra_and_conversion/example b/examples/more/08_algebra_and_conversion/example
index e34b096..4fa2fd2 100755
Binary files a/examples/more/08_algebra_and_conversion/example and b/examples/more/08_algebra_and_conversion/example differ
diff --git a/examples/more/09_ergonomic_algebra/example b/examples/more/09_ergonomic_algebra/example
index 33d3889..51a5957 100755
Binary files a/examples/more/09_ergonomic_algebra/example and b/examples/more/09_ergonomic_algebra/example differ
diff --git a/examples/more/11_billion_lognormals_paralell/example b/examples/more/11_billion_lognormals_paralell/example
index adcf8bd..1e4e463 100755
Binary files a/examples/more/11_billion_lognormals_paralell/example and b/examples/more/11_billion_lognormals_paralell/example differ
diff --git a/examples/more/12_time_to_botec_parallel/example b/examples/more/12_time_to_botec_parallel/example
index b61f3d2..636baa5 100755
Binary files a/examples/more/12_time_to_botec_parallel/example and b/examples/more/12_time_to_botec_parallel/example differ
diff --git a/examples/more/13_parallelize_min/example b/examples/more/13_parallelize_min/example
index 37cd51e..0a0e95e 100755
Binary files a/examples/more/13_parallelize_min/example and b/examples/more/13_parallelize_min/example differ
diff --git a/examples/more/13_parallelize_min/example.c b/examples/more/13_parallelize_min/example.c
index 13adc11..00f28e1 100644
--- a/examples/more/13_parallelize_min/example.c
+++ b/examples/more/13_parallelize_min/example.c
@@ -29,7 +29,7 @@ int main()
int n_samples = 1000000, n_threads = 16;
double* results = malloc(n_samples * sizeof(double));
- sampler_parallel(sampler_result, results, n_threads, n_samples);
+ sampler_parallel(sample_min_of_1000, results, n_threads, n_samples);
printf("Mean of the distribution of (taking the min of 1000 samples of a normal(5,2)): %f\n", array_mean(results, n_samples));
free(results);
@@ -57,7 +57,7 @@ int main()
}
}
if(min > result_remainder){
- min = results_remainder;
+ min = result_remainder;
}
free(results_quotient);
return min;
diff --git a/examples/more/14_check_confidence_interval/example b/examples/more/14_check_confidence_interval/example
new file mode 100755
index 0000000..edd76c3
Binary files /dev/null and b/examples/more/14_check_confidence_interval/example differ
diff --git a/examples/more/14_check_confidence_interval/example.c b/examples/more/14_check_confidence_interval/example.c
new file mode 100644
index 0000000..317985f
--- /dev/null
+++ b/examples/more/14_check_confidence_interval/example.c
@@ -0,0 +1,21 @@
+#include "../../../squiggle.h"
+#include "../../../squiggle_more.h"
+#include
+#include
+
+int main()
+{
+ // set randomness seed
+ uint64_t* seed = malloc(sizeof(uint64_t));
+ *seed = 1000; // xorshift can't start with a seed of 0
+
+ int n = 1000000;
+ double* xs = malloc(sizeof(double) * n);
+ for (int i = 0; i < n; i++) {
+ xs[i] = sample_to(10, 100, seed);
+ }
+ ci ci_90 = array_get_90_ci(xs, n);
+ printf("Recovering confidence interval of sample_to(10, 100):\n low: %f, high: %f\n", ci_90.low, ci_90.high);
+
+ free(seed);
+}
diff --git a/examples/more/makefile b/examples/more/makefile
index c03f24e..0ad04a8 100644
--- a/examples/more/makefile
+++ b/examples/more/makefile
@@ -48,6 +48,8 @@ all:
$(CC) $(OPTIMIZED) $(DEBUG) 10_twitter_thread_example/$(SRC) $(DEPS) -o 10_twitter_thread_example/$(OUTPUT)
$(CC) $(OPTIMIZED) $(DEBUG) 11_billion_lognormals_paralell/$(SRC) $(DEPS) -o 11_billion_lognormals_paralell/$(OUTPUT)
$(CC) $(OPTIMIZED) $(DEBUG) 12_time_to_botec_parallel/$(SRC) $(DEPS) -o 12_time_to_botec_parallel/$(OUTPUT)
+ $(CC) $(OPTIMIZED) $(DEBUG) 13_parallelize_min/$(SRC) $(DEPS) -o 13_parallelize_min/$(OUTPUT)
+ $(CC) $(OPTIMIZED) $(DEBUG) 14_check_confidence_interval/$(SRC) $(DEPS) -o 14_check_confidence_interval/$(OUTPUT)
format-all:
$(FORMATTER) 00_example_template/$(SRC)
@@ -63,6 +65,8 @@ format-all:
$(FORMATTER) 10_twitter_thread_example/$(SRC)
$(FORMATTER) 11_billion_lognormals_paralell/$(SRC)
$(FORMATTER) 12_time_to_botec_parallel/$(SRC)
+ $(FORMATTER) 13_parallelize_min/$(SRC)
+ $(FORMATTER) 14_check_confidence_interval/$(SRC)
run-all:
00_example_template/$(OUTPUT)
@@ -78,6 +82,8 @@ run-all:
10_twitter_thread_example/$(OUTPUT)
11_billion_lognormals_paralell/$(OUTPUT)
12_time_to_botec_parallel/$(OUTPUT)
+ 13_parallelize_min/$(OUTPUT)
+ 14_check_confidence_interval/$(OUTPUT)
## make one DIR=06_nuclear_recovery
one: $(DIR)/$(SRC)
diff --git a/scratchpad/makefile b/scratchpad/makefile
index a2aed9e..d515383 100644
--- a/scratchpad/makefile
+++ b/scratchpad/makefile
@@ -9,7 +9,7 @@ CC=gcc
# CC=tcc # <= faster compilation
# Main file
-SRC=scratchpad.c ../squiggle.c
+SRC=scratchpad.c ../squiggle.c ../squiggle_more.c
OUTPUT=scratchpad
## Dependencies
diff --git a/scratchpad/scratchpad b/scratchpad/scratchpad
index 84baeca..e64435f 100755
Binary files a/scratchpad/scratchpad and b/scratchpad/scratchpad differ
diff --git a/scratchpad/scratchpad.c b/scratchpad/scratchpad.c
index 055657d..b2f057a 100644
--- a/scratchpad/scratchpad.c
+++ b/scratchpad/scratchpad.c
@@ -1,4 +1,5 @@
#include "../squiggle.h"
+#include "../squiggle_more.h"
#include
#include
#include
@@ -9,14 +10,14 @@ int main()
// set randomness seed
uint64_t* seed = malloc(sizeof(uint64_t));
*seed = 1000; // xorshift can't start with a seed of 0
- /*
- for (int i = 0; i < 100; i++) {
- double draw = sample_unit_uniform(seed);
- printf("%f\n", draw);
-
- }*/
- // Test division
- printf("\n%d\n", 10 % 3);
+
+ int n = 1000000;
+ double* xs = malloc(sizeof(double) * n);
+ for (int i = 0; i < n; i++) {
+ xs[i] = sample_to(10, 100, seed);
+ }
+ ci ci_90 = array_get_90_ci(xs, n);
+ printf("Recovering confidence interval of sample_to(10, 100):\n low: %f, high: %f\n", ci_90.low, ci_90.high);
free(seed);
}
diff --git a/squiggle_more.h b/squiggle_more.h
index 35670f3..06747c1 100644
--- a/squiggle_more.h
+++ b/squiggle_more.h
@@ -6,9 +6,12 @@ void sampler_parallel(double (*sampler)(uint64_t* seed), double* results, int n_
/* Get 90% confidence interval */
typedef struct ci_t {
- float low;
- float high;
+ double low;
+ double high;
} ci;
+ci array_get_ci(ci interval, double* xs, int n);
+ci array_get_90_ci(double xs[], int n);
+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);
/* Algebra manipulations */