Multivariate Analysis Package  0.3
A multivariate distributions analysis package
 All Classes Namespaces Functions Pages
Public Member Functions | List of all members
Multivariate::AbstarctDistribution Class Referenceabstract

Distributions base class. More...

#include <AbstractDistribution.h>

Inheritance diagram for Multivariate::AbstarctDistribution:
Multivariate::NormalDistribution Multivariate::tDistribution Multivariate::UniformDistribution

Public Member Functions

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 Eigen::MatrixXd ExtractSamples (unsigned int NumSamples) const =0
 Generates multiple simulations from the distribution. More...
 
virtual Eigen::MatrixXd ExtractSamplesCDF (unsigned int NumSamples) const =0
 Extracts samples from the distribution and returns their 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 Eigen::VectorXd &Coordinates) const =0
 Computes the cumulative density function of the distribution in correspondence of the supplied coordinates. 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 Eigen::VectorXd &Coordinates) const =0
 Computes the probability density function of the distribution in correspondence of the supplied coordinates. 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 Eigen::VectorXd GetQuantile (double Prob) const =0
 Computes the inverse cumulative density function of the distribution in correspondence of the supplied probability. 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...
 
virtual bool SetDimension (unsigned int Dimension)=0
 Set the dimensionality of the distribution. More...
 
void SetRandomSeed (unsigned int NewSeed)
 Set the random number generator seed. More...
 
Unsafe Methods

The methods in this group use unsafe memory access or return arrays allocated on the heap that must be manually deleted.

These functions are normally not compiled for safety reasons. To use them, the mvPackageUnsafeMethods symbol must be defined at compile time

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...
 

Detailed Description

Distributions base class.

Class that works as an interface to distributions

To generate samples a boost::random::mt19937 random number generator is used and seeded with std::time(NULL).
If you construct multiple instances of derived classes, 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);

Note
This class is abstract
Date
November 2013
License
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

Here, you can find a copy of the GNU Lesser General Public License. Alternatively, see gnu.org.

Member Function Documentation

virtual Eigen::RowVectorXd Multivariate::AbstarctDistribution::ExtractSample ( ) const
inlinevirtual

Generates a single simulation from the distribution.

Returns
A row vector with number of elements equal to the dimensionality of the distribution representing a single extraction from the distribution

This is equal to calling ExtractSamples(1U)

See Also
ExtractSamples()
double * AbstarctDistribution::ExtractSampleArray ( ) const
virtual

Generates a single simulation from the distribution.

Returns
A dynamically allocated array with number of elements equal to the dimensionality of the distribution representing a single extraction from the distribution

This is equivalent to ExtractSample() but returns an array intead of an Eigen::RowVectorXd. If it can't be calculated, NULL is returned

Warning
This function will return an array allocated on the heap. If the user doesn't take care of deleting it, this will lead to memory leaks
virtual Eigen::RowVectorXd Multivariate::AbstarctDistribution::ExtractSampleCDF ( ) const
inlinevirtual

Generates a single simulation from the distribution and returns its marginal CDF.

Returns
A vector with number of elements equal to the dimensionality of the distribution representing a single extraction from the distribution

This is equal to calling ExtractSamplesCDF(1U)

See Also
ExtractSamplesCDF()
double * AbstarctDistribution::ExtractSampleCDFArray ( ) const
virtual

Generates a single simulation from the distribution and returns its marginal CDF.

Returns
A dynamically allocated array with number of elements equal to the dimensionality of the distribution representing a single extraction from the distribution

This is equivalent to ExtractSampleCDF() but returns an array intead of an Eigen::RowVectorXd. If it can't be calculated, NULL is returned

Warning
This function will return an array allocated on the heap. If the user doesn't take care of deleting it, this will lead to memory leaks
std::vector< double > AbstarctDistribution::ExtractSampleCDFVect ( ) const
virtual

Generates a single simulation from the distribution and returns its marginal CDF.

Returns
A vector with number of elements equal to the dimensionality of the distribution representing a single extraction from the distribution

This is equivalent to ExtractSampleCDF() but returns an std::vector intead of an Eigen::RowVectorXd

See Also
ExtractSamplesCDF()
virtual Eigen::MatrixXd Multivariate::AbstarctDistribution::ExtractSamples ( unsigned int  NumSamples) const
pure virtual

Generates multiple simulations from the distribution.

Parameters
NumSamplesThe number of simulation to run
Returns
A matrix with columns equal to the dimensionality of the distribution and rows equal to the number of simulations

This is a pure virtual function. Refer to child documentation for specific implementation details

Implemented in Multivariate::NormalDistribution, Multivariate::tDistribution, and Multivariate::UniformDistribution.

