forked from personal/squiggle.c
61 lines
1.8 KiB
C
61 lines
1.8 KiB
C
#ifndef SQUIGGLEC
|
|
#define SQUIGGLEC
|
|
|
|
// uint64_t header
|
|
#include <stdint.h>
|
|
|
|
// Pseudo Random number generator
|
|
uint64_t xorshift64(uint64_t* seed);
|
|
|
|
// Basic distribution sampling functions
|
|
double sample_unit_uniform(uint64_t* seed);
|
|
double sample_unit_normal(uint64_t* seed);
|
|
|
|
// Composite distribution sampling functions
|
|
double sample_uniform(double start, double end, uint64_t* seed);
|
|
double sample_normal(double mean, double sigma, uint64_t* seed);
|
|
double sample_lognormal(double logmean, double logsigma, uint64_t* seed);
|
|
double sample_to(double low, double high, uint64_t* seed);
|
|
|
|
double sample_gamma(double alpha, uint64_t* seed);
|
|
double sample_beta(double a, double b, uint64_t* seed);
|
|
|
|
// Array helpers
|
|
double array_sum(double* array, int length);
|
|
void array_cumsum(double* array_to_sum, double* array_cumsummed, int length);
|
|
double array_mean(double* array, int length);
|
|
double array_std(double* array, int length);
|
|
|
|
// Mixture function
|
|
double sample_mixture(double (*samplers[])(uint64_t*), double* weights, int n_dists, uint64_t* seed);
|
|
|
|
// Box
|
|
struct box {
|
|
int empty;
|
|
double content;
|
|
char* error_msg;
|
|
};
|
|
|
|
// Macros to handle errors
|
|
#define MAX_ERROR_LENGTH 500
|
|
#define EXIT_ON_ERROR 0
|
|
#define PROCESS_ERROR(error_msg) process_error(error_msg, EXIT_ON_ERROR, __FILE__, __LINE__)
|
|
struct box process_error(const char* error_msg, int should_exit, char* file, int line);
|
|
|
|
// Inverse cdf
|
|
struct box inverse_cdf_double(double cdf(double), double p);
|
|
struct box inverse_cdf_box(struct box cdf_box(double), double p);
|
|
|
|
// Samplers from cdf
|
|
struct box sampler_cdf_double(double cdf(double), uint64_t* seed);
|
|
struct box sampler_cdf_box(struct box cdf(double), uint64_t* seed);
|
|
|
|
// Get 90% confidence interval
|
|
struct c_i {
|
|
float low;
|
|
float high;
|
|
};
|
|
struct c_i get_90_confidence_interval(double (*sampler)(uint64_t*), uint64_t* seed);
|
|
|
|
#endif
|