bpp-core3  3.0.0
InvariantMixedDiscreteDistribution.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_INVARIANTMIXEDDISCRETEDISTRIBUTION_H
6 #define BPP_NUMERIC_PROB_INVARIANTMIXEDDISCRETEDISTRIBUTION_H
7 
8 
10 
11 namespace bpp
12 {
21 {
22 private:
23  std::unique_ptr<DiscreteDistributionInterface> dist_;
24  double invariant_, p_;
25  std::string nestedPrefix_;
26 
27 public:
37  InvariantMixedDiscreteDistribution(std::unique_ptr<DiscreteDistributionInterface> dist, double p, double invariant = 0.);
38 
40 
43  dist_(imdd.dist_->clone()),
44  invariant_(imdd.invariant_),
45  p_(imdd.p_),
46  nestedPrefix_(imdd.nestedPrefix_)
47  {}
48 
50  {
52  dist_.reset(imdd.dist_->clone());
53  invariant_ = imdd.invariant_;
54  p_ = imdd.p_;
55  nestedPrefix_ = imdd.nestedPrefix_;
56  return *this;
57  }
58 
60 
61 public:
62  std::string getName() const { return "Invariant"; }
63 
64  void fireParameterChanged(const ParameterList& parameters);
65 
66  void setNamespace(const std::string& prefix);
67 
74  void setNumberOfCategories(size_t nbClasses)
75  {
76  dist_->setNumberOfCategories(nbClasses);
78  }
79 
84 
85  double qProb(double x) const
86  {
87  return (x >= p_ + (1 - p_) * dist_->pProb(invariant_)) ? dist_->qProb((x - p_) / (1 - p_)) : dist_->qProb(x / (1 - p_));
88  }
89 
90  double pProb(double x) const
91  {
92  return (1 - p_) * dist_->pProb(x) + (x < invariant_ ? 0 : p_);
93  }
94 
95  double Expectation(double a) const
96  {
97  return (1 - p_) * dist_->Expectation(a) + (a < invariant_ ? 0 : p_);
98  }
99 
100  void setMedian(bool median)
101  {
102  if (median_ != median)
103  {
104  median_ = median;
105  dist_->setMedian(median);
107  }
108  }
109 
110  void discretize()
111  {
112  dist_->discretize();
114  }
115 
117 
118 protected:
119  void updateDistribution();
120 };
121 } // end of namespace bpp.
122 #endif // BPP_NUMERIC_PROB_INVARIANTMIXEDDISCRETEDISTRIBUTION_H
double pProb(double x) const
Return the cumulative quantile of the continuous version of the distribution, ie .
double Expectation(double a) const
Return a primitive function used for the expectation of the continuous version of the distribution...
const DiscreteDistributionInterface & variableSubDistribution() const
InvariantMixedDiscreteDistribution(std::unique_ptr< DiscreteDistributionInterface > dist, double p, double invariant=0.)
Build a new InvariantMixedDiscreteDistribution object.
InvariantMixedDiscreteDistribution * clone() const
Create a copy of this object and send a pointer to it.
Partial implementation of the DiscreteDistribution interface.
InvariantMixedDiscreteDistribution & operator=(const InvariantMixedDiscreteDistribution &imdd)
The constraint interface.
Definition: Constraints.h:28
void setNamespace(const std::string &prefix)
Set the namespace for the parameter names.
Interface for discrete distribution objects.
std::unique_ptr< DiscreteDistributionInterface > dist_
std::string getName() const
Get the name of the distribution.
InvariantMixedDiscreteDistribution(const InvariantMixedDiscreteDistribution &imdd)
The parameter list object.
Definition: ParameterList.h:27
AbstractDiscreteDistribution & operator=(const AbstractDiscreteDistribution &adde)
double qProb(double x) const
Return the quantile of the continuous version of the distribution, ie y such that ...
void restrictToConstraint(const ConstraintInterface &c)
Restricts the distribution to the domain where the constraint is respected, in addition of other pred...
void fireParameterChanged(const ParameterList &parameters)
Notify the class when one or several parameters have changed.
void discretize()
Discretizes the distribution in equiprobable classes.
void setMedian(bool median)
Sets the median value to true to say that the value in a class is proportional to the median value of...
Discrete mixed distribution, with a one-category fixed value (called "invariant") and a user-specifie...