squiggle.c/scratchpad/scratchpad.c

46 lines
1.3 KiB
C
Raw Normal View History

2023-09-27 13:10:40 +00:00
#include "../squiggle.h"
#include "../squiggle_more.h"
2023-09-27 13:10:40 +00:00
#include <math.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
2024-01-20 13:30:20 +00:00
// Replicate <https://arxiv.org/pdf/1806.02404.pdf>, and in particular the red line in page 11.
// Could also be interesting to just produce and save many samples.
2023-09-27 13:10:40 +00:00
// set randomness seed
uint64_t* seed = malloc(sizeof(uint64_t));
2024-01-20 13:02:59 +00:00
*seed = UINT64_MAX/64; // xorshift can't start with a seed of 0
2023-11-29 23:08:36 +00:00
int n_samples = 100*MILLION;
int p_sixteenth = 0;
int p_eighth = 0;
int p_quarter = 0;
int p_half = 0;
double sample;
for(int i=0; i<n_samples; i++){
sample = sample_unit_uniform(seed);
// printf("%lf\n", sample);
if (sample < 1.0/16.0){
p_sixteenth++;
p_eighth++;
p_quarter++;
p_half++;
} else if(sample < 0.125){
p_eighth++;
p_quarter++;
p_half++;
} else if(sample < 0.25){
p_quarter++;
p_half++;
} else if(sample < 0.5){
p_half++;
}else{
// printf("Sample > 0.5\n");
2024-01-20 13:02:59 +00:00
}
2024-01-20 13:30:20 +00:00
}
printf("p_16th: %lf; p_eighth; %lf; p_quarter: %lf; p_half: %lf", ((double)p_sixteenth)/n_samples, (double)p_eighth/n_samples, (double)p_quarter/n_samples, (double)p_half/n_samples);
2023-09-27 13:10:40 +00:00
}