2023-07-16 19:00:30 +00:00
|
|
|
#ifndef SQUIGGLEC
|
|
|
|
#define SQUIGGLEC
|
2023-06-26 17:44:41 +00:00
|
|
|
|
2023-07-16 19:00:30 +00:00
|
|
|
// uint32_t header
|
|
|
|
#include <stdint.h>
|
2023-06-26 17:44:41 +00:00
|
|
|
|
|
|
|
// Pseudo Random number generator
|
2023-07-16 19:00:30 +00:00
|
|
|
uint32_t xorshift32(uint32_t* seed);
|
2023-06-26 17:44:41 +00:00
|
|
|
|
2023-07-16 20:32:03 +00:00
|
|
|
// Basic distribution sampling functions
|
2023-07-22 17:21:20 +00:00
|
|
|
float sample_unit_uniform(uint32_t* seed);
|
|
|
|
float sample_unit_normal(uint32_t* seed);
|
2023-07-16 20:32:03 +00:00
|
|
|
|
|
|
|
// Composite distribution sampling functions
|
2023-07-22 17:21:20 +00:00
|
|
|
float sample_uniform(float from, float to, uint32_t* seed);
|
|
|
|
float sample_normal(float mean, float sigma, uint32_t* seed);
|
|
|
|
float sample_lognormal(float logmean, float logsigma, uint32_t* seed);
|
|
|
|
float sample_to(float low, float high, uint32_t* seed);
|
2023-06-26 17:44:41 +00:00
|
|
|
|
|
|
|
// Array helpers
|
2023-07-16 19:00:30 +00:00
|
|
|
float array_sum(float* array, int length);
|
|
|
|
void array_cumsum(float* array_to_sum, float* array_cumsummed, int length);
|
2023-07-22 17:36:43 +00:00
|
|
|
float array_mean(float* array, int length);
|
|
|
|
float array_std(float* array, int length);
|
2023-06-26 17:44:41 +00:00
|
|
|
|
|
|
|
// Mixture function
|
2023-07-22 17:21:20 +00:00
|
|
|
float sample_mixture(float (*samplers[])(uint32_t*), float* weights, int n_dists, uint32_t* seed);
|
2023-06-26 17:44:41 +00:00
|
|
|
|
2023-07-16 19:26:33 +00:00
|
|
|
// Box
|
|
|
|
struct box {
|
|
|
|
int empty;
|
|
|
|
float content;
|
|
|
|
char* error_msg;
|
|
|
|
};
|
|
|
|
|
2023-07-16 20:32:03 +00:00
|
|
|
// Macros to handle errors
|
|
|
|
#define MAX_ERROR_LENGTH 500
|
2023-07-16 20:58:20 +00:00
|
|
|
#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);
|
2023-07-16 20:32:03 +00:00
|
|
|
|
2023-07-16 19:26:33 +00:00
|
|
|
// Inverse cdf
|
|
|
|
struct box inverse_cdf_float(float cdf(float), float p);
|
|
|
|
struct box inverse_cdf_box(struct box cdf_box(float), float p);
|
|
|
|
|
|
|
|
// Samplers from cdf
|
2023-07-16 20:32:03 +00:00
|
|
|
struct box sampler_cdf_float(float cdf(float), uint32_t* seed);
|
|
|
|
struct box sampler_cdf_box(struct box cdf(float), uint32_t* seed);
|
2023-07-16 19:26:33 +00:00
|
|
|
|
2023-07-16 19:00:30 +00:00
|
|
|
#endif
|