CosmoBolognaLib
Free Software C++/Python libraries for cosmological calculations
cbl::glob::Distribution Class Reference

The class CombinedDistribution. More...

#include "Headers/Distribution.h"

Inheritance diagram for cbl::glob::Distribution:

Public Member Functions

DistributionType distributionType () const
 return the distribution type More...
 
double operator() (double xx)
 evaluate distribution More...
 
double log_distribution (double xx)
 evaluate log-distribution More...
 
void set_seed (const int seed)
 set distribution seed More...
 
void set_limits (const double xmin, const double xmax)
 set the distribution limits More...
 
void set_constant_distribution (const double value)
 set a constant distribution More...
 
void set_uniform_distribution (const double xmin, const double xmax, const int seed=1)
 set an uniform distribution with input limits and seed More...
 
void set_gaussian_distribution (const double mean, const double sigma, const int seed=1)
 set normal distribution More...
 
void set_poisson_distribution (const double mean, const int seed=1)
 set poisson distribution
More...
 
void set_custom_distribution (const distribution_func func, const std::shared_ptr< void > distribution_fixed_pars, const std::vector< double > distribution_pars, const int seed=1)
 set a custom distribution More...
 
void set_discrete_values (const std::vector< double > discrete_values, const std::vector< double > weights, const int seed=1)
 set discrete distribution values and weights More...
 
void set_binned_distribution (const std::vector< double > var, const std::vector< double > dist, const std::string interpolationType="Spline", const int seed=1)
 set discrete distribution values and weights More...
 
double xmin () const
 return the private member m_xmin More...
 
double xmax () const
 return the private member m_xmax More...
 
double get_mean () const
 return the private member m_mean More...
 
double get_sigma () const
 return the private member m_sigma More...
 
double get_seed () const
 return the private member m_seed More...
 
double distribution_range () const
 the distribution range More...
 
bool isIncluded (const double value) const
 check if a value is included in the distribution limits More...
 
double sample () const
 sample a value from the distribution More...
 
double sample (const int seed)
 sample a value from the distribution More...
 
std::vector< double > sample_vector (const int nvalues)
 sample values from the distribution More...
 
double mean ()
 return the mean value of the distribution More...
 
double variance ()
 return the standard deviation of the distribution More...
 
double std ()
 return the standard deviation of the distribution More...
 
double skewness ()
 return the skewness of the distribution More...
 
double kurtosis ()
 return the kurtosis of the distribution More...
 
std::vector< double > moments ()
 return the moments of the distribution distribution More...
 
double median ()
 return the median of the distibution More...
 
double percentile (const unsigned int i)
 return the i-th percentile of the distribution More...
 
double mode ()
 return the distribution mode More...
 
void get_distribution (std::vector< double > &xx, std::vector< double > &fx, std::vector< double > &err, const std::vector< double > FF, const std::vector< double > WW, const int nbin, const bool linear=true, const std::string file_out=par::defaultString, const double fact=1., const double V1=par::defaultDouble, const double V2=par::defaultDouble, const bool bin_type=true, const bool conv=false, const double sigma=0.)
 derive and store the number distribution of a given std::vector More...
 
Constructors/destructors
 Distribution ()
 default constructor
 
 Distribution (const DistributionType distributionType, const double value)
 constructor of a constant distribution More...
 
 Distribution (const DistributionType distributionType, const double xmin, const double xmax, const int seed=3213)
 constructor of a flat distribution More...
 
 Distribution (const DistributionType distributionType, const std::vector< double > distribution_params, const double xmin, const double xmax, const int seed=1)
 constructor More...
 
 Distribution (const DistributionType distributionType, const distribution_func func, const std::shared_ptr< void > distribution_fixed_pars, const std::vector< double > distribution_pars, const double xmin, const double xmax, const int seed=1)
 constructor More...
 
 Distribution (const DistributionType distributionType, const std::vector< double > discrete_values, const std::vector< double > weights, const int seed=1)
 constructor More...
 
 Distribution (const DistributionType distributionType, const std::vector< double > var, const std::vector< double > dist, const int nbin, const std::string interpolationType, const int seed=1)
 constructor More...
 
 ~Distribution ()=default
 default destructor
 

Protected Member Functions

void m_set_distribution_normalization ()
 set distribution normalization
 
double m_moments_integrator (const double xx, const unsigned int order)
 integrand of the moments distribution More...
 
double m_central_moments_integrator (const double xx, const unsigned int order)
 integrand of the central moments of the distribution More...
 
double m_percentile_integrator (const double xx)
 integrand of the percentile of the distribution More...
 

