bpp-core3  3.0.0
InvariantMixedDiscreteDistribution.h
Go to the documentation of this file.
1 //
2 // File: InvariantMixedDiscreteDistribution.h
3 // Authors:
4 // Julien Dutheil
5 // Created: 2007-12-24 12:02:00
6 //
7 
8 /*
9  Copyright or © or Copr. Bio++ Development Team, (November 17, 2004)
10 
11  This software is a computer program whose purpose is to provide classes
12  for numerical calculus.
13 
14  This software is governed by the CeCILL license under French law and
15  abiding by the rules of distribution of free software. You can use,
16  modify and/ or redistribute the software under the terms of the CeCILL
17  license as circulated by CEA, CNRS and INRIA at the following URL
18  "http://www.cecill.info".
19 
20  As a counterpart to the access to the source code and rights to copy,
21  modify and redistribute granted by the license, users are provided only
22  with a limited warranty and the software's author, the holder of the
23  economic rights, and the successive licensors have only limited
24  liability.
25 
26  In this respect, the user's attention is drawn to the risks associated
27  with loading, using, modifying and/or developing or reproducing the
28  software by the user in light of its specific status of free software,
29  that may mean that it is complicated to manipulate, and that also
30  therefore means that it is reserved for developers and experienced
31  professionals having in-depth computer knowledge. Users are therefore
32  encouraged to load and test the software's suitability as regards their
33  requirements in conditions enabling the security of their systems and/or
34  data to be ensured and, more generally, to use and operate it in the
35  same conditions as regards security.
36 
37  The fact that you are presently reading this means that you have had
38  knowledge of the CeCILL license and that you accept its terms.
39 */
40 
41 #ifndef BPP_NUMERIC_PROB_INVARIANTMIXEDDISCRETEDISTRIBUTION_H
42 #define BPP_NUMERIC_PROB_INVARIANTMIXEDDISCRETEDISTRIBUTION_H
43 
44 
46 
47 namespace bpp
48 {
57 {
58 private:
60  double invariant_, p_;
61  std::string nestedPrefix_;
62 
63 public:
73  InvariantMixedDiscreteDistribution(DiscreteDistribution* dist, double p, double invariant = 0.);
74 
76  {
77  delete dist_;
78  }
79 
82  dist_(dynamic_cast<DiscreteDistribution*>(imdd.dist_->clone())),
83  invariant_(imdd.invariant_),
84  p_(imdd.p_),
86  {}
87 
89  {
91  dist_ = dynamic_cast<DiscreteDistribution*>(imdd.dist_->clone());
92  invariant_ = imdd.invariant_;
93  p_ = imdd.p_;
95  return *this;
96  }
97 
99 
100 public:
101  std::string getName() const {return "Invariant"; }
102 
103  void fireParameterChanged(const ParameterList& parameters);
104 
105  void setNamespace(const std::string& prefix);
106 
113  void setNumberOfCategories(size_t nbClasses)
114  {
115  dist_->setNumberOfCategories(nbClasses);
117  }
118 
123 
124  double qProb(double x) const
125  {
126  return (x >= p_ + (1 - p_) * dist_->pProb(invariant_)) ? dist_->qProb((x - p_) / (1 - p_)) : dist_->qProb(x / (1 - p_));
127  }
128 
129  double pProb(double x) const
130  {
131  return (1 - p_) * dist_->pProb(x) + (x < invariant_ ? 0 : p_);
132  }
133 
134  double Expectation(double a) const
135  {
136  return (1 - p_) * dist_->Expectation(a) + (a < invariant_ ? 0 : p_);
137  }
138 
139  void setMedian(bool median)
140  {
141  if (median_ != median)
142  {
143  median_ = median;
144  dist_->setMedian(median);
146  }
147  }
148 
149  void discretize()
150  {
151  dist_->discretize();
153  }
154 
155  void restrictToConstraint(const Constraint& c);
156 
157 protected:
158  void updateDistribution();
159 };
160 } // end of namespace bpp.
161 #endif // BPP_NUMERIC_PROB_INVARIANTMIXEDDISCRETEDISTRIBUTION_H
Partial implementation of the DiscreteDistribution interface.
AbstractDiscreteDistribution & operator=(const AbstractDiscreteDistribution &adde)
The constraint interface.
Definition: Constraints.h:66
Interface for discrete distribution objects.
virtual void setMedian(bool median)=0
Sets the median value to true to say that the value in a class is proportional to the median value of...
virtual void discretize()=0
Discretizes the distribution in equiprobable classes.
virtual void setNumberOfCategories(size_t nbClasses)=0
sets the number of categories and discretizes if there is a change in this number.
DiscreteDistribution * clone() const =0
Create a copy of this object and send a pointer to it.
virtual double Expectation(double a) const =0
Return a primitive function used for the expectation of the continuous version of the distribution,...
virtual double pProb(double x) const =0
Return the cumulative quantile of the continuous version of the distribution, ie .
virtual double qProb(double x) const =0
Return the quantile of the continuous version of the distribution, ie y such that .
Discrete mixed distribution, with a one-category fixed value (called "invariant") and a user-specifie...
void discretize()
Discretizes the distribution in equiprobable classes.
InvariantMixedDiscreteDistribution & operator=(const InvariantMixedDiscreteDistribution &imdd)
std::string getName() const
Get the name of the distribution.
const DiscreteDistribution * getVariableSubDistribution() const
void restrictToConstraint(const Constraint &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.
InvariantMixedDiscreteDistribution(const InvariantMixedDiscreteDistribution &imdd)
double pProb(double x) const
Return the cumulative quantile of the continuous version of the distribution, ie .
void setNamespace(const std::string &prefix)
Set the namespace for the parameter names.
double Expectation(double a) const
Return a primitive function used for the expectation of the continuous version of the distribution,...
InvariantMixedDiscreteDistribution * clone() const
Create a copy of this object and send a pointer to it.
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...
InvariantMixedDiscreteDistribution(DiscreteDistribution *dist, double p, double invariant=0.)
Build a new InvariantMixedDiscreteDistribution object.
double qProb(double x) const
Return the quantile of the continuous version of the distribution, ie y such that .
The parameter list object.
Definition: ParameterList.h:65