bpp-core3  3.0.0
TruncatedExponentialDiscreteDistribution.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_TRUNCATEDEXPONENTIALDISCRETEDISTRIBUTION_H
6 #define BPP_NUMERIC_PROB_TRUNCATEDEXPONENTIALDISCRETEDISTRIBUTION_H
7 
8 
9 #include "../Constraints.h"
10 #include "../Random/RandomTools.h"
12 
13 namespace bpp
14 {
27 {
28 protected:
29  double lambda_;
30 
31  double tp_;
32 
33  /*
34  * Probability of the condition given x < tp_.
35  *
36  */
37 
38  double cond_;
39 
40 public:
51  TruncatedExponentialDiscreteDistribution(size_t n, double lambda = 1., double truncationPoint = 10);
52 
55  lambda_(dist.lambda_),
56  tp_(dist.tp_),
57  cond_(dist.cond_)
58  {}
59 
61  {
63  lambda_ = dist.lambda_;
64  tp_ = dist.tp_;
65  cond_ = dist.cond_;
66  return *this;
67  }
68 
70 
72 
73 public:
74  std::string getName() const {return "TruncExponential";}
75 
76  void fireParameterChanged(const ParameterList& parameters);
77 
78  double randC() const
79  {
80  double x = RandomTools::randExponential(1. / getParameterValue("lambda"));
81  while (!intMinMax_->isCorrect(x))
83 
84  return x;
85  }
86 
87  double pProb(double x) const
88  {
89  if (x >= tp_)
90  return 1.;
91  else
92  return (1. - exp(-lambda_ * x)) / cond_;
93  }
94 
95  double qProb(double x) const
96  {
97  if (x == 1)
98  return tp_;
99  else
100  return -log(1. - cond_ * x) / lambda_;
101  }
102 
103  double Expectation(double a) const
104  {
105  if (a < tp_)
106  return (1. / lambda_ - exp(-a * lambda_) * (a + 1. / lambda_)) / cond_;
107  else
108  return (1. / lambda_ - exp(-tp_ * lambda_) * (tp_ + 1. / lambda_)) / cond_;
109  }
110 
112 };
113 } // end of namespace bpp.
114 #endif // BPP_NUMERIC_PROB_TRUNCATEDEXPONENTIALDISCRETEDISTRIBUTION_H
Partial implementation of the DiscreteDistribution interface.
The constraint interface.
Definition: Constraints.h:28
TruncatedExponentialDiscreteDistribution & operator=(const TruncatedExponentialDiscreteDistribution &dist)
static double randExponential(double mean)
Definition: RandomTools.h:154
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
AbstractDiscreteDistribution & operator=(const AbstractDiscreteDistribution &adde)
std::shared_ptr< IntervalConstraint > intMinMax_
the interval where the distribution is defined/restricted.
TruncatedExponentialDiscreteDistribution(const TruncatedExponentialDiscreteDistribution &dist)
TruncatedExponentialDiscreteDistribution(size_t n, double lambda=1., double truncationPoint=10)
Build a new truncated exponential discrete distribution.
void fireParameterChanged(const ParameterList &parameters)
Notify the class when one or several parameters have changed.
std::string getName() const
Get the name of the distribution.
double randC() const
Draw a random number from the continuous version of this distribution, if it exists.
double Expectation(double a) const
Return a primitive function used for the expectation of the continuous version of the distribution...
double pProb(double x) const
Return the cumulative quantile of the continuous version of the distribution, ie .
void restrictToConstraint(const ConstraintInterface &c)
Restricts the distribution to the domain where the constraint is respected, in addition of other pred...
TruncatedExponentialDiscreteDistribution * clone() const
Create a copy of this object and send a pointer to it.
Discretized Truncated (on the right) Exponential distribution, where the probabilities are given the ...
double qProb(double x) const
Return the quantile of the continuous version of the distribution, ie y such that ...