Marmote Core
The project aims at realizing the prototype of a software environment dedicated to modeling with Markov chains.
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
discreteDistribution Class Reference

The general discrete distribution with finite support. More...

#include <discreteDistribution.h>

Inheritance diagram for discreteDistribution:
Distribution Distribution bernoulliDistribution bernoulliDistribution diracDistribution diracDistribution uniformDiscreteDistribution uniformDiscreteDistribution

Public Member Functions

 discreteDistribution (int sz, double *vals, double *probas)
 Constructor for a general discrete distribution from arrays. The array is ***copied***, not taken as pointer. The mean is calculated at creation. More...
 
 discreteDistribution (int sz, char *name)
 Constructor for a general discrete distribution from a file. The file is assumed to contain only the probas. The values are arbitrarily chosen between 0 and sz-1. The mean is calculated at creation. More...
 
 ~discreteDistribution ()
 Destructor for a general discrete distribution. The convention is that internal arrays for values and probas are freed at this moment. If they are useful for something else, they sould be copied. More...
 
double getProba (int i)
 Read accessor for the probas. This is a pseudo-accessor since it performs additional checks. More...
 
double getValue (int i)
 Read accessor for the values. This is a pseudo-accessor since it performs additional checks. More...
 
int nbVals ()
 Read accessor to the number of values in the distribution. More...
 
bool setProba (int i, double v)
 Write accessor for the probas. This is a pseudo-accessor since it performs additional checks. More...
 
double mean ()
 Calculation of the mean. Returns the value since it is pre-computed. More...
 
double rate ()
 Calculation of the rate, which is the inverse of the mean. If the mean is 0, the value INFINITE_RATE is returned. More...
 
double moment (int order)
 Computing the moments of the distribution. More...
 
double laplace (double s)
 computing the Laplace transform of the distribution at real point More...
 
double dLaplace (double s)
 computing the derivative of the Laplace transform at real points More...
 
double cdf (double x)
 Computation of the cumulative density function at some real point x. More...
 
bool hasMoment (int order)
 Test of existence of a moment. These distributions always have one. More...
 
discreteDistributionrescale (double factor)
 rescaling a distribution by some real factor. Not all distributions allow this for any real factor. If the operation fails, or if the factor is 1.0, a copy of the distribution should be returned (not by using the copy() function). More...
 
discreteDistributioncopy ()
 copying a distribution. Typically implemented as rescale(1.0). More...
 
double sample ()
 Sampling from the law This is the straightforward, non optimized, linear-time algorithm. More...
 
double distanceL2 (discreteDistribution *d)
 Computes the L2 distance between two distributions. In case of incompatible or infinite sizes, a negative number is returned. More...
 
double distanceL1 (discreteDistribution *d)
 Computes the L1 distance between this distribution and another one. In case of incompatible or infinite sizes, a negative number is returned. More...
 
double distanceLinfinity (discreteDistribution *d)
 Computes the L-infinity distance between two distributions. In case of incompatible or infinite sizes, a negative number is returned. More...
 
std::string toString ()
 Printing a representation of the law into a string. More...
 
void write (FILE *out, int mode)
 Printing a representation of the law. More...
 
 discreteDistribution (int sz, double *vals, double *probas)
 Constructor for a general discrete distribution from arrays. The array is ***copied***, not taken as pointer. The mean is calculated at creation. More...
 
 discreteDistribution (int sz, char *name)
 Constructor for a general discrete distribution from a file. The file is assumed to contain only the probas. The values are arbitrarily chosen between 0 and sz-1. The mean is calculated at creation. More...
 
 ~discreteDistribution ()
 Destructor for a general discrete distribution. The convention is that internal arrays for values and probas are freed at this moment. If they are useful for something else, they sould be copied. More...
 
double getProba (int i)
 Read accessor for the probas. This is a pseudo-accessor since it performs additional checks. More...
 
double getValue (int i)
 Read accessor for the values. This is a pseudo-accessor since it performs additional checks. More...
 
int nbVals ()
 Read accessor to the number of values in the distribution. More...
 
bool setProba (int i, double v)
 Write accessor for the probas. This is a pseudo-accessor since it performs additional checks. More...
 
double mean ()
 Calculation of the mean. Returns the value since it is pre-computed. More...
 
double rate ()
 Calculation of the rate, which is the inverse of the mean. If the mean is 0, the value INFINITE_RATE is returned. More...
 
