squiggle.c

Self-contained Monte Carlo estimation in C99
Log | Files | Refs | README

squiggle.h (1348B)


      1 #ifndef SQUIGGLE_C_CORE
      2 #define SQUIGGLE_C_CORE
      3 
      4 // uint64_t header
      5 #include <stdint.h>
      6 
      7 // Pseudo Random number generator
      8 uint64_t xorshift64(uint64_t* seed);
      9 
     10 // Basic distribution sampling functions
     11 double sample_unit_uniform(uint64_t* seed);
     12 double sample_unit_normal(uint64_t* seed);
     13 
     14 // Composite distribution sampling functions
     15 double sample_uniform(double start, double end, uint64_t* seed);
     16 double sample_normal(double mean, double sigma, uint64_t* seed);
     17 double sample_lognormal(double logmean, double logsigma, uint64_t* seed);
     18 double sample_normal_from_90_ci(double low, double high, uint64_t* seed);
     19 double sample_to(double low, double high, uint64_t* seed);
     20 
     21 double sample_gamma(double alpha, uint64_t* seed);
     22 double sample_beta(double a, double b, uint64_t* seed);
     23 double sample_laplace(double successes, double failures, uint64_t* seed);
     24 
     25 // Array helpers
     26 double array_sum(double* array, int length);
     27 void array_cumsum(double* array_to_sum, double* array_cumsummed, int length);
     28 double array_mean(double* array, int length);
     29 double array_std(double* array, int length);
     30 
     31 // Mixture function
     32 double sample_mixture(double (*samplers[])(uint64_t*), double* weights, int n_dists, uint64_t* seed);
     33 
     34 // Macro to mute "unused variable" warning when -Wall -Wextra is enabled. Useful for nested functions
     35 #define UNUSED(x) (void)(x)
     36 
     37 #endif