bpp-core3  3.0.0
BetaDiscreteDistribution.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
5 #ifndef BPP_NUMERIC_PROB_BETADISCRETEDISTRIBUTION_H
6 #define BPP_NUMERIC_PROB_BETADISCRETEDISTRIBUTION_H
7 
8 
9 #include "../Random/RandomTools.h"
11 
12 namespace bpp
13 {
29 {
30 private:
31  double alpha_, beta_;
32 
33  /* for computation economy */
34 
35  double diffln_;
36 
37 public:
46  BetaDiscreteDistribution(size_t n, double alpha = 1, double beta = 1, short discretization = DISCRETIZATION_EQUAL_PROB_WHEN_POSSIBLE);
47 
49 
51 
52  BetaDiscreteDistribution* clone() const override { return new BetaDiscreteDistribution(*this); }
53 
54 public:
55  std::string getName() const override { return "Beta";}
56 
57  void fireParameterChanged(const ParameterList& parameters) override;
58 
59  double randC() const override
60  {
61  double x = RandomTools::randBeta(getParameterValue("alpha"),
62  getParameterValue("beta"));
63  while (!intMinMax_->isCorrect(x))
65  getParameterValue("beta"));
66  return x;
67  }
68 
69  double qProb(double x) const override;
70 
71  double pProb(double x) const override;
72 
73  double Expectation(double a) const override;
74 };
75 } // end of namespace bpp.
76 #endif // BPP_NUMERIC_PROB_BETADISCRETEDISTRIBUTION_H
Partial implementation of the DiscreteDistribution interface.
BetaDiscreteDistribution * clone() const override
Create a copy of this object and send a pointer to it.
static double randBeta(double alpha, double beta)
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...
Discretized Beta distribution with parameters alpha and beta, on a given interval. On default, the interval is , but it can be restricted.
BetaDiscreteDistribution & operator=(const BetaDiscreteDistribution &)=default
double getParameterValue(const std::string &name) const override
Get the value for parameter of name 'name'.
The parameter list object.
Definition: ParameterList.h:27
std::shared_ptr< IntervalConstraint > intMinMax_
the interval where the distribution is defined/restricted.
void fireParameterChanged(const ParameterList &parameters) override
Notify the class when one or several parameters have changed.
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 .
std::string getName() const override
Get the name of the distribution.
double randC() const override
Draw a random number from the continuous version of this distribution, if it exists.