bpp-core3  3.0.0
ExponentialDiscreteDistribution.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_EXPONENTIALDISCRETEDISTRIBUTION_H
6 #define BPP_NUMERIC_PROB_EXPONENTIALDISCRETEDISTRIBUTION_H
7 
8 
9 #include "../Constraints.h"
10 #include "../Random/RandomTools.h"
12 
13 namespace bpp
14 {
22 {
23 protected:
24  double lambda_;
25 
26 public:
36  ExponentialDiscreteDistribution(size_t n, double lambda = 1.);
37 
40  lambda_(dist.lambda_)
41  {}
42 
44  {
46  lambda_ = dist.lambda_;
47  return *this;
48  }
49 
51 
53 
54 public:
55  std::string getName() const {return "Exponential";}
56 
57  void fireParameterChanged(const ParameterList& parameters);
58 
59  double randC() const
60  {
61  double x = RandomTools::randExponential(1. / getParameterValue("lambda"));
62  while (!intMinMax_->isCorrect(x))
64 
65  return x;
66  }
67 
68  double pProb(double x) const
69  {
70  return 1. - exp(-lambda_ * x);
71  }
72 
73  double qProb(double x) const
74  {
75  return -log(1. - x) / lambda_;
76  }
77 
78  double Expectation(double a) const
79  {
80  return 1. / lambda_ - exp(-a * lambda_) * (a + 1. / lambda_);
81  }
82 };
83 } // end of namespace bpp.
84 #endif // BPP_NUMERIC_PROB_EXPONENTIALDISCRETEDISTRIBUTION_H
Partial implementation of the DiscreteDistribution interface.
ExponentialDiscreteDistribution * clone() const
Create a copy of this object and send a pointer to it.
std::string getName() const
Get the name of the distribution.
static double randExponential(double mean)
Definition: RandomTools.h:154
Discretized Exponential distribution.
double getParameterValue(const std::string &name) const override
Get the value for parameter of name 'name'.
The parameter list object.
Definition: ParameterList.h:27
double Expectation(double a) const
Return a primitive function used for the expectation of the continuous version of the distribution...
double randC() const
Draw a random number from the continuous version of this distribution, if it exists.
AbstractDiscreteDistribution & operator=(const AbstractDiscreteDistribution &adde)
double pProb(double x) const
Return the cumulative quantile of the continuous version of the distribution, ie .
void fireParameterChanged(const ParameterList &parameters)
Notify the class when one or several parameters have changed.
std::shared_ptr< IntervalConstraint > intMinMax_
the interval where the distribution is defined/restricted.
ExponentialDiscreteDistribution(const ExponentialDiscreteDistribution &dist)
ExponentialDiscreteDistribution & operator=(const ExponentialDiscreteDistribution &dist)
double qProb(double x) const
Return the quantile of the continuous version of the distribution, ie y such that ...
ExponentialDiscreteDistribution(size_t n, double lambda=1.)
Build a new discretized exponential distribution.