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
89 
97  double getProba(int i);
98 
106  double getValue(int i);
107 
113  int nbVals() { return _nbVals; };
114 
123  bool setProba(int i, double v);
124 
125 public:
126  // probabilistic member functions
127 
133  double mean() { return _mean; };
134 
141  double rate(); // inverse of the mean
145  double moment( int order );
149  double laplace( double s ); // Laplace transform at real points
153  double dLaplace( double s ); // derivative of the Laplace transform
160  double cdf( double x );
167  bool hasMoment( int order );
168 
172  discreteDistribution *rescale( double factor );
177 
183  double sample();
184 
192  double distanceL2( discreteDistribution* d );
200  double distanceL1(discreteDistribution* d);
208 
209  public:
215  std::string toString();
222  void write( FILE *out, int mode );
223 
224 };
225 
226 #endif // DISCRETEDISTRIBUTION_H
void write(FILE *out, int mode)
Printing a representation of the law.
Definition: discreteDistribution.cpp:255
double * _values
Definition: discreteDistribution.h:84
bool hasMoment(int order)
Test of existence of a moment. These distributions always have one.
Definition: discreteDistribution.cpp:189
double distanceL2(discreteDistribution *d)
Computes the L2 distance between two distributions. In case of incompatible or infinite sizes...
Definition: discreteDistribution.cpp:419
double distanceLinfinity(discreteDistribution *d)
Computes the L-infinity distance between two distributions. In case of incompatible or infinite sizes...
Definition: discreteDistribution.cpp:448
int _nbVals
Definition: discreteDistribution.h:83
std::string name()
Read accessor to the type name of the distribution.
Definition: Distribution.h:66
double * _probas
Definition: discreteDistribution.h:85
double mean()
Calculation of the mean. Returns the value since it is pre-computed.
Definition: discreteDistribution.h:133
A class for representing probability distributions.
Definition: Distribution.h:44
discreteDistribution * copy()
copying a distribution. Typically implemented as rescale(1.0).
Definition: discreteDistribution.cpp:339
int nbVals()
Read accessor to the number of values in the distribution.
Definition: discreteDistribution.h:113
std::string toString()
Printing a representation of the law into a string.
Definition: discreteDistribution.cpp:293
bool setProba(int i, double v)
Write accessor for the probas. This is a pseudo-accessor since it performs additional checks...
Definition: discreteDistribution.cpp:141
discreteDistribution * rescale(double factor)
rescaling a distribution by some real factor. Not all distributions allow this for any real factor...
Definition: discreteDistribution.cpp:318
double getValue(int i)
Read accessor for the values. This is a pseudo-accessor since it performs additional checks...
Definition: discreteDistribution.cpp:123
virtual double distanceL1(Distribution *d)
Computing generally the L1 distance between distributions.
Definition: Distribution.cpp:51
~discreteDistribution()
Destructor for a general discrete distribution. The convention is that internal arrays for values and...
Definition: discreteDistribution.cpp:96
double laplace(double s)
computing the Laplace transform of the distribution at real point
Definition: discreteDistribution.cpp:200
double cdf(double x)
Computation of the cumulative density function at some real point x.
Definition: discreteDistribution.cpp:236
double moment(int order)
Computing the moments of the distribution.
Definition: discreteDistribution.cpp:176
double sample()
Sampling from the law This is the straightforward, non optimized, linear-time algorithm.
Definition: discreteDistribution.cpp:352
double getProba(int i)
Read accessor for the probas. This is a pseudo-accessor since it performs additional checks...
Definition: discreteDistribution.cpp:105
double distanceL1(discreteDistribution *d)
Computes the L1 distance between this distribution and another one. In case of incompatible or infini...
Definition: discreteDistribution.cpp:372
double dLaplace(double s)
computing the derivative of the Laplace transform at real points
Definition: discreteDistribution.cpp:218
double _mean
Definition: Distribution.h:239
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:160
The general discrete distribution with finite support.
Definition: discreteDistribution.h:25