bpp-core3  3.0.0
GammaDiscreteDistribution.cpp
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
5 #include "../../Utils/MapTools.h"
6 #include "../NumConstants.h"
7 #include "../Random/RandomTools.h"
9 
10 using namespace bpp;
11 
12 // From the STL:
13 #include <cmath>
14 
15 using namespace std;
16 
19 GammaDiscreteDistribution::GammaDiscreteDistribution(size_t n, double alpha, double beta, double minimumAlpha, double minimumBeta, bool paramOffset, double offset) :
20  AbstractDiscreteDistribution(n, "Gamma."),
21  alpha_(alpha),
22  beta_(beta),
23  offset_(offset),
24  ga1_(1)
25 {
26  // We use a lower bound of 0.0001 for alpha and beta to prohibe errors due to computer
27  // floating precision: if alpha is quite low (gamma -> constant), some classes
28  // may have the same category value, leading to a classe number lower than expected.
29  // NB: if this is the case, then a warning is shown. This may happen in optimization
30  // algorithms.
31 
32  if (n<=1)
33  throw Exception("At least 2 classes for Gamma discrete distribution.");
34 
35  addParameter_(new Parameter("Gamma.alpha", alpha, std::make_shared<IntervalConstraint>(1, minimumAlpha, true)));
36  addParameter_(new Parameter("Gamma.beta", beta, std::make_shared<IntervalConstraint>(1, minimumBeta, true)));
37  if (paramOffset)
38  addParameter_(new Parameter("Gamma.offset", offset));
39 
41 
42  intMinMax_->setLowerBound(offset_, true);
43  discretize();
44 }
45 
48  alpha_(gdd.alpha_),
49  beta_(gdd.beta_),
50  offset_(gdd.offset_),
51  ga1_(gdd.ga1_)
52 {}
53 
55 {
57  alpha_ = gdd.alpha_;
58  beta_ = gdd.beta_;
59  offset_ = gdd.offset_;
60  ga1_ = gdd.ga1_;
61 
62  return *this;
63 }
64 
66 
67 /******************************************************************************/
68 
70 {
72  alpha_ = getParameterValue("alpha");
73  beta_ = getParameterValue("beta");
74  if (hasParameter("offset"))
75  offset_ = getParameterValue("offset");
77 
78  discretize();
79 }
80 
81 /******************************************************************************/
82 
83 // Adapted from function DiscreteGamma of Yang
84 
85 double GammaDiscreteDistribution::qProb(double x) const
86 {
88 }
89 
90 
91 double GammaDiscreteDistribution::pProb(double x) const
92 {
94 }
95 
97 {
99 }
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.
STL namespace.
This class is designed to facilitate the manipulation of parameters.
Definition: Parameter.h:97
void addParameter_(Parameter *parameter)
double getParameterValue(const std::string &name) const override
Get the value for parameter of name &#39;name&#39;.
The parameter list object.
Definition: ParameterList.h:27
virtual void fireParameterChanged(const ParameterList &parameters)
Notify the class when one or several parameters have changed.
AbstractDiscreteDistribution & operator=(const AbstractDiscreteDistribution &adde)
std::shared_ptr< IntervalConstraint > intMinMax_
the interval where the distribution is defined/restricted.
GammaDiscreteDistribution & operator=(const GammaDiscreteDistribution &)
GammaDiscreteDistribution(size_t n, double alpha=1., double beta=1., double minimumAlpha=0.05, double minimumBeta=0.05, bool paramOffset=false, double offset=0)
Build a new discretized gamma distribution.
bool hasParameter(const std::string &name) const override
Tell if there is a parameter with specified name.
virtual void discretize()
Discretizes the distribution in equiprobable classes.
static double pGamma(double x, double alpha, double beta)
cumulative probability function.
Definition: RandomTools.h:545
Exception base class. Overload exception constructor (to control the exceptions mechanism). Destructor is already virtual (from std::exception)
Definition: Exceptions.h:20
static double lnGamma(double alpha)
Computes given .
Definition: RandomTools.h:472
Discretized Gamma distribution with an offset.
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:530
double qProb(double x) const
Return the quantile of the continuous version of the distribution, ie y such that ...
void fireParameterChanged(const ParameterList &parameters)
Notify the class when one or several parameters have changed.