Routines for statistics and advanced traffic generation.
More...
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <errno.h>
#include <string.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <syslog.h>
#include <float.h>
#include <fenv.h>
#include "debug.h"
#include "fg_math.h"
#include "fg_error.h"
#include "fg_definitions.h"
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
#include <gsl/gsl_cdf.h>
#include <gsl/gsl_sf_gamma.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_errno.h>
Go to the source code of this file.
|
int | dist_bernoulli (struct flow *flow, const double p) |
|
double | dist_chisq (struct flow *flow, const double nu) |
|
double | dist_exponential (struct flow *flow, const double mu) |
|
double | dist_lognormal (struct flow *flow, const double zeta, const double sigma) |
|
double | dist_normal (struct flow *flow, const double mu, const double sigma_square) |
|
double | dist_pareto (struct flow *flow, const double k, const double x_min) |
|
double | dist_uniform (struct flow *flow, const double minval, const double maxval) |
|
double | dist_weibull (struct flow *flow, const double alpha, const double beta) |
|
void | free_math_functions (struct flow *flow) |
|
void | init_math_functions (struct flow *flow, unsigned long seed) |
|
Routines for statistics and advanced traffic generation.
Definition in file fg_math.c.
◆ dist_bernoulli()
int dist_bernoulli |
( |
struct flow * |
flow, |
|
|
const double |
p |
|
) |
| |
Definition at line 179 of file fg_math.c.
182 gsl_rng * r =
flow->
r;
183 return gsl_ran_bernoulli (r, p);
186 return rn_uniform_zero_to_one() <= p;
◆ dist_chisq()
double dist_chisq |
( |
struct flow * |
flow, |
|
|
const double |
nu |
|
) |
| |
Definition at line 219 of file fg_math.c.
222 gsl_rng * r =
flow->
r;
223 return gsl_ran_chisq(r, nu);
◆ dist_exponential()
double dist_exponential |
( |
struct flow * |
flow, |
|
|
const double |
mu |
|
) |
| |
Definition at line 123 of file fg_math.c.
126 gsl_rng * r =
flow->
r;
127 return gsl_ran_exponential(r, mu);
130 return -log(rn_uniform())+mu;
◆ dist_lognormal()
double dist_lognormal |
( |
struct flow * |
flow, |
|
|
const double |
zeta, |
|
|
const double |
sigma |
|
) |
| |
Definition at line 163 of file fg_math.c.
167 gsl_rng * r =
flow->
r;
168 return gsl_ran_lognormal (r, zeta, sigma);
◆ dist_normal()
double dist_normal |
( |
struct flow * |
flow, |
|
|
const double |
mu, |
|
|
const double |
sigma_square |
|
) |
| |
Definition at line 149 of file fg_math.c.
153 const gsl_rng * r =
flow->
r;
154 return gsl_ran_gaussian (r, sigma_square) + mu;
157 const double x = rn_uniform_minusone_to_one();
158 return (1.0 / sqrt(2.0*M_PI*sigma_square)) *
159 exp((-pow ((x-mu),2)) / (2 * sigma_square));
◆ dist_pareto()
double dist_pareto |
( |
struct flow * |
flow, |
|
|
const double |
k, |
|
|
const double |
x_min |
|
) |
| |
Definition at line 190 of file fg_math.c.
194 gsl_rng * r =
flow->
r;
195 return gsl_ran_pareto (r, k, x_min);
198 const double x = rn_uniform();
202 return (k/x_min) * pow (x_min/x,k+1);
◆ dist_uniform()
double dist_uniform |
( |
struct flow * |
flow, |
|
|
const double |
minval, |
|
|
const double |
maxval |
|
) |
| |
Definition at line 136 of file fg_math.c.
140 gsl_rng * r =
flow->
r;
141 return gsl_ran_flat(r, minval, maxval);
144 const double x = rn_uniform_zero_to_one();
145 return ((maxval-minval) * x) + minval;
◆ dist_weibull()
double dist_weibull |
( |
struct flow * |
flow, |
|
|
const double |
alpha, |
|
|
const double |
beta |
|
) |
| |
Definition at line 206 of file fg_math.c.
210 gsl_rng * r =
flow->
r;
211 return gsl_ran_weibull (r, alpha, beta);
214 const double x = rn_uniform_zero_to_one();
215 return alpha * beta * pow (x,beta-1.0) * exp(-alpha * pow(x,beta));
◆ free_math_functions()
void free_math_functions |
( |
struct flow * |
flow | ) |
|
◆ init_math_functions()
void init_math_functions |
( |
struct flow * |
flow, |
|
|
unsigned long |
seed |
|
) |
| |
Definition at line 58 of file fg_math.c.
65 fesetround(FE_TONEAREST);
69 const gsl_rng_type * T;
72 flow->
r = gsl_rng_alloc (T);
77 DEBUG_MSG(LOG_WARNING,
"client did not supply random seed value");
78 int data = open(
"/dev/urandom", O_RDONLY);
79 rc = read(
data, &seed,
sizeof (
long) );
82 crit(
"read /dev/urandom failed");
86 gsl_rng_set (
flow->
r, seed);
87 DEBUG_MSG(LOG_WARNING,
"initalized local libgsl random functions for "
88 "flow %d with seed %lu, gsl generator is: %s",
91 srand((
unsigned)seed);
92 DEBUG_MSG(LOG_WARNING,
"initalized posix random functions with seed "
93 "%u", (
unsigned)seed);