forked from personal/squiggle.c
more refactors; add another example
This commit is contained in:
parent
fb110a35f3
commit
186b10cddf
Binary file not shown.
|
@ -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 <https://nunosempere.com/blog/2023/03/15/fit-beta/>\n");
|
||||
|
||||
free(seed);
|
||||
}
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -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;
|
||||
|
|
BIN
examples/more/14_check_confidence_interval/example
Executable file
BIN
examples/more/14_check_confidence_interval/example
Executable file
Binary file not shown.
21
examples/more/14_check_confidence_interval/example.c
Normal file
21
examples/more/14_check_confidence_interval/example.c
Normal file
|
@ -0,0 +1,21 @@
|
|||
#include "../../../squiggle.h"
|
||||
#include "../../../squiggle_more.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
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);
|
||||
}
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Binary file not shown.
|
@ -1,4 +1,5 @@
|
|||
#include "../squiggle.h"
|
||||
#include "../squiggle_more.h"
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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 */
|
||||
|
|
Loading…
Reference in New Issue
Block a user