bpp-core  2.2.0
InvariantMixedDiscreteDistribution.h
Go to the documentation of this file.
1 //
2 // File: InvariantMixedDiscreteDistribution.h
3 // Created by: Julien Dutheil
4 // Created on: Mon Dec 24 12:02 2007
5 //
6 
7 /*
8  Copyright or © or Copr. Bio++ Development Team, (November 17, 2004)
9 
10  This software is a computer program whose purpose is to provide classes
11  for numerical calculus.
12 
13  This software is governed by the CeCILL license under French law and
14  abiding by the rules of distribution of free software. You can use,
15  modify and/ or redistribute the software under the terms of the CeCILL
16  license as circulated by CEA, CNRS and INRIA at the following URL
17  "http://www.cecill.info".
18 
19  As a counterpart to the access to the source code and rights to copy,
20  modify and redistribute granted by the license, users are provided only
21  with a limited warranty and the software's author, the holder of the
22  economic rights, and the successive licensors have only limited
23  liability.
24 
25  In this respect, the user's attention is drawn to the risks associated
26  with loading, using, modifying and/or developing or reproducing the
27  software by the user in light of its specific status of free software,
28  that may mean that it is complicated to manipulate, and that also
29  therefore means that it is reserved for developers and experienced
30  professionals having in-depth computer knowledge. Users are therefore
31  encouraged to load and test the software's suitability as regards their
32  requirements in conditions enabling the security of their systems and/or
33  data to be ensured and, more generally, to use and operate it in the
34  same conditions as regards security.
35 
36  The fact that you are presently reading this means that you have had
37  knowledge of the CeCILL license and that you accept its terms.
38  */
39 
40 #ifndef _INVARIANTMIXEDDISCRETEDISTRIBUTION_H_
41 #define _INVARIANTMIXEDDISCRETEDISTRIBUTION_H_
42 
44 
45 namespace bpp
46 {
55 {
56 private:
58  double invariant_, p_;
59  std::string nestedPrefix_;
60 
61 public:
71  InvariantMixedDiscreteDistribution(DiscreteDistribution* dist, double p, double invariant = 0.);
72 
74  {
75  delete dist_;
76  }
77 
81  dist_(dynamic_cast<DiscreteDistribution*>(imdd.dist_->clone())),
82  invariant_(imdd.invariant_),
83  p_(imdd.p_),
85  {}
86 
88  {
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 
162 #endif // _INVARIANTMIXEDDISCRETEDISTRIBUTION_H_
void restrictToConstraint(const Constraint &c)
Restricts the distribution to the domain where the constraint is respected, in addition of other pred...
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...
virtual double pProb(double x) const =0
Return the cumulative quantile of the continuous version of the distribution, ie .
virtual double Expectation(double a) const =0
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.
Partial implementation of the DiscreteDistribution interface.
InvariantMixedDiscreteDistribution & operator=(const InvariantMixedDiscreteDistribution &imdd)
This class allows to perform a correspondence analysis.
Interface for discrete distribution objects.
InvariantMixedDiscreteDistribution(DiscreteDistribution *dist, double p, double invariant=0.)
Build a new InvariantMixedDiscreteDistribution object.
void setNamespace(const std::string &prefix)
Set the namespace for the parameter names.
std::string getName() const
Get the name of the distribution.
InvariantMixedDiscreteDistribution(const InvariantMixedDiscreteDistribution &imdd)
The parameter list object.
Definition: ParameterList.h:61
AbstractDiscreteDistribution & operator=(const AbstractDiscreteDistribution &adde)
double qProb(double x) const
Return the quantile of the continuous version of the distribution, ie y such that ...
const DiscreteDistribution * getVariableSubDistribution() const
A partial implementation of the Parametrizable interface.
void fireParameterChanged(const ParameterList &parameters)
Notify the class when one or several parameters have changed.
void discretize()
Discretizes the distribution in equiprobable classes.
virtual void discretize()=0
Discretizes the distribution in equiprobable classes.
The constraint interface.
Definition: Constraints.h:62
virtual double qProb(double x) const =0
Return the quantile of the continuous version of the distribution, ie y such that ...
AbstractParameterAliasable & operator=(const AbstractParameterAliasable &ap)
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...
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...
Discrete mixed distribution, with a one-category fixed value (called "invariant") and a user-specifie...
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.