virtual Eigen::MatrixXd Multivariate::AbstarctDistribution::ExtractSamplesCDF ( unsigned int  NumSamples) const
pure virtual

Extracts samples from the distribution and returns their marginal CDF.

Parameters
NumSamplesThe number of simulation to run
Returns
A matrix with columns equal to the dimensionality of the distribution and rows equal to the number of simulations

This is a pure virtual function. Refer to child documentation for specific implementation details

Implemented in Multivariate::NormalDistribution, Multivariate::tDistribution, and Multivariate::UniformDistribution.

std::map< unsigned int, std::vector< double > > AbstarctDistribution::ExtractSamplesCDFMap ( unsigned int  NumSamples) const
virtual

Extracts samples from the distribution and returns their marginal CDF.

Parameters
NumSamplesThe number of simulation to run
Returns
A matrix with columns equal to the dimensionality of the distribution and rows equal to the number of simulations

This function generates NumSamples simulation from the current distribution, computes the marginal cumulative density function for each of them and returns them in a map form.

This function can be seen as simulation extractions from a copula

If NumSamples is 0 or the distribution is invalid, a null matrix is returned

double ** AbstarctDistribution::ExtractSamplesCDFMatix ( unsigned int  NumSamples) const
virtual

Generates a single simulation from the distribution and returns its marginal CDF.

Parameters
NumSamplesThe number of simulation to run
Returns
A dynamically allocated matrix with number of columns equal to the dimensionality of the distribution and number of rows equal to the number of simulations representing multiple draws from the distribution

This is equivalent to ExtractSamplesCDF() but returns a matrix intead of an Eigen::MatrixXd. If it can't be calculated, NULL is returned

Warning
This function will return a matrix allocated on the heap. If the user doesn't take care of deleting it, this will lead to memory leaks
std::map< unsigned int, std::vector< double > > AbstarctDistribution::ExtractSamplesMap ( unsigned int  NumSamples) const
virtual

Generates multiple simulations from the distribution.

Parameters
NumSamplesThe number of simulation to run
Returns
A map that has as keys the index of the dimension (starting from 0) and as values a vector containing the simulation results for that dimension

This function generates NumSamples simulation from the current distribution and returns them in a map form.

If NumSamples is 0 or the distribution is invalid, an empty map is returned

double ** AbstarctDistribution::ExtractSamplesMatix ( unsigned int  NumSamples) const
virtual

Generates a single simulation from the distribution.

Parameters
NumSamplesThe number of simulation to run
Returns
A dynamically allocated matrix with number of columns equal to the dimensionality of the distribution and number of rows equal to the number of simulations representing multiple draws from the distribution

This is equivalent to ExtractSamples() but returns a matrix intead of an Eigen::MatrixXd. If it can't be calculated, NULL is returned

Warning
This function will return a matrix allocated on the heap. If the user doesn't take care of deleting it, this will lead to memory leaks
std::vector< double > AbstarctDistribution::ExtractSampleVector ( ) const
virtual

Generates a single simulation from the distribution.

Returns
A vector with number of elements equal to the dimensionality of the distribution representing a single extraction from the distribution

This is equivalent to ExtractSample() but returns an std::vector intead of an Eigen::RowVectorXd

See Also
ExtractSamples()
virtual double Multivariate::AbstarctDistribution::GetCumulativeDesity ( const Eigen::VectorXd &  Coordinates) const
pure virtual

Computes the cumulative density function of the distribution in correspondence of the supplied coordinates.

Parameters
CoordinatesA vector containing the coordinates of the point for which the cdf should be computed
Returns
The value of the cumulative density function

This is a pure virtual function. Refer to child documentation for specific implementation details

Implemented in Multivariate::NormalDistribution, Multivariate::tDistribution, and Multivariate::UniformDistribution.

double AbstarctDistribution::GetCumulativeDesity ( const std::vector< double > &  Coordinates) const
virtual

Computes the cumulative density function of the distribution in correspondence of the supplied coordinates.

Parameters
CoordinatesA vector containing the coordinates of the point for which the cdf should be computed
Returns
The value of the cumulative density function

This is an overloaded version of GetCumulativeDesity(const Eigen::VectorXd&, bool, unsigned int)const

double AbstarctDistribution::GetCumulativeDesity ( double *  Coordinates) const
virtual

Computes the cumulative density function of the distribution in correspondence of the supplied coordinates.

Parameters
CoordinatesAn array containing the coordinates of the point for which the cdf should be computed
Returns
The value of the cumulative density function