double moment (int order)
 Computing the moments of the distribution. More...
 
double laplace (double s)
 computing the Laplace transform of the distribution at real point More...
 
double dLaplace (double s)
 computing the derivative of the Laplace transform at real points More...
 
double cdf (double x)
 
bool hasMoment (int order)
 Test of existence of a moment. These distributions always have one. More...
 
discreteDistributionrescale (double factor)
 rescaling a distribution by some real factor. Not all distributions allow this for any real factor. If the operation fails, or if the factor is 1.0, a copy of the distribution should be returned (not by using the copy() function). More...
 
discreteDistributioncopy ()
 copying a distribution. Typically implemented as rescale(1.0). More...
 
double sample ()
 
double distanceL2 (discreteDistribution *d)
 
double distanceL1 (discreteDistribution *d)
 
double distanceLinfinity (discreteDistribution *d)
 
std::string toString ()
 
void write (FILE *out, int mode)
 
- Public Member Functions inherited from Distribution
virtual ~Distribution ()
 Standard destructor. More...
 
std::string name ()
 Read accessor to the type name of the distribution. More...
 
double variance ()
 Computing the variance of the random variable: the second moment minus the square of the first moment. Variance is the square of the coefficient of variation. The Distribution class offers a default implementation. More...
 
double ccdf (double x)
 computing the complementary cumulative distributon function (or tail) at some real point x. This is the probability that the random variable is strictly larger than x. The Distribution class offers a default implementation. More...
 
void iidSample (int n, double *s)
 drawing an i.i.d. sample from the distribution. The result is returned in an array (that must have been already allocated) passed as a parameter. The Distribution class offers the default implementation with repeated call to sample(). More...
 
virtual double distanceL1 (Distribution *d)
 Computing generally the L1 distance between distributions. More...
 
virtual bool hasProperty (std::string pro)
 Property test function. Current properties are: More...
 
void fprint ()
 write on stdout with NORMAL_PRINT_MODE More...
 
virtual ~Distribution ()
 Standard destructor. More...
 
std::string name ()
 Read accessor to the type name of the distribution. More...
 
double variance ()
 Computing the variance of the random variable: the second moment minus the square of the first moment. Variance is the square of the coefficient of variation. The Distribution class offers a default implementation. More...
 
double ccdf (double x)
 computing the complementary cumulative distributon function (or tail) at some real point x. This is the probability that the random variable is strictly larger than x. The Distribution class offers a default implementation. More...
 
void iidSample (int n, double *s)
 drawing an i.i.d. sample from the distribution. The result is returned in an array (that must have been already allocated) passed as a parameter. The Distribution class offers the default implementation with repeated call to sample(). More...
 
virtual double distanceL1 (Distribution *d)
 Computing generally the L1 distance between distributions. More...
 
virtual bool hasProperty (std::string pro)
 Property test function. Current properties are: More...
 
void fprint ()
 write on stdout with NORMAL_PRINT_MODE More...
 

Protected Member Functions

 discreteDistribution (int sz)
 Constructor for a general discrete distribution from its size. Arrays are created to this size but not initialized. DANGEROUS to use since methods cannot check whether these arrays are correct or not. Use reserved to sub-types such as diracDistribution. More...
 
 discreteDistribution (int sz)
 Constructor for a general discrete distribution from its size. Arrays are created to this size but not initialized. DANGEROUS to use since methods cannot check whether these arrays are correct or not. Use reserved to sub-types such as diracDistribution. More...
 

Protected Attributes

int _nbVals
 
double * _values
 
double * _probas
 
- Protected Attributes inherited from Distribution
std::string _name
 
double _mean
 

Additional Inherited Members

- Static Public Member Functions inherited from Distribution
static double u_0_1 (void)
 
static double exponential (double mean)
 
static double u_0_1 (void)
 
static double exponential (double mean)
 

Detailed Description

The general discrete distribution with finite support.

Constructor & Destructor Documentation

discreteDistribution::discreteDistribution ( int  sz,
double *  vals,
double *  probas 
)

Constructor for a general discrete distribution from arrays. The array is ***copied***, not taken as pointer. The mean is calculated at creation.

Author
Alain Jean-Marie
Parameters
sznumber of values/probas
valsarray of values
probasprobability vector
Returns
an object of type discreteDistribution
discreteDistribution::discreteDistribution ( int  sz,
char *  name 
)