Protected Attributes

DistributionType m_distributionType
 the type of distribution
 
distribution_func m_func
 the probability distribution function
 
std::shared_ptr< random::RandomNumbersm_distribution_random
 the distribution random generator
 
double m_xmin
 the distribution lower limit
 
double m_xmax
 the distribution upper limit
 
std::vector< double > m_distribution_func_pars
 the parameters of the distribution function
 
std::shared_ptr< void > m_distribution_func_fixed_pars
 void pointer for the distribution function
 
double m_distribution_normalization
 the distribution normalization
 
double m_log_distribution_normalization
 the natural log of distribution normalization
 
double m_mean
 the distribution mean
 
double m_variance
 the distribution variance
 
double m_sigma
 the distribution standard deviation
 
int m_seed
 the distribution seed
 

Detailed Description

The class CombinedDistribution.

The class Distribution.

This class is used to define the N-dimensional distribution

This class is used to define the distribution

Definition at line 124 of file Distribution.h.

Constructor & Destructor Documentation

◆ Distribution() [1/6]

cbl::glob::Distribution::Distribution ( const DistributionType  distributionType,
const double  value 
)

constructor of a constant distribution

Parameters
distributionTypethe type of distribution to be created
valuethe value to be returned

Definition at line 67 of file Distribution.cpp.

◆ Distribution() [2/6]

cbl::glob::Distribution::Distribution ( const DistributionType  distributionType,
const double  xmin,
const double  xmax,
const int  seed = 3213 
)

constructor of a flat distribution

Parameters
distributionTypethe type of distribution to be created
xminlower limit of the distribution
xmaxupper limit of the distribution
seedthe distribution seed for random sampling

Definition at line 80 of file Distribution.cpp.

◆ Distribution() [3/6]

cbl::glob::Distribution::Distribution ( const DistributionType  distributionType,
const std::vector< double >  distribution_params,
const double  xmin,
const double  xmax,
const int  seed = 1 
)

constructor

Parameters
distributionTypethe type of distribution to be created
distribution_paramsparameters of the distribution function or discrete list of values for discrete distribution
xminlower limit of the distribution
xmaxupper limit of the distribution
seedthe distribution seed for random sampling

Definition at line 92 of file Distribution.cpp.

◆ Distribution() [4/6]

cbl::glob::Distribution::Distribution ( const DistributionType  distributionType,
const distribution_func  func,
const std::shared_ptr< void >  distribution_fixed_pars,
const std::vector< double >  distribution_pars,
const double  xmin,
const double  xmax,
const int  seed = 1 
)

constructor

Parameters
distributionTypethe type of distribution to be created
functhe functional form of the distribution
distribution_fixed_parsthe fixed parameters
distribution_parsthe distribution parameters
xminlower limit of the distribution
xmaxupper limit of the distribution
seedthe distribution seed for random sampling

Definition at line 118 of file Distribution.cpp.

◆ Distribution() [5/6]

cbl::glob::Distribution::Distribution ( const DistributionType  distributionType,
const std::vector< double >  discrete_values,
const std::vector< double >  weights,
const int  seed = 1 
)

constructor

Parameters
distributionTypethe type of distribution to be created
discrete_valueslist of discrete values
weightslist of weights for discrete values
seedthe distribution seed for random sampling

Definition at line 132 of file Distribution.cpp.

◆ Distribution() [6/6]

cbl::glob::Distribution::Distribution ( const DistributionType  distributionType,
const std::vector< double >  var,
const std::vector< double >  dist,
const int  nbin,
const std::string  interpolationType,
const int  seed = 1 
)

constructor

Parameters
distributionTypethe type of distribution to be created
varvector containing binned values
distlist of distribution values for each bin
nbinthe number of bins
interpolationTypethe kind of interpolation
seedthe distribution seed for random sampling

Definition at line 144 of file Distribution.cpp.

Member Function Documentation

◆ distribution_range()

double cbl::glob::Distribution::distribution_range ( ) const
inline

the distribution range

Returns
the prior range defined as xmax-xmin

Definition at line 470 of file Distribution.h.

◆ distributionType()

DistributionType cbl::glob::Distribution::distributionType ( ) const
inline

return the distribution type

Returns
the distribution type

Definition at line 316 of file Distribution.h.

◆ get_distribution()

