Marmote Core
The project aims at realizing the prototype of a software environment dedicated to modeling with Markov chains.
Distribution.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 DISTRIBUTION_H
17 #define DISTRIBUTION_H
18 
19 #include <math.h>
20 #include <stdio.h>
21 #include <string>
22 #include <vector>
23 #include "../marmoteConstants.h"
24 
25 // Definition of +oo for durations and rates
26 #define INFINITE_DURATION HUGE_VAL
27 #define INFINITE_RATE HUGE_VAL
28 
29 // Definitions for printing styles
30 #define NO_PRINT_MODE 0
31 #define DEFAULT_PRINT_MODE 1
32 #define NORMAL_PRINT_MODE 1
33 #define QNAP_PRINT_MODE 2
34 #define PROSIT_PRINT_MODE 3
35 #define MMPP_PRINT_MODE 4
36 #define PNED_PRINT_MODE 5
37 #define MAPLE_PRINT_MODE 6
38 
39 // Definition of the class
44 class Distribution {
45 
46  protected:
47  std::string _name;
49  protected:
50  // Distribution();
51  // Distribution( Distribution d ); // copy
52 
53  public:
57  virtual ~Distribution() {};
58 
59 public:
60  // accessors
66  std::string name() { return _name; };
67 
68  public:
69  // probabilistic member functions
75  virtual double mean() = 0;
81  virtual double rate() = 0;
88  virtual double moment( int order ) = 0;
97  double variance();
104  virtual double laplace( double s ) = 0;
111  virtual double dLaplace( double s ) = 0;
119  virtual double cdf( double x ) = 0;
129  double ccdf( double x ) { return 1.0 - cdf(x); };
136  virtual bool hasMoment( int order ) = 0;
137 
148  virtual Distribution* rescale( double factor ) = 0;
155  virtual Distribution* copy() = 0;
161  virtual double sample() = 0;
171  void iidSample( int n, double* s );
172 
179  virtual double distanceL1( Distribution* d );
180 
190  virtual bool hasProperty( std::string pro );
191  /* functions existing in the ERS package, not implemented yet
192  Law_Desc Parse_Law( char Nom, Liste_Reel Params,
193  Liste_Reel Params2, Law_List The_SubLaws );
194  int Parse_Law_From_Args ( char**, int, int, Law_Desc );
195  Law_List Append_Law( Law_List, Law_Desc New_Law );
196  */
197 
198  public:
199  // standard pseudo-random generators
206  static double u_0_1(void);
214  static double exponential(double mean);
215 
216  public:
222  virtual std::string toString() = 0;
230  virtual void write( FILE *out, int mode ) = 0;
231  // virtual void fprint() = 0;
236  void fprint() { write( stdout, NORMAL_PRINT_MODE ); }
237 
238  protected:
239  double _mean;
241 };
242 
243 #endif // DISTRIBUTION_H
virtual bool hasMoment(int order)=0
test for the existence of moments of any order
virtual double moment(int order)=0
Computing the moments of the distribution.
virtual double rate()=0
computing the "rate", defined as the inverse of the mean
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 be...
Definition: Distribution.cpp:31
std::string name()
Read accessor to the type name of the distribution.
Definition: Distribution.h:66
A class for representing probability distributions.
Definition: Distribution.h:44
double ccdf(double x)
computing the complementary cumulative distributon function (or tail) at some real point x...
Definition: Distribution.h:129
virtual std::string toString()=0
an utility to convert the distribution into a string.
virtual void write(FILE *out, int mode)=0
an utility to write the distribution to some file, according to some format.
double variance()
Computing the variance of the random variable: the second moment minus the square of the first moment...
Definition: Distribution.cpp:25
virtual Distribution * copy()=0
copying a distribution. Typically implemented as rescale(1.0).
std::string _name
Definition: Distribution.h:47
virtual double distanceL1(Distribution *d)
Computing generally the L1 distance between distributions.
Definition: Distribution.cpp:51
virtual ~Distribution()
Standard destructor.
Definition: Distribution.h:57
virtual double laplace(double s)=0
computing the Laplace transform of the distribution at real point
virtual bool hasProperty(std::string pro)
Property test function. Current properties are:
Definition: Distribution.cpp:100
virtual double mean()=0
computing the mathematical expectation or mean
static double exponential(double mean)
Definition: Distribution.cpp:45
virtual double cdf(double x)=0
computing the cumulative distribution function at some real point x. This is the probability that the...
virtual Distribution * rescale(double factor)=0
rescaling a distribution by some real factor. Not all distributions allow this for any real factor...
virtual double dLaplace(double s)=0
computing the derivative of the Laplace transform at real points
static double u_0_1(void)
Definition: Distribution.cpp:39
virtual double sample()=0
drawing a (pseudo)random value according to the distribution.
double _mean
Definition: Distribution.h:239
void fprint()
write on stdout with NORMAL_PRINT_MODE
Definition: Distribution.h:236