#ifndef TOR_PROB_DISTR_H
#define TOR_PROB_DISTR_H
#include "lib/cc/compat_compiler.h"
#include "lib/cc/torint.h"
#include "lib/testsupport/testsupport.h"
struct dist_t {
const struct dist_ops_t *ops;
};
#define DIST_BASE(OPS) { .ops = (OPS) }
#ifdef __COVERITY__
#define TYPE_CHECK_OBJ(OPS, OBJ, TYPE) 0
#else
#define TYPE_CHECK_OBJ(OPS, OBJ, TYPE) \
(0*sizeof(&(OBJ) - (const TYPE *)&(OBJ)))
#endif
#define DIST_BASE_TYPED(OPS, OBJ, TYPE) \
DIST_BASE((OPS) + TYPE_CHECK_OBJ(OPS,OBJ,TYPE))
const char *dist_name(const struct dist_t *);
double dist_sample(const struct dist_t *);
double dist_cdf(const struct dist_t *, double x);
double dist_sf(const struct dist_t *, double x);
double dist_icdf(const struct dist_t *, double p);
double dist_isf(const struct dist_t *, double p);
struct dist_ops_t {
const char *name;
double (*sample)(const struct dist_t *);
double (*cdf)(const struct dist_t *, double x);
double (*sf)(const struct dist_t *, double x);
double (*icdf)(const struct dist_t *, double p);
double (*isf)(const struct dist_t *, double p);
};
struct geometric_t {
struct dist_t base;
double p;
};
extern const struct dist_ops_t geometric_ops;
#define GEOMETRIC(OBJ) \
DIST_BASE_TYPED(&geometric_ops, OBJ, struct geometric_t)
struct genpareto_t {
struct dist_t base;
double mu;
double sigma;
double xi;
};
extern const struct dist_ops_t genpareto_ops;
#define GENPARETO(OBJ) \
DIST_BASE_TYPED(&genpareto_ops, OBJ, struct genpareto_t)
struct weibull_t {
struct dist_t base;
double lambda;
double k;
};
extern const struct dist_ops_t weibull_ops;
#define WEIBULL(OBJ) \
DIST_BASE_TYPED(&weibull_ops, OBJ, struct weibull_t)
struct log_logistic_t {
struct dist_t base;
double alpha;
double beta;
};
extern const struct dist_ops_t log_logistic_ops;
#define LOG_LOGISTIC(OBJ) \
DIST_BASE_TYPED(&log_logistic_ops, OBJ, struct log_logistic_t)
struct logistic_t {
struct dist_t base;
double mu;
double sigma;
};
extern const struct dist_ops_t logistic_ops;
#define LOGISTIC(OBJ) \
DIST_BASE_TYPED(&logistic_ops, OBJ, struct logistic_t)
struct uniform_t {
struct dist_t base;
double a;
double b;
};
extern const struct dist_ops_t uniform_ops;
#define UNIFORM(OBJ) \
DIST_BASE_TYPED(&uniform_ops, OBJ, struct uniform_t)
#ifdef PROB_DISTR_PRIVATE
STATIC double logithalf(double p0);
STATIC double logit(double p);
STATIC double random_uniform_01(void);
STATIC double logistic(double x);
STATIC double cdf_logistic(double x, double mu, double sigma);
STATIC double sf_logistic(double x, double mu, double sigma);
STATIC double icdf_logistic(double p, double mu, double sigma);
STATIC double isf_logistic(double p, double mu, double sigma);
STATIC double sample_logistic(uint32_t s, double t, double p0);
STATIC double cdf_log_logistic(double x, double alpha, double beta);
STATIC double sf_log_logistic(double x, double alpha, double beta);
STATIC double icdf_log_logistic(double p, double alpha, double beta);
STATIC double isf_log_logistic(double p, double alpha, double beta);
STATIC double sample_log_logistic(uint32_t s, double p0);
STATIC double cdf_weibull(double x, double lambda, double k);
STATIC double sf_weibull(double x, double lambda, double k);
STATIC double icdf_weibull(double p, double lambda, double k);
STATIC double isf_weibull(double p, double lambda, double k);
STATIC double sample_weibull(uint32_t s, double p0, double lambda, double k);
STATIC double sample_uniform_interval(double p0, double a, double b);
STATIC double cdf_genpareto(double x, double mu, double sigma, double xi);
STATIC double sf_genpareto(double x, double mu, double sigma, double xi);
STATIC double icdf_genpareto(double p, double mu, double sigma, double xi);
STATIC double isf_genpareto(double p, double mu, double sigma, double xi);
STATIC double sample_genpareto(uint32_t s, double p0, double xi);
#endif
#endif