fix: reorder headers to fix compilation error

This commit is contained in:
NunoSempere 2023-11-18 21:10:21 +00:00
parent 61851a321a
commit 6387c0df70
23 changed files with 132 additions and 122 deletions

View File

@ -1,7 +1,7 @@
#include "../../squiggle.h"
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
// Estimate functions
double sample_0(uint64_t* seed)
@ -24,7 +24,8 @@ double sample_many(uint64_t* seed)
return sample_to(2, 10, seed);
}
int main(){
int main()
{
// set randomness seed
uint64_t* seed = malloc(sizeof(uint64_t));
*seed = 1000; // xorshift can't start with 0

View File

@ -1,9 +1,10 @@
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include "../../squiggle.h"
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
int main(){
int main()
{
// set randomness seed
uint64_t* seed = malloc(sizeof(uint64_t));
*seed = 1000; // xorshift can't start with 0
@ -14,25 +15,24 @@ int main(){
int n_dists = 4;
double sample_0(uint64_t* seed){ return 0; }
double sample_1(uint64_t* seed) { return 1; }
double sample_few(uint64_t* seed){ return sample_to(1, 3, seed); }
double sample_many(uint64_t* seed){ return sample_to(2, 10, seed); }
double sample_0(uint64_t * seed) { return 0; }
double sample_1(uint64_t * seed) { return 1; }
double sample_few(uint64_t * seed) { return sample_to(1, 3, seed); }
double sample_many(uint64_t * seed) { return sample_to(2, 10, seed); }
double (*samplers[])(uint64_t*) = { sample_0, sample_1, sample_few, sample_many };
double weights[] = { 1 - p_c, p_c / 2, p_c / 4, p_c / 4 };
int n_samples = 1000000;
double* result_many = (double *) malloc(n_samples * sizeof(double));
for(int i=0; i<n_samples; i++){
double* result_many = (double*)malloc(n_samples * sizeof(double));
for (int i = 0; i < n_samples; i++) {
result_many[i] = sample_mixture(samplers, weights, n_dists, seed);
}
printf("result_many: [");
for(int i=0; i<100; i++){
for (int i = 0; i < 100; i++) {
printf("%.2f, ", result_many[i]);
}
printf("]\n");
free(seed);
}

View File

@ -42,4 +42,3 @@ int main()
free(seed);
}

Binary file not shown.

View File

@ -5,7 +5,8 @@
#include <stdlib.h>
// Estimate functions
double beta_1_2_sampler(uint64_t* seed){
double beta_1_2_sampler(uint64_t* seed)
{
return sample_beta(1, 2.0, seed);
}

Binary file not shown.

Binary file not shown.

View File

@ -45,7 +45,5 @@ int main()
ci ci_90 = get_90_confidence_interval(sample_minutes_per_day_jumping_rope_needed_to_burn_10kg, seed);
printf("90%% confidence interval: [%f, %f]\n", ci_90.low, ci_90.high);
free(seed);
}

Binary file not shown.

View File

@ -14,27 +14,31 @@ double yearly_probability_nuclear_collapse(double year, uint64_t* seed)
// to get a probability,
// rather than sampling from a distribution over probabilities.
}
double yearly_probability_nuclear_collapse_2023(uint64_t* seed){
double yearly_probability_nuclear_collapse_2023(uint64_t* seed)
{
return yearly_probability_nuclear_collapse(2023, seed);
}
double yearly_probability_nuclear_collapse_after_recovery(double year, double rebuilding_period_length_years, uint64_t* seed){
double yearly_probability_nuclear_collapse_after_recovery(double year, double rebuilding_period_length_years, uint64_t* seed)
{
// assumption: nuclear
double successes = 1.0;
double failures = (year - rebuilding_period_length_years - 1960 - 1);
return sample_laplace(successes, failures, seed);
}
double yearly_probability_nuclear_collapse_after_recovery_example(uint64_t* seed){
double yearly_probability_nuclear_collapse_after_recovery_example(uint64_t* seed)
{
double year = 2070;
double rebuilding_period_length_years =30;
double rebuilding_period_length_years = 30;
// So, there was a nuclear collapse in 2040,
// then a recovery period of 30 years
// and it's now 2070
return yearly_probability_nuclear_collapse_after_recovery(year, rebuilding_period_length_years, seed);
}
double yearly_probability_nuclear_collapse_after_recovery_antiinductive(uint64_t* seed){
return yearly_probability_nuclear_collapse(2023, seed)/2;
double yearly_probability_nuclear_collapse_after_recovery_antiinductive(uint64_t* seed)
{
return yearly_probability_nuclear_collapse(2023, seed) / 2;
}
int main()

Binary file not shown.

View File

@ -22,8 +22,8 @@ int main()
ln1_ci.low, ln1_ci.high,
ln1.logmean, ln1.logstd);
lognormal_params ln2 = convert_ci_to_lognormal_params((ci){.low = 1, .high = 10});
lognormal_params ln3 = convert_ci_to_lognormal_params((ci){.low = 5, .high = 50});
lognormal_params ln2 = convert_ci_to_lognormal_params((ci) { .low = 1, .high = 10 });
lognormal_params ln3 = convert_ci_to_lognormal_params((ci) { .low = 5, .high = 50 });
lognormal_params sln = algebra_product_lognormals(ln2, ln3);
ci sln_ci = convert_lognormal_params_to_ci(sln);

View File

@ -6,9 +6,9 @@
#include <stdlib.h>
#define ln lognormal_params
#define to(...) convert_ci_to_lognormal_params((ci) __VA_ARGS__)
#define from(...) convert_lognormal_params_to_ci((ln) __VA_ARGS__)
#define times(a,b) algebra_product_lognormals(a,b)
#define to(...) convert_ci_to_lognormal_params((ci)__VA_ARGS__)
#define from(...) convert_lognormal_params_to_ci((ln)__VA_ARGS__)
#define times(a, b) algebra_product_lognormals(a, b)
int main()
{
@ -16,8 +16,8 @@ int main()
uint64_t* seed = malloc(sizeof(uint64_t));
*seed = 1000; // xorshift can't start with 0
ln a = to({.low = 1, .high = 10});
ln b = to({.low = 5, .high = 500});
ln a = to({ .low = 1, .high = 10 });
ln b = to({ .low = 5, .high = 500 });
ln c = times(a, b);
printf("Result: to(%f, %f)\n", from(c).low, from(c).high);

View File

@ -4,19 +4,23 @@
#include <stdio.h>
#include <stdlib.h>
double sample_0(uint64_t* seed){
double sample_0(uint64_t* seed)
{
return 0;
}
double sample_1(uint64_t* seed){
double sample_1(uint64_t* seed)
{
return 1;
}
double sample_normal_mean_1_std_2(uint64_t* seed){
double sample_normal_mean_1_std_2(uint64_t* seed)
{
return sample_normal(1, 2, seed);
}
double sample_1_to_3(uint64_t* seed){
double sample_1_to_3(uint64_t* seed)
{
return sample_to(1, 3, seed);
}

View File

@ -0,0 +1,3 @@
build:
format:

View File

@ -1,16 +1,17 @@
#include "../../squiggle.h"
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
// Estimate functions
int main(){
int main()
{
// set randomness seed
uint64_t* seed = malloc(sizeof(uint64_t));
*seed = 1000; // xorshift can't start with 0
for(int i=0; i<100; i++){
double sample = sample_lognormal(0,10, seed);
for (int i = 0; i < 100; i++) {
double sample = sample_lognormal(0, 10, seed);
printf("%f\n", sample);
}
free(seed);

View File

@ -1,3 +1,4 @@
#include "squiggle.h"
#include <float.h>
#include <limits.h>
#include <math.h>
@ -6,7 +7,6 @@
#include <stdlib.h>
#include <sys/types.h>
#include <time.h>
#include "squiggle.h"
// math constants
#define PI 3.14159265358979323846 // M_PI in gcc gnu99
@ -58,7 +58,6 @@ ci get_90_confidence_interval(double (*sampler)(uint64_t*), uint64_t* seed)
return result;
}
// ## Sample from an arbitrary cdf
struct box {
int empty;