![]() |
Multivariate Analysis Package
0.3
A multivariate distributions analysis package
|
Multivariate Student's t Distribution More...
#include <tDist.h>
Public Member Functions | |
tDistribution (unsigned int Dimension, unsigned int DegFreedom, const Eigen::VectorXd &locVect, const Eigen::MatrixXd &ScaleMatr) | |
Construct a multivariate student's t with the given parameters. More... | |
tDistribution (unsigned int Dimension=1U, unsigned int DegFreedom=1U) | |
Construct a multivariate standardized student's t. More... | |
Eigen::MatrixXd | ExtractSamples (unsigned int NumSamples) const |
Generates multiple simulations from the distribution. More... | |
Eigen::MatrixXd | ExtractSamplesCDF (unsigned int NumSamples) const |
Extracts samples from the distribution and returns their marginal CDF. More... | |
double | GetCumulativeDesity (const Eigen::VectorXd &Coordinates) const |
Computes the cumulative density function of the distribution in correspondence of the supplied coordinates. More... | |
unsigned int | GetDegreesOfFreedom () const |
Get the degrees of freedom of the distribution. More... | |
double | GetDensity (const Eigen::VectorXd &Coordinates) const |
Computes the probability density function of the distribution in correspondence of the supplied coordinates. More... | |
const Eigen::VectorXd & | GetLocationVector () const |
Get the location vector of the distribution. More... | |
Eigen::VectorXd | GetQuantile (double Prob) const |
Computes the inverse cumulative density function of the distribution in correspondence of the supplied probability. More... | |
const Eigen::MatrixXd & | GetScaleMatrix () const |
Get the scale matrix of the distribution. More... | |
Eigen::MatrixXd | GetVarMatrix () const |
Computes the variance matrix of the distribution. More... | |
bool | SetDegreesOfFreedom (unsigned int a) |
Set the degrees of freedom of the distribution. More... | |
bool | SetDimension (unsigned int Dimension) |
Set the dimensionality of the distribution. More... | |
bool | SetLocationVector (const Eigen::VectorXd &mVect) |
Set the expected values vector. More... | |
bool | SetLocationVector (const std::vector< double > &mVect) |
Set the location vector. More... | |
bool | SetScaleMatrix (const Eigen::MatrixXd &SclMatr) |
Set the scale matrix of the distribution. More... | |
bool | SetScaleMatrix (const std::vector< double > &mVect, bool RowWise=true) |
Set the scale matrix of the distribution. More... | |
![]() | |
virtual Eigen::RowVectorXd | ExtractSample () const |
Generates a single simulation from the distribution. More... | |
virtual Eigen::RowVectorXd | ExtractSampleCDF () const |
Generates a single simulation from the distribution and returns its marginal CDF. More... | |
virtual std::vector< double > | ExtractSampleCDFVect () const |
Generates a single simulation from the distribution and returns its marginal CDF. More... | |
virtual std::map< unsigned int, std::vector< double > > | ExtractSamplesCDFMap (unsigned int NumSamples) const |
Extracts samples from the distribution and returns their marginal CDF. More... | |
virtual std::map< unsigned int, std::vector< double > > | ExtractSamplesMap (unsigned int NumSamples) const |
Generates multiple simulations from the distribution. More... | |
virtual std::vector< double > | ExtractSampleVector () const |
Generates a single simulation from the distribution. More... | |
virtual double | GetCumulativeDesity (const std::vector< double > &Coordinates) const |
Computes the cumulative density function of the distribution in correspondence of the supplied coordinates. More... | |
unsigned int | GetCurrentSeed () const |
Get the random number generator seed. More... | |
virtual double | GetDensity (const std::vector< double > &Coordinates) const |
Computes the probability density function of the distribution in correspondence of the supplied coordinates. More... | |
unsigned int | GetDimension () const |
Get the dimensionality of the distribution. More... | |
virtual std::vector< double > | GetQuantileVector (double Prob) const |
Computes the inverse cumulative density function of the distribution in correspondence of the supplied probability. More... | |
bool | IsValid () const |
Check if the distribution is valid. More... | |
void | SetRandomSeed (unsigned int NewSeed) |
Set the random number generator seed. More... | |
virtual double * | GetQuantileArray (double Prob) |
Computes the inverse cumulative density function of the distribution in correspondence of the supplied probability. More... | |
virtual double | GetCumulativeDesity (double *Coordinates) const |
Computes the cumulative density function of the distribution in correspondence of the supplied coordinates. More... | |
virtual double | GetDensity (double *Coordinates) const |
Computes the probability density function of the distribution in correspondence of the supplied coordinates. More... | |
virtual double * | ExtractSampleArray () const |
Generates a single simulation from the distribution. More... | |
virtual double ** | ExtractSamplesMatix (unsigned int NumSamples) const |
Generates a single simulation from the distribution. More... | |
virtual double * | ExtractSampleCDFArray () const |
Generates a single simulation from the distribution and returns its marginal CDF. More... | |
virtual double ** | ExtractSamplesCDFMatix (unsigned int NumSamples) const |
Generates a single simulation from the distribution and returns its marginal CDF. More... | |
Multivariate Student's t Distribution
This class provides the functionality of calculating the probability density value, cumulative probability density value and generate random samples from a multivariate Student's t distribution.
Defining:
The multivariate student's t distribution funtion is defined as: \( f(\textbf{x})= \frac{\Gamma(\frac{v+k}{2})}{\Gamma(\frac{v}{2}) v^{k/2} \pi^{k/2} |\boldsymbol{\Sigma}|^{1/2} (1+ \frac{1}{v} (\textbf{x}-\boldsymbol{\mu})' \boldsymbol{\Sigma}^{-1} (\textbf{x}-\boldsymbol{\mu}))^{\frac{v+k}{2}}} \)
The algorithm for cdf calculation is based on A. Genz & F. Bretz (2002)
If you construct multiple instances of this class, to avoid the generated samples to be the same, you should supply a different seed. To do so, for example, you can call MyDistribution.SetRandomSeed(MyDistribution.GetCurrentSeed()+1U);
Please refer to the Examples page for usage examples.
tDistribution::tDistribution | ( | unsigned int | Dimension, |
unsigned int | DegFreedom, | ||
const Eigen::VectorXd & | locVect, | ||
const Eigen::MatrixXd & | ScaleMatr | ||
) |
Construct a multivariate student's t with the given parameters.
Dimension | The dimensionality of the distribution (supports also univariate student's t distributions in case this is 1) |
DegFreedom | The degrees of freedom of the distribution |
locVect | The location vector |
ScaleMatr | The scale matrix |
Construct a multivariate student's t distribution.
In case:
The class will be considered invalid (it can be checked using IsValid()
) and won't produce any result until the problem is fixed.
tDistribution::tDistribution | ( | unsigned int | Dimension = 1U , |
unsigned int | DegFreedom = 1U |
||
) |
Construct a multivariate standardized student's t.
Dimension | The dimensionality of the multivariate normal (supports also univariate Gaussian distributions in case this is 1) |
DegFreedom | The degrees of freedom of the distribution |
Construct a multivariate student's t distribution with all location parameters set to 0 and scale matrix set to the identity.
In case the Dimension or the DegFreedom are 0 the class will be considered invalid (it can be checked using IsValid()
) and won't produce any result until the problem is fixed.
If no argument is specified, a univariate standardized student's t with 1 degree of freedom, is created
|
virtual |
Generates multiple simulations from the distribution.
NumSamples | The number of simulation to run |
This function generates NumSamples simulation from the current distribution and returns them in matrix form.
If NumSamples is 0 or the distribution is invalid, a null matrix is returned
Implements Multivariate::AbstarctDistribution.
|
virtual |
Extracts samples from the distribution and returns their marginal CDF.
NumSamples | The number of simulation to run |
This function generates NumSamples simulation from the current distribution, computes the marginal cumulative density function for each of them and returns them in matrix form.
This function simulates extractions from a t copula
If NumSamples is 0 or the distribution is invalid, a null matrix is returned
Implements Multivariate::AbstarctDistribution.
|
virtual |
Computes the cumulative density function of the distribution in correspondence of the supplied coordinates.
Coordinates | A vector containing the coordinates of the point for which the cdf should be computed |
This function computes the cumulative density function of the current distribution associated with the given coordinates.
If the number of elements in Coordinates is different from the dimensionality of the distribution or the distribution is invalid, -1 is returned.
Implements Multivariate::AbstarctDistribution.
|
inline |
Get the degrees of freedom of the distribution.
|
virtual |
Computes the probability density function of the distribution in correspondence of the supplied coordinates.
Coordinates | A vector containing the coordinates of the point for which the pdf should be computed |
This function computes the probability density function of the current distribution associated with the given coordinates.
If the number of elements in Coordinates is different from the dimensionality of the distribution or the distribution is invalid, -1 is returned
Implements Multivariate::AbstarctDistribution.
|
inline |
Get the location vector of the distribution.
|
virtual |
Computes the inverse cumulative density function of the distribution in correspondence of the supplied probability.
Prob | The probability for which the corresponding quantile must be found |
This function computes the inverse cumulative density function of the current distribution associated with the given probability.
The solution is unique only in the univariate case.
Generally the system of equations \( F^{-1}(Coordinates_1 \cdots Coordinates_k)=Prob \) has k-1 degrees of freedom, where k is the dimensionality of the distribution.
The additional restriction imposed to get to an unique solution is that each coordinate has equal distance from it's mean.
If the probability supplied is greater than 1, less than 0 or the distribution is invalid, an empty vector is returned.
Implements Multivariate::AbstarctDistribution.
|
inline |
Get the scale matrix of the distribution.
Eigen::MatrixXd tDistribution::GetVarMatrix | ( | ) | const |
Computes the variance matrix of the distribution.
This function computes the variance matrix of the current distribution.
Defining:
The variance matrix is defined as \( \frac{v}{v-2} \boldsymbol{\Sigma} \forall v>2 \)
If the degrees of freedom are less than 3 or the distribution is invalid, a null matrix is returned
bool tDistribution::SetDegreesOfFreedom | ( | unsigned int | a | ) |
Set the degrees of freedom of the distribution.
a | The number of degrees of freedom of the distribution |
This function tries to set the degrees of freedom of the distribution to the new ones.
In case a is less than 1 the degrees of freedom of the distribution will not be changed and this function will return false
|
virtual |
Set the dimensionality of the distribution.
Dimension | the new dimensionality of the distribution |
This function will try to change the dimensionality of the distribution (e.g. 2 for bivariate, 3 for trivariate, etc.)
All the components of the location vector will be reset to 0 and the scale matrix will default to an identity matrix, degrees of freedom wil not be changed
If the argument passed is 0 the dimensionality will not be changed and the function will return false
Implements Multivariate::AbstarctDistribution.
|
inline |
Set the expected values vector.
mVect | the vector of new values for the location vector |
This function attempts to set the location vector to the new values supplied.
If the degrees of freedom are more than 1, this vector is the mean vector
If the dimension of the vector is different from the dimension of the distribution the location vector is not changed and false is returned
bool tDistribution::SetLocationVector | ( | const std::vector< double > & | mVect | ) |
Set the location vector.
mVect | the vector of new values for the location vector |
This is an overloaded version of SetLocationVector(const Eigen::VectorXd&)
bool tDistribution::SetScaleMatrix | ( | const Eigen::MatrixXd & | SclMatr | ) |
Set the scale matrix of the distribution.
SclMatr | the new scale matrix of the distribution |
This function tries to set the scale matrix of the distribution to the new one.
In case:
The scale matrix of the distribution will not be changed and this function will return false
bool tDistribution::SetScaleMatrix | ( | const std::vector< double > & | mVect, |
bool | RowWise = true |
||
) |
Set the scale matrix of the distribution.
mVect | a vector containing the elements of the new scale matrix of the distribution |
RowWise | if it's set to true (the default) the matrix will be filled by row. If it's false it will be filled by columns |
This function tries to set the scale matrix of the distribution to the new one.
Constructs square a matrix with number of rows equal to the dimensionality of the distribution, it is then filled with the values supplied in order according to the RowWise parameter
In case:
The scale matrix of the distribution will not be changed and this function will return false