formatting pass

This commit is contained in:
NunoSempere 2023-07-24 00:15:05 +02:00
parent ef40ef5ae7
commit 84399e60a2

View File

@ -1,6 +1,6 @@
#include "../../squiggle.h" #include "../../squiggle.h"
#include <stdint.h>
#include <math.h> #include <math.h>
#include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -9,7 +9,7 @@ double probability_of_dying_nuno(uint64_t* seed)
double first_year_russian_nuclear_weapons = 1953; double first_year_russian_nuclear_weapons = 1953;
double current_year = 2022; double current_year = 2022;
double laplace_probability_nuclear_exchange_year = sample_beta(1, current_year - first_year_russian_nuclear_weapons + 1, seed); double laplace_probability_nuclear_exchange_year = sample_beta(1, current_year - first_year_russian_nuclear_weapons + 1, seed);
double laplace_probability_nuclear_exchange_month = 1 - pow(1-laplace_probability_nuclear_exchange_year,(1.0/12.0)) ; double laplace_probability_nuclear_exchange_month = 1 - pow(1 - laplace_probability_nuclear_exchange_year, (1.0 / 12.0));
double london_hit_conditional_on_russia_nuclear_weapon_usage = sample_beta(7.67, 69.65, seed); double london_hit_conditional_on_russia_nuclear_weapon_usage = sample_beta(7.67, 69.65, seed);
// I.e., a beta distribution with a range of 0.05 to 0.16 into: https://nunosempere.com/blog/2023/03/15/fit-beta/ // I.e., a beta distribution with a range of 0.05 to 0.16 into: https://nunosempere.com/blog/2023/03/15/fit-beta/
@ -34,9 +34,10 @@ double probability_of_dying_eli(uint64_t* seed)
return probability_of_dying; return probability_of_dying;
} }
double mixture(uint64_t* seed){ double mixture(uint64_t* seed)
double (*samplers[])(uint64_t*) = {probability_of_dying_nuno, probability_of_dying_eli}; {
double weights[] = {0.5, 0.5}; double (*samplers[])(uint64_t*) = { probability_of_dying_nuno, probability_of_dying_eli };
double weights[] = { 0.5, 0.5 };
return sample_mixture(samplers, weights, 2, seed); return sample_mixture(samplers, weights, 2, seed);
} }
@ -47,23 +48,21 @@ int main()
*seed = 1000; // xorshift can't start with 0 *seed = 1000; // xorshift can't start with 0
int n = 1000 * 1000; int n = 1000 * 1000;
double* mixture_result = malloc(sizeof(double) * n); double* mixture_result = malloc(sizeof(double) * n);
for(int i=0; i<n; i++){ for (int i = 0; i < n; i++) {
mixture_result[i] = mixture(seed); mixture_result[i] = mixture(seed);
} }
printf("mixture_result: [ "); printf("mixture_result: [ ");
for(int i=0; i<9; i++){ for (int i = 0; i < 9; i++) {
printf("%.6f, ", mixture_result[i]); printf("%.6f, ", mixture_result[i]);
} }
printf("... ]\n"); printf("... ]\n");
struct c_i c_i_90 = get_90_confidence_interval(mixture, seed); struct c_i c_i_90 = get_90_confidence_interval(mixture, seed);
printf("mean: %f\n", array_mean(mixture_result, n)); printf("mean: %f\n", array_mean(mixture_result, n));
printf("90%% confidence interval: [%f, %f]\n", c_i_90.low, c_i_90.high); printf("90%% confidence interval: [%f, %f]\n", c_i_90.low, c_i_90.high);
free(seed); free(seed);
} }