void cbl::glob::Distribution::get_distribution ( std::vector< double > &  xx,
std::vector< double > &  fx,
std::vector< double > &  err,
const std::vector< double >  FF,
const std::vector< double >  WW,
const int  nbin,
const bool  linear = true,
const std::string  file_out = par::defaultString,
const double  fact = 1.,
const double  V1 = par::defaultDouble,
const double  V2 = par::defaultDouble,
const bool  bin_type = true,
const bool  conv = false,
const double  sigma = 0. 
)

derive and store the number distribution of a given std::vector

Parameters
[out]xxstd::vector containing the binned values of the variable
[out]fxstd::vector containing the binned values of the distribution
[out]errstd::vector containing the binned Poisson errors
[in]FFstd::vector containing the given set of data
[in]WWstd::vector containing the weights
[in]nbinthe number of bins
[in]lineartrue → linear binning; false → logarithmic binning
[in]file_outthe output file where the distribution is stored
[in]factfactor used to normalized the distribution
[in]V1the minimum limit of the distribution
[in]V2the maximum limit of the distribution
[in]bin_typetrue → dn/dvar; false → dn/dlogvar
[in]convtrue → compute the Gaussian convolvolution of the distribution; false → do not convolve
[in]sigmaσ of the Gaussian kernel

Definition at line 580 of file Distribution.cpp.

◆ get_mean()

double cbl::glob::Distribution::get_mean ( ) const
inline

return the private member m_mean

Returns
the distribution mean

Definition at line 448 of file Distribution.h.

◆ get_seed()

double cbl::glob::Distribution::get_seed ( ) const
inline

return the private member m_seed

Returns
the distribution seed

Definition at line 462 of file Distribution.h.

◆ get_sigma()

double cbl::glob::Distribution::get_sigma ( ) const
inline

return the private member m_sigma

Returns
the distribution standard deviation

Definition at line 455 of file Distribution.h.

◆ isIncluded()

bool cbl::glob::Distribution::isIncluded ( const double  value) const

check if a value is included in the distribution limits

Parameters
valuethe value to be checked
Returns
0 → not included in distribution range; 1 → included in distribution range

Definition at line 359 of file Distribution.cpp.

◆ kurtosis()

double cbl::glob::Distribution::kurtosis ( )

return the kurtosis of the distribution

Returns
the distribution std

Definition at line 485 of file Distribution.cpp.

◆ log_distribution()

double cbl::glob::Distribution::log_distribution ( double  xx)

evaluate log-distribution

Parameters
xxthe value for distribution calculation
Returns
the log-distribution value

Definition at line 175 of file Distribution.cpp.

◆ m_central_moments_integrator()

double cbl::glob::Distribution::m_central_moments_integrator ( const double  xx,
const unsigned int  order 
)
inlineprotected

integrand of the central moments of the distribution

Parameters
xxthe integration variable
ordermoment order
Returns
integrand

Definition at line 192 of file Distribution.h.

◆ m_moments_integrator()

double cbl::glob::Distribution::m_moments_integrator ( const double  xx,
const unsigned int  order 
)
inlineprotected

integrand of the moments distribution

Parameters
xxthe integration variable
ordermoment order
Returns
integrand

Definition at line 180 of file Distribution.h.

◆ m_percentile_integrator()

double cbl::glob::Distribution::m_percentile_integrator ( const double  xx)
protected

integrand of the percentile of the distribution

Parameters
xxthe integration variable
Returns
integrand

Definition at line 45 of file Distribution.cpp.

◆ mean()

double cbl::glob::Distribution::mean ( )

return the mean value of the distribution

Returns
the mean value of the distribution

Definition at line 408 of file Distribution.cpp.

◆ median()

double cbl::glob::Distribution::median ( )
inline

return the median of the distibution

Returns
the distribution median

Definition at line 558 of file Distribution.h.

◆ mode()

double cbl::glob::Distribution::mode ( )

return the distribution mode

Returns
the distribution mode

Definition at line 541 of file Distribution.cpp.

◆ moments()

vector< double > cbl::glob::Distribution::moments ( )

return the moments of the distribution distribution

Returns
the distribution moments

Definition at line 507 of file Distribution.cpp.

◆ operator()()

double cbl::glob::Distribution::operator() ( double  xx)

evaluate distribution

Parameters
xxthe value for distribution calculation
Returns
the distribution value

Definition at line 165 of file Distribution.cpp.

◆ percentile()

double cbl::glob::Distribution::percentile ( const unsigned int  i)

return the i-th percentile of the distribution

Parameters
ithe percentile
Returns
the distribution median

Definition at line 516 of file Distribution.cpp.

◆ sample() [1/2]

double cbl::glob::Distribution::sample ( ) const

sample a value from the distribution

