bpp-core  2.2.0
GammaDiscreteDistribution.cpp
Go to the documentation of this file.
1 //
2 // File: GammaDiscreteDistribution.cpp
3 // Created by: Julien Dutheil
4 // Created on: Sun Oct 26 20:36:12 2003
5 //
6 
7 /*
8  Copyright or © or Copr. CNRS, (November 17, 2004)
9 
10  This software is a computer program whose purpose is to provide classes
11  for numerical calculus.
12 
13  This software is governed by the CeCILL license under French law and
14  abiding by the rules of distribution of free software. You can use,
15  modify and/ or redistribute the software under the terms of the CeCILL
16  license as circulated by CEA, CNRS and INRIA at the following URL
17  "http://www.cecill.info".
18 
19  As a counterpart to the access to the source code and rights to copy,
20  modify and redistribute granted by the license, users are provided only
21  with a limited warranty and the software's author, the holder of the
22  economic rights, and the successive licensors have only limited
23  liability.
24 
25  In this respect, the user's attention is drawn to the risks associated
26  with loading, using, modifying and/or developing or reproducing the
27  software by the user in light of its specific status of free software,
28  that may mean that it is complicated to manipulate, and that also
29  therefore means that it is reserved for developers and experienced
30  professionals having in-depth computer knowledge. Users are therefore
31  encouraged to load and test the software's suitability as regards their
32  requirements in conditions enabling the security of their systems and/or
33  data to be ensured and, more generally, to use and operate it in the
34  same conditions as regards security.
35 
36  The fact that you are presently reading this means that you have had
37  knowledge of the CeCILL license and that you accept its terms.
38  */
39 
41 #include "../Random/RandomTools.h"
42 #include "../NumConstants.h"
43 #include "../../Utils/MapTools.h"
44 
45 using namespace bpp;
46 
47 // From the STL:
48 #include <cmath>
49 
50 using namespace std;
51 
54 GammaDiscreteDistribution::GammaDiscreteDistribution(size_t n, double alpha, double beta, double minimumAlpha, double minimumBeta) :
56  AbstractDiscreteDistribution(n, "Gamma."),
57  alpha_(alpha),
58  beta_(beta),
59  ga1_(1)
60 {
61  // We use a lower bound of 0.0001 for alpha and beta to prohibe errors due to computer
62  // floating precision: if alpha is quite low (gamma -> constant), some classes
63  // may have the same category value, leading to a classe number lower than expected.
64  // NB: if this is the case, then a warning is shown. This may happen in optimization
65  // algorithms.
66  addParameter_(new Parameter("Gamma.alpha", alpha, new IntervalConstraint(1, minimumAlpha, true), true));
67  addParameter_(new Parameter("Gamma.beta", beta, new IntervalConstraint(1, minimumBeta, true), true));
69 
70  intMinMax_.setLowerBound(0, true);
71  discretize();
72 }
73 
77  alpha_(gdd.alpha_),
78  beta_(gdd.beta_),
79  ga1_(gdd.ga1_)
80 {
81 }
82 
84 {
87  alpha_=gdd.alpha_;
88  beta_=gdd.beta_;
89  ga1_=gdd.ga1_;
90 
91  return *this;
92 }
93 
95 
96 /******************************************************************************/
97 
99 {
101  alpha_ = getParameterValue("alpha");
102  beta_ = getParameterValue("beta");
104 
105  discretize();
106 }
107 
108 /******************************************************************************/
109 
110 // Adapted from function DiscreteGamma of Yang
111 
112 double GammaDiscreteDistribution::qProb(double x) const
113 {
114  return RandomTools::qGamma(x, alpha_, beta_);
115 }
116 
117 
118 double GammaDiscreteDistribution::pProb(double x) const
119 {
120  return RandomTools::pGamma(x, alpha_, beta_);
121 }
122 
124 {
125  return RandomTools::pGamma(a, alpha_ + 1, beta_) / beta_ * ga1_;
126 }
127 
void fireParameterChanged(const ParameterList &parameters)
Notify the class when one or several parameters have changed.
double Expectation(double a) const
Return a primitive function used for the expectation of the continuous version of the distribution...
Partial implementation of the DiscreteDistribution interface.
An interval, either bounded or not, which can also have infinite bounds.
Definition: Constraints.h:135
This class allows to perform a correspondence analysis.
void setLowerBound(double lowerBound, bool strict)
Definition: Constraints.h:210
GammaDiscreteDistribution(size_t n, double alpha=1., double beta=1., double minimumAlpha=0.05, double minimumBeta=0.05)
Build a new discretized gamma distribution.
STL namespace.
This class is designed to facilitate the manipulation of parameters.
Definition: Parameter.h:135
void addParameter_(Parameter *parameter)
The parameter list object.
Definition: ParameterList.h:61
AbstractDiscreteDistribution & operator=(const AbstractDiscreteDistribution &adde)
A partial implementation of the Parametrizable interface.
GammaDiscreteDistribution & operator=(const GammaDiscreteDistribution &)
static double lnGamma(double alpha)
Computes given .
virtual void discretize()
Discretizes the distribution in equiprobable classes.
AbstractParameterAliasable & operator=(const AbstractParameterAliasable &ap)
static double pGamma(double x, double alpha, double beta)
cumulative probability function.
Definition: RandomTools.h:459
Discretized Gamma distribution.
double pProb(double x) const
Return the cumulative quantile of the continuous version of the distribution, ie .
static double qGamma(double prob, double alpha, double beta)
The Gamma quantile function.
Definition: RandomTools.h:444
double qProb(double x) const
Return the quantile of the continuous version of the distribution, ie y such that ...
IntervalConstraint intMinMax_
the interval where the distribution is defined/restricted.
double getParameterValue(const std::string &name) const
Get the value for parameter of name &#39;name&#39;.
void fireParameterChanged(const ParameterList &parameters)
Notify the class when one or several parameters have changed.