bpp-core3  3.0.0
BetaDiscreteDistribution.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 BetaDiscreteDistribution::BetaDiscreteDistribution(size_t n, double alpha, double beta, short discretization) :
20  AbstractDiscreteDistribution(n, NumConstants::VERY_TINY(), "Beta.", discretization),
21  alpha_(alpha),
22  beta_(beta),
23  diffln_(0)
24 {
25  addParameter_(new Parameter("Beta.alpha", alpha, std::make_shared<IntervalConstraint>(true, 0.0001, true)));
26 
27  // For precision issues, beta cannot be too low
28  addParameter_(new Parameter("Beta.beta", beta, std::make_shared<IntervalConstraint>(true, 0.0001, true)));
29  intMinMax_->setLowerBound(0, true);
30  intMinMax_->setUpperBound(1, true);
31 
33  discretize();
34 }
35 
36 /******************************************************************************/
37 
39 {
41  alpha_ = getParameterValue("alpha");
42  beta_ = getParameterValue("beta");
43 
44  if (alpha_ <= 1 && intMinMax_->getLowerBound() == 0)
45  intMinMax_->setLowerBound(precision(), false);
46 
47  if (beta_ <= 1 && intMinMax_->getUpperBound() == 1)
48  intMinMax_->setUpperBound(1 - precision(), false);
49 
51  discretize();
52 }
53 
54 /******************************************************************************/
55 
56 double BetaDiscreteDistribution::qProb(double x) const
57 {
58  return RandomTools::qBeta(x, alpha_, beta_);
59 }
60 
61 double BetaDiscreteDistribution::pProb(double x) const
62 {
63  return RandomTools::pBeta(x, alpha_, beta_);
64 }
65 
67 {
68  return RandomTools::pBeta(a, alpha_ + 1, beta_) * diffln_;
69 }
Partial implementation of the DiscreteDistribution interface.
this static class contains several useful constant values.
Definition: NumConstants.h:20
BetaDiscreteDistribution(size_t n, double alpha=1, double beta=1, short discretization=DISCRETIZATION_EQUAL_PROB_WHEN_POSSIBLE)
Build a new discretized beta distribution.
double Expectation(double a) const override
Return a primitive function used for the expectation of the continuous version of the distribution...
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.
static double qBeta(double prob, double alpha, double beta)
The Beta quantile function.
std::shared_ptr< IntervalConstraint > intMinMax_
the interval where the distribution is defined/restricted.
double getLowerBound() const
methods about the range of the definition
virtual void discretize()
Discretizes the distribution in equiprobable classes.
void fireParameterChanged(const ParameterList &parameters) override
Notify the class when one or several parameters have changed.
static double pBeta(double x, double alpha, double beta)
Definition: RandomTools.h:615
double qProb(double x) const override
Return the quantile of the continuous version of the distribution, ie y such that ...
double pProb(double x) const override
Return the cumulative quantile of the continuous version of the distribution, ie .
static double lnBeta(double alpha, double beta)
Computes given and .