bpp-core3  3.0.0
UniformDiscreteDistribution.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_UNIFORMDISCRETEDISTRIBUTION_H
6 #define BPP_NUMERIC_PROB_UNIFORMDISCRETEDISTRIBUTION_H
7 
8 
9 #include "../Constraints.h"
10 #include "../Random/RandomTools.h"
12 
13 namespace bpp
14 {
23 {
24 private:
25  double min_;
26  double max_;
27 
28 public:
35  UniformDiscreteDistribution(unsigned int n, double min = 0., double max = 1.);
36 
38 
40 
42 
44 
45 public:
46  std::string getName() const {return "Uniform";}
47 
48  void fireParameterChanged(const ParameterList& parameters);
49 
50  double randC() const
51  {
53  while (!intMinMax_->isCorrect(x))
55  return x;
56  }
57 
58  double qProb(double x) const
59  {
60  return min_ + x * (max_ - min_);
61  }
62 
63  double pProb(double x) const
64  {
65  return (x <= min_) ? 0 : (x - min_) / (max_ - min_);
66  }
67 
68  double Expectation(double a) const
69  {
70  return (a <= min_) ? 0 : ((a >= max_) ? (max_ + min_) / 2 : (a * a - min_ * min_) / (max_ - min_) / 2);
71  }
72 };
73 } // end of namespace bpp.
74 #endif // BPP_NUMERIC_PROB_UNIFORMDISCRETEDISTRIBUTION_H
Partial implementation of the DiscreteDistribution interface.
double pProb(double x) const
Return the cumulative quantile of the continuous version of the distribution, ie .
double randC() const
Draw a random number from the continuous version of this distribution, if it exists.
UniformDiscreteDistribution & operator=(const UniformDiscreteDistribution &)
void fireParameterChanged(const ParameterList &parameters)
Notify the class when one or several parameters have changed.
The parameter list object.
Definition: ParameterList.h:27
UniformDiscreteDistribution * clone() const
Create a copy of this object and send a pointer to it.
std::shared_ptr< IntervalConstraint > intMinMax_
the interval where the distribution is defined/restricted.
static double giveRandomNumberBetweenZeroAndEntry(double entry)
Get a double random value (between 0 and specified range).
Definition: RandomTools.h:78
double qProb(double x) const
Return the quantile of the continuous version of the distribution, ie y such that ...
UniformDiscreteDistribution(unsigned int n, double min=0., double max=1.)
Build a new discretized uniform distribution.
Discretized Uniform distribution. All categories are equidistributed all along a given interval...
double Expectation(double a) const
Return a primitive function used for the expectation of the continuous version of the distribution...
std::string getName() const
Get the name of the distribution.