38#include "gsl/gsl_linalg.h"
39#include "gsl/gsl_matrix.h"
40#include "gsl/gsl_rng.h"
41#include "gsl/gsl_randist.h"
42#include "gsl/gsl_vector.h"
43#include "gsl/gsl_version.h"
55#if (GSL_MAJOR_VERSION == 1) || ((GSL_MAJOR_VERSION == 2) && (GSL_MINOR_VERSION < 2))
56#include <gsl/gsl_blas.h>
58gsl_ran_multivariate_gaussian(
const gsl_rng *
r,
const gsl_vector *mu,
const gsl_matrix *L, gsl_vector *
result)
60 const size_t M = L->size1;
61 const size_t N = L->size2;
64 GSL_ERROR(
"requires square matrix", GSL_ENOTSQR);
65 }
else if (mu->size != M) {
66 GSL_ERROR(
"incompatible dimension of mean vector with variance-covariance matrix", GSL_EBADLEN);
67 }
else if (
result->size != M) {
68 GSL_ERROR(
"incompatible dimension of result vector", GSL_EBADLEN);
72 for (i = 0; i < M; ++i)
73 gsl_vector_set(
result, i, gsl_ran_ugaussian(
r));
75 gsl_blas_dtrmv(CblasLower, CblasNoTrans, CblasNonUnit, L,
result);
76 gsl_vector_add(
result, mu);
114 if (
this == &eng)
return *
this;
143 return gsl_rng_uniform_pos(
fRng->
Rng() );
149 return gsl_rng_uniform_int(
fRng->
Rng(), max );
154 return gsl_rng_min(
fRng->
Rng() );
159 return gsl_rng_max(
fRng->
Rng() );
165 for (
double * itr = begin; itr != end; ++itr ) {
166 *itr = gsl_rng_uniform_pos(
fRng->
Rng() );
178 unsigned int ct =
static_cast<unsigned int>(curtime);
188 gsl_rng_set(
fRng->
Rng(), seed );
194 assert (
fRng !=
nullptr);
195 assert (
fRng->
Rng() !=
nullptr );
196 return std::string( gsl_rng_name(
fRng->
Rng() ) );
202 assert (
fRng !=
nullptr);
203 return gsl_rng_size(
fRng->
Rng() );
224 return gsl_ran_gaussian_ratio_method(
fRng->
Rng(),
sigma);
238 gsl_ran_bivariate_gaussian(
fRng->
Rng(), sigmaX, sigmaY, rho, &
x, &
y);
248 bool allocateL =
false;
250 ldec =
new double[dim*dim];
254 gsl_matrix_view L = gsl_matrix_view_array(ldec, dim, dim);
255 gsl_vector_const_view mu = gsl_vector_const_view_array(pars, dim);
256 gsl_vector_view
x = gsl_vector_view_array(genpars, dim);
259 gsl_matrix_const_view A = gsl_matrix_const_view_array(covmat, dim, dim);
260 gsl_matrix_memcpy(&L.matrix, &A.matrix);
261#if ((GSL_MAJOR_VERSION >= 2) && (GSL_MINOR_VERSION > 2))
262 gsl_linalg_cholesky_decomp1(&L.matrix);
264 gsl_linalg_cholesky_decomp(&L.matrix);
268 gsl_ran_multivariate_gaussian(
fRng->
Rng(), &mu.vector, &L.matrix, &
x.vector);
278 return gsl_ran_exponential(
fRng->
Rng(), mu);
284 return gsl_ran_cauchy(
fRng->
Rng(),
a);
290 return gsl_ran_landau(
fRng->
Rng());
302 return gsl_ran_gamma(
fRng->
Rng(),
a,
b);
314 return gsl_ran_chisq(
fRng->
Rng(), nu);
321 return gsl_ran_fdist(
fRng->
Rng(), nu1, nu2);
327 return gsl_ran_tdist(
fRng->
Rng(), nu);
339 return gsl_ran_logistic(
fRng->
Rng(),
a);
345 return gsl_ran_pareto(
fRng->
Rng(),
a,
b);
357 gsl_ran_dir_3d(
fRng->
Rng(), &
x, &
y, &z);
363 return gsl_ran_poisson(
fRng->
Rng(), mu);
369 return gsl_ran_binomial(
fRng->
Rng(),
p,
n);
375 return gsl_ran_negative_binomial(
fRng->
Rng(),
p,
n);
382 std::vector<unsigned int> ival(
p.size());
383 gsl_ran_multinomial(
fRng->
Rng(),
p.size(), ntot, &
p.front(), &ival[0]);
double gsl_ran_gaussian_acr(const gsl_rng *r, const double sigma)
const gsl_rng_type * gsl_rng_mixmax
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
GSLRandomEngine Base class for all GSL random engines, normally user instantiate the derived classes ...
double operator()() const
Generate a random number between ]0,1] 0 is excluded and 1 is included.
void Dir3D(double &x, double &y, double &z) const
generate random numbers in a 3D sphere of radious 1
void SetSeed(unsigned int seed) const
set the random generator seed
void Gaussian2D(double sigmaX, double sigmaY, double rho, double &x, double &y) const
Bivariate Gaussian distribution with correlation.
unsigned int Poisson(double mu) const
Poisson distribution.
double ChiSquare(double nu) const
Chi square distribution.
double FDist(double nu1, double nu2) const
F distribution.
GSLRngWrapper * Engine()
internal method to return the engine Used by class like GSLMCIntegrator to set the engine
double Gamma(double a, double b) const
Gamma distribution.
GSLRandomEngine()
default constructor.
double Exponential(double mu) const
Exponential distribution.
double GaussianTail(double a, double sigma) const
Gaussian Tail distribution.
double Rayleigh(double sigma) const
Rayleigh distribution.
std::vector< unsigned int > Multinomial(unsigned int ntot, const std::vector< double > &p) const
Multinomial distribution.
unsigned long MaxInt() const
return the maximum integer +1 a generator can handle
double Cauchy(double a) const
Cauchy distribution.
double GaussianZig(double sigma) const
Gaussian distribution - Ziggurat method.
unsigned long MinInt() const
return the minimum integer a generator can handle typically this value is 0
double Gaussian(double sigma) const
Gaussian distribution - default method is Box-Muller (polar method)
double Beta(double a, double b) const
Beta distribution.
double Landau() const
Landau distribution.
unsigned int NegativeBinomial(double p, double n) const
Negative Binomial distribution.
void RandomArray(Iterator begin, Iterator end) const
Generate an array of random numbers.
unsigned int Size() const
return the state size of generator
double Pareto(double a, double b) const
Pareto distribution.
double LogNormal(double zeta, double sigma) const
Log Normal distribution.
unsigned int Binomial(double p, unsigned int n) const
Binomial distribution.
void Dir2D(double &x, double &y) const
generate random numbers in a 2D circle of radious 1
void Terminate()
delete pointer to contained rng
void GaussianND(size_t dim, const double *pars, const double *covmat, double *genpars, double *lmat=nullptr) const
Multivariate Gaussian distribution.
std::string Name() const
return name of generator
double GaussianRatio(double sigma) const
Gaussian distribution - Ratio method.
double Logistic(double a) const
Logistic distribution.
unsigned long RndmInt(unsigned long max) const
Generate an integer number between [0,max-1] (including 0 and max-1) if max is larger than available ...
void SetType(GSLRngWrapper *r)
internal method used by the derived class to set the type of generators
void Initialize()
initialize the generator If no rng is present the default one based on Mersenne and Twister is create...
double tDist(double nu) const
t student distribution
GSLRandomEngine & operator=(const GSLRandomEngine &eng)
Assignment operator : make a deep copy of the contained GSL generator.
virtual ~GSLRandomEngine()
call Terminate()
GSLRngWrapper class to wrap gsl_rng structure.
Namespace for new Math classes and functions.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
static void FreeEngine(gsl_rng *r)
static void CreateEngine(gsl_rng *r)