2023-11-18 20:25:12 +00:00
|
|
|
#ifndef SQUIGGLE_C_EXTRA
|
2023-11-29 23:21:24 +00:00
|
|
|
#define SQUIGGLE_C_EXTRA
|
2023-11-18 20:25:12 +00:00
|
|
|
|
2023-11-29 23:21:24 +00:00
|
|
|
/* Parallel sampling */
|
|
|
|
void sampler_parallel(double (*sampler)(uint64_t* seed), double* results, int n_threads, int n_samples);
|
2023-11-18 20:25:12 +00:00
|
|
|
|
2023-11-29 23:21:24 +00:00
|
|
|
/* Get 90% confidence interval */
|
2023-11-18 20:25:12 +00:00
|
|
|
typedef struct ci_t {
|
2023-11-29 23:21:24 +00:00
|
|
|
double low;
|
|
|
|
double high;
|
2023-11-18 20:25:12 +00:00
|
|
|
} ci;
|
2023-11-29 23:21:24 +00:00
|
|
|
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);
|
2023-11-18 20:25:12 +00:00
|
|
|
|
2023-11-29 23:21:24 +00:00
|
|
|
/* Algebra manipulations */
|
2023-11-18 20:25:12 +00:00
|
|
|
|
|
|
|
typedef struct normal_params_t {
|
|
|
|
double mean;
|
|
|
|
double std;
|
|
|
|
} normal_params;
|
|
|
|
normal_params algebra_sum_normals(normal_params a, normal_params b);
|
|
|
|
|
|
|
|
typedef struct lognormal_params_t {
|
|
|
|
double logmean;
|
|
|
|
double logstd;
|
|
|
|
} lognormal_params;
|
|
|
|
lognormal_params algebra_product_lognormals(lognormal_params a, lognormal_params b);
|
|
|
|
|
|
|
|
lognormal_params convert_ci_to_lognormal_params(ci x);
|
2023-11-29 23:21:24 +00:00
|
|
|
ci convert_lognormal_params_to_ci(lognormal_params y);
|
2023-11-18 20:25:12 +00:00
|
|
|
|
2023-11-29 23:21:24 +00:00
|
|
|
/* Error handling */
|
2023-12-03 18:25:35 +00:00
|
|
|
typedef struct box_t {
|
2023-11-29 23:21:24 +00:00
|
|
|
int empty;
|
|
|
|
double content;
|
|
|
|
char* error_msg;
|
2023-12-03 18:25:35 +00:00
|
|
|
} box;
|
2023-11-29 23:21:24 +00:00
|
|
|
#define MAX_ERROR_LENGTH 500
|
|
|
|
#define EXIT_ON_ERROR 0
|
|
|
|
#define PROCESS_ERROR(error_msg) process_error(error_msg, EXIT_ON_ERROR, __FILE__, __LINE__)
|
2023-12-03 18:25:35 +00:00
|
|
|
box process_error(const char* error_msg, int should_exit, char* file, int line);
|
2023-11-29 23:21:24 +00:00
|
|
|
void array_print(double* array, int length);
|
|
|
|
|
|
|
|
/* Inverse cdf */
|
2023-12-03 18:25:35 +00:00
|
|
|
box inverse_cdf_double(double cdf(double), double p);
|
|
|
|
box inverse_cdf_box(box cdf_box(double), double p);
|
2023-11-29 23:21:24 +00:00
|
|
|
|
|
|
|
/* Samplers from cdf */
|
2023-12-03 18:25:35 +00:00
|
|
|
box sampler_cdf_double(double cdf(double), uint64_t* seed);
|
|
|
|
box sampler_cdf_box(box cdf(double), uint64_t* seed);
|
2023-11-19 15:50:21 +00:00
|
|
|
|
2023-11-18 20:25:12 +00:00
|
|
|
#endif
|