This is an overloaded version of GetCumulativeDesity(const Eigen::VectorXd& Coordinates, bool UseGenz, unsigned int NumSimul)

Warning
This function will search for a number of elements equal to the dimensionality of the distribution in the array. This may mean accessing unallocated memory blocks if the supplied array is not big enough
unsigned int Multivariate::AbstarctDistribution::GetCurrentSeed ( ) const
inline

Get the random number generator seed.

Returns
The random number generator seed.

This function return the seed that was used to initialize the random number generator.

Note
This seed is different from the srand() seed and, even with the same seed, random number generated by the internal generator will be different by those generated by rand()
See Also
SetRandomSeed()
virtual double Multivariate::AbstarctDistribution::GetDensity ( const Eigen::VectorXd &  Coordinates) const
pure virtual

Computes the probability density function of the distribution in correspondence of the supplied coordinates.

Parameters
CoordinatesA vector containing the coordinates of the point for which the pdf should be computed
Returns
The value of the probability density function

This is a pure virtual function. Refer to child documentation for specific implementation details

Implemented in Multivariate::NormalDistribution, Multivariate::tDistribution, and Multivariate::UniformDistribution.

double AbstarctDistribution::GetDensity ( const std::vector< double > &  Coordinates) const
virtual

Computes the probability density function of the distribution in correspondence of the supplied coordinates.

Parameters
CoordinatesA vector containing the coordinates of the point for which the pdf should be computed
Returns
The value of the probability density function

This is an overloaded version of GetDensity(const Eigen::VectorXd& Coordinates, bool GetLogDensity)const

Reimplemented in Multivariate::UniformDistribution.

double AbstarctDistribution::GetDensity ( double *  Coordinates) const
virtual

Computes the probability density function of the distribution in correspondence of the supplied coordinates.

Parameters
CoordinatesAn array containing the coordinates of the point for which the pdf should be computed
Returns
The value of the probability density function

This is an overloaded version of GetDensity(const Eigen::VectorXd&, bool)

Warning
This function will search for a number of elements equal to the dimensionality of the distribution in the array. This may mean accessing unallocated memory blocks if the supplied array is not big enough
unsigned int Multivariate::AbstarctDistribution::GetDimension ( ) const
inline

Get the dimensionality of the distribution.

Returns
The current dimensionality of the distribution
See Also
SetDimension()
virtual Eigen::VectorXd Multivariate::AbstarctDistribution::GetQuantile ( double  Prob) const
pure virtual

Computes the inverse cumulative density function of the distribution in correspondence of the supplied probability.

Parameters
ProbThe probability for which the corresponding quantile must be found
Returns
A vector containing the coordinates of the quantile

This is a pure virtual function. Refer to child documentation for specific implementation details

Implemented in Multivariate::NormalDistribution, Multivariate::tDistribution, and Multivariate::UniformDistribution.

double * AbstarctDistribution::GetQuantileArray ( double  Prob)
virtual

Computes the inverse cumulative density function of the distribution in correspondence of the supplied probability.

Returns
A dynamically allocated array containing the coordinates of the quantile

This is equivalent to GetQuantile() but returns an array intead of an Eigen::VectorXd. If it can't be calculated, NULL is returned

Warning
This function will return a matrix allocated on the heap. If the user doesn't take care of deleting it, this will lead to memory leaks
std::vector< double > AbstarctDistribution::GetQuantileVector ( double  Prob) const
virtual

Computes the inverse cumulative density function of the distribution in correspondence of the supplied probability.

Returns
A vector containing the coordinates of the quantile

This is equivalent to GetQuantile() but returns an std::vector intead of an Eigen::VectorXd

bool Multivariate::AbstarctDistribution::IsValid ( ) const
inline

Check if the distribution is valid.

Returns
A boolean determining if the structure of the distribution is valid

If this function returns false the structure of the distribution is meaningless and no result will be produced until the invalid parameters are cured.

virtual bool Multivariate::AbstarctDistribution::SetDimension ( unsigned int  Dimension)
pure virtual

Set the dimensionality of the distribution.

Parameters
Dimensionthe new dimensionality of the distribution
Returns
A boolean determining if the dimensionality was changed successfully

This is a pure virtual function. Refer to child documentation for specific implementation details

See Also
GetDimension()

Implemented in Multivariate::NormalDistribution, Multivariate::tDistribution, and Multivariate::UniformDistribution.

void AbstarctDistribution::SetRandomSeed ( unsigned int  NewSeed)

Set the random number generator seed.

Parameters
NewSeedthe new random seed
Note
This seed is different from the srand() seed and, even with the same seed, random number generated by the internal generator will be different by those generated by rand()
See Also
GetCurrentSeed()