Constructor for a general discrete distribution from a file. The file is assumed to contain only the probas. The values are arbitrarily chosen between 0 and sz-1. The mean is calculated at creation.

Author
Alain Jean-Marie
Parameters
sznumber of values/probas
namethe name of the file
Returns
an object of type discreteDistribution
discreteDistribution::discreteDistribution ( int  sz)
protected

Constructor for a general discrete distribution from its size. Arrays are created to this size but not initialized. DANGEROUS to use since methods cannot check whether these arrays are correct or not. Use reserved to sub-types such as diracDistribution.

Author
Alain Jean-Marie
Parameters
sznumber of values/probas
Returns
an object of type discreteDistribution
discreteDistribution::~discreteDistribution ( )

Destructor for a general discrete distribution. The convention is that internal arrays for values and probas are freed at this moment. If they are useful for something else, they sould be copied.

Author
Alain Jean-Marie
discreteDistribution::discreteDistribution ( int  sz,
double *  vals,
double *  probas 
)

Constructor for a general discrete distribution from arrays. The array is ***copied***, not taken as pointer. The mean is calculated at creation.

Author
Alain Jean-Marie
Parameters
sznumber of values/probas
valsarray of values
probasprobability vector
Returns
an object of type discreteDistribution
discreteDistribution::discreteDistribution ( int  sz,
char *  name 
)

Constructor for a general discrete distribution from a file. The file is assumed to contain only the probas. The values are arbitrarily chosen between 0 and sz-1. The mean is calculated at creation.

Author
Alain Jean-Marie
Parameters
sznumber of values/probas
namethe name of the file
Returns
an object of type discreteDistribution
discreteDistribution::discreteDistribution ( int  sz)
protected

Constructor for a general discrete distribution from its size. Arrays are created to this size but not initialized. DANGEROUS to use since methods cannot check whether these arrays are correct or not. Use reserved to sub-types such as diracDistribution.

Author
Alain Jean-Marie
Parameters
sznumber of values/probas
Returns
an object of type discreteDistribution
discreteDistribution::~discreteDistribution ( )

Destructor for a general discrete distribution. The convention is that internal arrays for values and probas are freed at this moment. If they are useful for something else, they sould be copied.

Author
Alain Jean-Marie

Member Function Documentation

double discreteDistribution::cdf ( double  x)
virtual
Parameters
x
Returns
double

Implements Distribution.

Reimplemented in uniformDiscreteDistribution.

double discreteDistribution::cdf ( double  x)
virtual

Computation of the cumulative density function at some real point x.

Parameters
x
Returns
double
Author
Alain Jean-Marie
Parameters
xvalue at which the CDF is computed
Returns
CDF(x)

Implements Distribution.

Reimplemented in uniformDiscreteDistribution, uniformDiscreteDistribution, bernoulliDistribution, and diracDistribution.

discreteDistribution* discreteDistribution::copy ( )
virtual

copying a distribution. Typically implemented as rescale(1.0).

See also
rescale(double)
Returns
a copy of the distribution

Implements Distribution.

Reimplemented in uniformDiscreteDistribution.

discreteDistribution * discreteDistribution::copy ( )
virtual

copying a distribution. Typically implemented as rescale(1.0).

Copying the law.

See also
rescale(double)
Returns
a copy of the distribution
Author
Alain Jean-Marie
Returns
a copy of the law

Implements Distribution.

Reimplemented in uniformDiscreteDistribution, uniformDiscreteDistribution, bernoulliDistribution, and diracDistribution.

double discreteDistribution::distanceL1 ( discreteDistribution d)
Parameters
d
Returns
double
double discreteDistribution::distanceL1 ( discreteDistribution d)

Computes the L1 distance between this distribution and another one. In case of incompatible or infinite sizes, a negative number is returned.

Parameters
d
Returns
double
Author
Alain Jean-Marie
Parameters
dthe second distribution
Returns
the distance
double discreteDistribution::distanceL2 ( discreteDistribution d)
Parameters
d
Returns
double
double discreteDistribution::distanceL2 ( discreteDistribution d)

Computes the L2 distance between two distributions. In case of incompatible or infinite sizes, a negative number is returned.

Parameters
d
Returns
double
Author
Alain Jean-Marie
Parameters
dthe second distribution
Returns
the distance
double discreteDistribution::distanceLinfinity ( discreteDistribution d)
Parameters
d
Returns
double
double discreteDistribution::distanceLinfinity ( discreteDistribution d)

Computes the L-infinity distance between two distributions. In case of incompatible or infinite sizes, a negative number is returned.

Parameters
d
Returns
double
Author
Alain Jean-Marie
Parameters
dthe second distribution
Returns
the distance
double discreteDistribution::dLaplace ( double  s)
virtual

computing the derivative of the Laplace transform at real points

Parameters
sthe value at which to compute
Returns
the value of the derivative of the Laplace transform

Implements Distribution.

Reimplemented in uniformDiscreteDistribution.

double discreteDistribution::dLaplace ( double  s)
virtual

computing the derivative of the Laplace transform at real points

Computation of the derivative of the Laplace transform at some real point s.

Parameters
sthe value at which to compute
Returns
the value of the derivative of the Laplace transform
Author
Alain Jean-Marie
Parameters
svalue at which the derivative is computed
Returns
d LT(s)/ds

Implements Distribution.

Reimplemented in uniformDiscreteDistribution, uniformDiscreteDistribution, bernoulliDistribution, and diracDistribution.

double discreteDistribution::getProba ( int  i)

Read accessor for the probas. This is a pseudo-accessor since it performs additional checks.

Author
Alain Jean-Marie
Parameters
ithe index of the entry
Returns
the probability of entry i, or 0 if the index is out of range
double discreteDistribution::getProba ( int  i)

Read accessor for the probas. This is a pseudo-accessor since it performs additional checks.

Author
Alain Jean-Marie
Parameters
ithe index of the entry
Returns
the probability of entry i, or 0 if the index is out of range
double discreteDistribution::getValue ( int  i)

Read accessor for the values. This is a pseudo-accessor since it performs additional checks.

Author
Alain Jean-Marie
Parameters
ithe index of the entry
Returns
the value of entry i, or 0 if the index is out of range
double discreteDistribution::getValue ( int  i)

Read accessor for the values. This is a pseudo-accessor since it performs additional checks.

Author
Alain Jean-Marie
Parameters
ithe index of the entry
Returns
the value of entry i, or 0 if the index is out of range
bool discreteDistribution::hasMoment ( int  order)
virtual

Test of existence of a moment. These distributions always have one.

Author
Alain Jean-Marie
Parameters
orderorder of the moment
Returns
true

Implements Distribution.

Reimplemented in uniformDiscreteDistribution.

bool discreteDistribution::hasMoment ( int  order)
virtual

Test of existence of a moment. These distributions always have one.

Author
Alain Jean-Marie
Parameters
orderorder of the moment
Returns
true

Implements Distribution.

Reimplemented in uniformDiscreteDistribution, uniformDiscreteDistribution, bernoulliDistribution, and diracDistribution.

double discreteDistribution::laplace ( double  s)
virtual

computing the Laplace transform of the distribution at real point

Parameters
sthe value at which to compute
Returns
the value of the Laplace transform

Implements Distribution.

Reimplemented in uniformDiscreteDistribution.

double discreteDistribution::laplace ( double  s)
virtual

computing the Laplace transform of the distribution at real point

Computation of the Laplace transform at some real point s.

Parameters
sthe value at which to compute
Returns
the value of the Laplace transform
Author
Alain Jean-Marie
Parameters
svalue at which the derivative is computed
Returns
LT(s)

Implements Distribution.

Reimplemented in uniformDiscreteDistribution, uniformDiscreteDistribution, bernoulliDistribution, and diracDistribution.

double discreteDistribution::mean ( )
inlinevirtual

Calculation of the mean. Returns the value since it is pre-computed.

Author
Alain Jean-Marie
Returns
the mathematical expectation of the distribution

Implements Distribution.

Reimplemented in uniformDiscreteDistribution.

double discreteDistribution::mean ( )
inlinevirtual

Calculation of the mean. Returns the value since it is pre-computed.

Author
Alain Jean-Marie
Returns
the mathematical expectation of the distribution

Implements Distribution.

Reimplemented in uniformDiscreteDistribution, bernoulliDistribution, uniformDiscreteDistribution, and diracDistribution.

double discreteDistribution::moment ( int  order)
virtual

Computing the moments of the distribution.

Parameters
orderthe order of the moment to be computed
Returns
the moment

Implements Distribution.

Reimplemented in uniformDiscreteDistribution.

double discreteDistribution::moment ( int  order)
virtual

Computing the moments of the distribution.

Parameters
orderthe order of the moment to be computed
Returns
the moment

Implements Distribution.