Returns
value of the parameter

Definition at line 371 of file Distribution.cpp.

◆ sample() [2/2]

double cbl::glob::Distribution::sample ( const int  seed)

sample a value from the distribution

Parameters
seedthe seed for random number generation
Returns
value of the parameter

Definition at line 383 of file Distribution.cpp.

◆ sample_vector()

vector< double > cbl::glob::Distribution::sample_vector ( const int  nvalues)

sample values from the distribution

Parameters
nvaluesthe number of points to be generated
Returns
values of the parameter

Definition at line 393 of file Distribution.cpp.

◆ set_binned_distribution()

void cbl::glob::Distribution::set_binned_distribution ( const std::vector< double >  var,
const std::vector< double >  dist,
const std::string  interpolationType = "Spline",
const int  seed = 1 
)

set discrete distribution values and weights

Parameters
varvector containing binned values
distlist of distribution values for each bin
interpolationTypethe kind of interpolation
seedthe distribution seed for random sampling

Definition at line 336 of file Distribution.cpp.

◆ set_constant_distribution()

void cbl::glob::Distribution::set_constant_distribution ( const double  value)

set a constant distribution

Parameters
valuethe value to be returned

Definition at line 195 of file Distribution.cpp.

◆ set_custom_distribution()

void cbl::glob::Distribution::set_custom_distribution ( const distribution_func  func,
const std::shared_ptr< void >  distribution_fixed_pars,
const std::vector< double >  distribution_pars,
const int  seed = 1 
)

set a custom distribution

Parameters
functhe functional form of the distribution
distribution_fixed_parsthe fixed parameters
distribution_parsthe distribution parameters
seedthe distribution seed for random sampling

Definition at line 317 of file Distribution.cpp.

◆ set_discrete_values()

void cbl::glob::Distribution::set_discrete_values ( const std::vector< double >  discrete_values,
const std::vector< double >  weights,
const int  seed = 1 
)

set discrete distribution values and weights

Parameters
discrete_valuesvector containing discrete values
weightslist of weights for discrete values
seedthe distribution seed for random sampling

Definition at line 286 of file Distribution.cpp.

◆ set_gaussian_distribution()

void cbl::glob::Distribution::set_gaussian_distribution ( const double  mean,
const double  sigma,
const int  seed = 1 
)

set normal distribution

Parameters
meanthe normal distribution mean
sigmathe normal distribution standard deviation
seedthe distribution seed for random sampling

Definition at line 233 of file Distribution.cpp.

◆ set_limits()

void cbl::glob::Distribution::set_limits ( const double  xmin,
const double  xmax 
)

set the distribution limits

Parameters
xminlower limit of the distribution
xmaxupper limit of the distribution

Definition at line 185 of file Distribution.cpp.

◆ set_poisson_distribution()

void cbl::glob::Distribution::set_poisson_distribution ( const double  mean,
const int  seed = 1 
)

set poisson distribution

Parameters
meanthe poisson distribution mean
seedthe distribution seed for random sampling

Definition at line 255 of file Distribution.cpp.

◆ set_seed()

void cbl::glob::Distribution::set_seed ( const int  seed)
inline

set distribution seed

Parameters
seedthe distribution seed

Definition at line 343 of file Distribution.h.

◆ set_uniform_distribution()

void cbl::glob::Distribution::set_uniform_distribution ( const double  xmin,
const double  xmax,
const int  seed = 1 
)

set an uniform distribution with input limits and seed

Parameters
xminlower limit of the distribution
xmaxupper limit of the distribution
seedthe distribution seed for random sampling

Definition at line 211 of file Distribution.cpp.

◆ skewness()

double cbl::glob::Distribution::skewness ( )

return the skewness of the distribution

Returns
the distribution std

Definition at line 463 of file Distribution.cpp.

◆ std()

double cbl::glob::Distribution::std ( )

return the standard deviation of the distribution

Returns
the distribution std

Definition at line 454 of file Distribution.cpp.

◆ variance()

double cbl::glob::Distribution::variance ( )

return the standard deviation of the distribution

Returns
the distribution std

Definition at line 430 of file Distribution.cpp.

◆ xmax()

double cbl::glob::Distribution::xmax ( ) const
inline

return the private member m_xmax

Returns
the distribution upper limit

Definition at line 441 of file Distribution.h.

◆ xmin()

double cbl::glob::Distribution::xmin ( ) const
inline

return the private member m_xmin

Returns
the distribution lower limit

Definition at line 434 of file Distribution.h.


The documentation for this class was generated from the following files: