Marmote Core
The project aims at realizing the prototype of a software environment dedicated to modeling with Markov chains.
discreteDistribution.h
1 /* Marmote is free software: you can redistribute it and/or modify
2 it under the terms of the GNU General Public License as published by
3 the Free Software Foundation, either version 3 of the License, or
4 (at your option) any later version.
5 
6 Marmote is distributed in the hope that it will be useful,
7 but WITHOUT ANY WARRANTY; without even the implied warranty of
8 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 GNU General Public License for more details.
10 
11 You should have received a copy of the GNU General Public License
12 along with Marmote. If not, see <http://www.gnu.org/licenses/>.
13 
14 Copyright 2015 Alain Jean-Marie, Jean-Michel Fourneau, Jean-Marc Vincent, Issam Rabhi */
15 
16 #ifndef DISCRETEDISTRIBUTION_H
17 #define DISCRETEDISTRIBUTION_H
18 
19 #include "Distribution.h"
20 
25 class discreteDistribution : public virtual Distribution {
26 
27  public:
28  // constructors
44  discreteDistribution( int sz, double* vals, double* probas );
45 
57  discreteDistribution( int sz, char *name );
58 
59  protected:
60  // partial constructors
69  discreteDistribution( int sz );
70 
71 public:
72  // destructor
80 
81 protected:
82  // specific variables
83  int _nbVals;
84  double* _values;
85  double* _probas;
87 public:
88  // accessors and such
89 
97  double getProbaByIndex(int i);
98 
106  double getProba(double value);
107 
115  double getValue(int i);
116 
122  int nbVals() { return _nbVals; };
123 
132  bool setProba(int i, double v);
133 
134 public:
135  // probabilistic member functions
136 
142  double mean() { return _mean; };
143 
150  double rate(); // inverse of the mean
154  double moment( int order );
158  double laplace( double s ); // Laplace transform at real points
162  double dLaplace( double s ); // derivative of the Laplace transform
169  double cdf( double x );
176  bool hasMoment( int order );
177 
181  discreteDistribution *rescale( double factor );
186 
192  double sample();
193 
201  double distanceL2( discreteDistribution* d );
209  double distanceL1(discreteDistribution* d);
217 
218  public:
224  std::string toString();
231  void write( FILE *out, int mode );
232 
233 };
234 
235 #endif // DISCRETEDISTRIBUTION_H
void write(FILE *out, int mode)
Printing a representation of the law.
Definition: discreteDistribution.cpp:269
bool hasMoment(int order)
Test of existence of a moment. These distributions always have one.
Definition: discreteDistribution.cpp:203
double * _values
Definition: discreteDistribution.h:84
double distanceL2(discreteDistribution *d)
Computes the L2 distance between two distributions. In case of incompatible or infinite sizes...
Definition: discreteDistribution.cpp:433
double distanceLinfinity(discreteDistribution *d)
Computes the L-infinity distance between two distributions. In case of incompatible or infinite sizes...
Definition: discreteDistribution.cpp:462
int _nbVals
Definition: discreteDistribution.h:83
std::string name()
Read accessor to the type name of the distribution.
Definition: Distribution.h:66
double mean()
Calculation of the mean. Returns the value since it is pre-computed.
Definition: discreteDistribution.h:142
A class for representing probability distributions.
Definition: Distribution.h:44
discreteDistribution * copy()
copying a distribution. Typically implemented as rescale(1.0).
Definition: discreteDistribution.cpp:353
int nbVals()
Read accessor to the number of values in the distribution.
Definition: discreteDistribution.h:122
std::string toString()
Printing a representation of the law into a string.
Definition: discreteDistribution.cpp:307
bool setProba(int i, double v)
Write accessor for the probas. This is a pseudo-accessor since it performs additional checks...
Definition: discreteDistribution.cpp:155
discreteDistribution * rescale(double factor)
rescaling a distribution by some real factor. Not all distributions allow this for any real factor...
Definition: discreteDistribution.cpp:332
double getValue(int i)
Read accessor for the values. This is a pseudo-accessor since it performs additional checks...
Definition: discreteDistribution.cpp:137
virtual double distanceL1(Distribution *d)
Computing generally the L1 distance between distributions.
Definition: Distribution.cpp:53
double getProbaByIndex(int i)
Read accessor for the elements of the probas array. This is a pseudo-accessor since it performs addit...
Definition: discreteDistribution.cpp:105
~discreteDistribution()
Destructor for a general discrete distribution. The convention is that internal arrays for values and...
Definition: discreteDistribution.cpp:96
double getProba(double value)
Computes the probability of a particular value. The tolerance VALUE_TOLERANCE is applied to match val...
Definition: discreteDistribution.cpp:123
double laplace(double s)
computing the Laplace transform of the distribution at real point
Definition: discreteDistribution.cpp:214
double cdf(double x)
Computation of the cumulative density function at some real point x.
Definition: discreteDistribution.cpp:250
double moment(int order)
Computing the moments of the distribution.
Definition: discreteDistribution.cpp:190
double sample()
Sampling from the law This is the straightforward, non optimized, linear-time algorithm.
Definition: discreteDistribution.cpp:366
double distanceL1(discreteDistribution *d)
Computes the L1 distance between this distribution and another one. In case of incompatible or infini...
Definition: discreteDistribution.cpp:386
double dLaplace(double s)
computing the derivative of the Laplace transform at real points
Definition: discreteDistribution.cpp:232
double _mean
Definition: Distribution.h:240
double * _probas
Definition: discreteDistribution.h:85
double rate()
Calculation of the rate, which is the inverse of the mean. If the mean is 0, the value INFINITE_RATE ...
Definition: discreteDistribution.cpp:174
The general discrete distribution with finite support.
Definition: discreteDistribution.h:25