Reimplemented in uniformDiscreteDistribution, bernoulliDistribution, uniformDiscreteDistribution, and diracDistribution.

int discreteDistribution::nbVals ( )
inline

Read accessor to the number of values in the distribution.

Returns
the number of values _nbVals
int discreteDistribution::nbVals ( )
inline

Read accessor to the number of values in the distribution.

Returns
the number of values _nbVals
double discreteDistribution::rate ( )
virtual

Calculation of the rate, which is the inverse of the mean. If the mean is 0, the value INFINITE_RATE is returned.

Author
Alain Jean-Marie
Returns
the rate

Implements Distribution.

Reimplemented in uniformDiscreteDistribution.

double discreteDistribution::rate ( )
virtual

Calculation of the rate, which is the inverse of the mean. If the mean is 0, the value INFINITE_RATE is returned.

Author
Alain Jean-Marie
Returns
the rate

Implements Distribution.

Reimplemented in uniformDiscreteDistribution, bernoulliDistribution, uniformDiscreteDistribution, and diracDistribution.

discreteDistribution* discreteDistribution::rescale ( double  factor)
virtual

rescaling a distribution by some real factor. Not all distributions allow this for any real factor. If the operation fails, or if the factor is 1.0, a copy of the distribution should be returned (not by using the copy() function).

See also
copy()
Parameters
factorthe real factor to be used
Returns
a new distribution object

Implements Distribution.

Reimplemented in uniformDiscreteDistribution.

discreteDistribution * discreteDistribution::rescale ( double  factor)
virtual

rescaling a distribution by some real factor. Not all distributions allow this for any real factor. If the operation fails, or if the factor is 1.0, a copy of the distribution should be returned (not by using the copy() function).

Rescaling the law X by some real factor f.

See also
copy()
Parameters
factorthe real factor to be used
Returns
a new distribution object
Author
Alain Jean-Marie
Parameters
factorthe factor f
Returns
the law f*X

Implements Distribution.

Reimplemented in uniformDiscreteDistribution, uniformDiscreteDistribution, bernoulliDistribution, and diracDistribution.

double discreteDistribution::sample ( )
virtual
Returns
double

Implements Distribution.

Reimplemented in uniformDiscreteDistribution.

double discreteDistribution::sample ( )
virtual

Sampling from the law This is the straightforward, non optimized, linear-time algorithm.

Returns
double
Author
Alain Jean-Marie
Returns
a copy of the law

Implements Distribution.

Reimplemented in uniformDiscreteDistribution, uniformDiscreteDistribution, bernoulliDistribution, and diracDistribution.

bool discreteDistribution::setProba ( int  i,
double  v 
)

Write accessor for the probas. This is a pseudo-accessor since it performs additional checks.

Author
Alain Jean-Marie
Parameters
ithe index of the entry
vthe value to be given to the entry
Returns
true if ok, or false if the index is out of range
bool discreteDistribution::setProba ( int  i,
double  v 
)

Write accessor for the probas. This is a pseudo-accessor since it performs additional checks.

Author
Alain Jean-Marie
Parameters
ithe index of the entry
vthe value to be given to the entry
Returns
true if ok, or false if the index is out of range
std::string discreteDistribution::toString ( )
virtual
Returns
std::string

Implements Distribution.

Reimplemented in uniformDiscreteDistribution.

std::string discreteDistribution::toString ( )
virtual

Printing a representation of the law into a string.

Returns
std::string
Author
Alain Jean-Marie
Returns
a string

Implements Distribution.

Reimplemented in uniformDiscreteDistribution, uniformDiscreteDistribution, bernoulliDistribution, and diracDistribution.

void discreteDistribution::write ( FILE *  out,
int  mode 
)
virtual
Parameters
out
mode

Implements Distribution.

Reimplemented in uniformDiscreteDistribution.

void discreteDistribution::write ( FILE *  out,
int  mode 
)
virtual

Printing a representation of the law.

Parameters
out
mode
Author
Alain Jean-Marie
Parameters
outfile descriptor of the output stream
moderepresentation for the output

Implements Distribution.

Reimplemented in uniformDiscreteDistribution, uniformDiscreteDistribution, bernoulliDistribution, and diracDistribution.

Member Data Documentation

int discreteDistribution::_nbVals
protected

number of values in the distribution

double * discreteDistribution::_probas
protected

table of probabilities

double * discreteDistribution::_values
protected

table of values


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