42 #include "../Random/RandomTools.h" 43 #include "../VectorTools.h" 51 numberOfCategories_(nbClasses),
60 numberOfCategories_(nbClasses),
61 distribution_(
Order(delta)),
69 numberOfCategories_(adde.numberOfCategories_),
70 distribution_(adde.distribution_),
71 bounds_(adde.bounds_),
72 intMinMax_(adde.intMinMax_),
99 cerr <<
"DEBUG: ERROR!!! Number of categories is <= 0 in AbstractDiscreteDistribution::setNumberOfCategories()." << endl;
113 map<double, double>::const_iterator it =
distribution_.begin();
114 for (
unsigned int i = 0; i < categoryIndex; i++)
125 map<double, double>::const_iterator it =
distribution_.begin();
126 for (
unsigned int i = 0; i < categoryIndex; i++)
146 for (map<double, double>::const_iterator it =
distribution_.begin();
150 result[i] = it->first;
162 for (map<double, double>::const_iterator it =
distribution_.begin();
166 result[i] = it->second;
201 for (map<double, double>::const_iterator i =
distribution_.begin();
205 cumprob += i->second;
218 map<double, double>::const_iterator it =
distribution_.find(category);
219 for (map<double, double>::const_iterator i =
distribution_.begin();
233 map<double, double>::const_iterator it =
distribution_.find(category);
236 for (map<double, double>::const_iterator i = ++it;
250 map<double, double>::const_iterator it =
distribution_.find(category);
253 for (map<double, double>::const_iterator i = ++it;
267 map<double, double>::const_iterator it =
distribution_.find(category);
268 for (map<double, double>::const_iterator i =
distribution_.begin();
283 (out <<
"Pr(" << (i->first) <<
") = " << (i->second)).endLine();
294 map<double, double>::const_iterator it =
distribution_.begin();
295 for (
unsigned int i=1;i<
bounds_.size();i++)
330 bounds_[i-1] =
qProb(minX + static_cast<double>(i) * ec);
339 values[i] =
qProb(minX + (static_cast<double>(i) + 0.5) * ec);
347 values[i] *= mean / t / ec;
357 values[i] = (b - a) / ec;
459 throw Exception(
"AbstractDiscreteDistribution::restrictToConstraint: the constraint is not an interval");
void set(double category, double probability)
Set the probability associated to a class.
double getInfCumulativeProbability(double category) const
double getCategory(size_t categoryIndex) const
Comparator class for AbstractDiscreteDistribution.
Vdouble getBounds() const
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...
double getLowerBound() const
Partial implementation of the DiscreteDistribution interface.
double getIInfCumulativeProbability(double category) const
bool strictLowerBound() const
this static class contains several useful constant values.
An interval, either bounded or not, which can also have infinite bounds.
This class allows to perform a correspondence analysis.
virtual bool isCorrect(double value) const
Tell if a given value is correct.
double getSSupCumulativeProbability(double category) const
double getSupCumulativeProbability(double category) const
double getBound(size_t i) const
void add(double category, double probability)
Modify the probability associated to a class.
Vdouble getProbabilities() const
double getProbability(size_t categoryIndex) const
size_t getNumberOfCategories() const
static std::string toString(T t)
General template method to convert to a string.
AbstractDiscreteDistribution & operator=(const AbstractDiscreteDistribution &adde)
A partial implementation of the Parametrizable interface.
void print(OutputStream &out) const
Print the distribution (categories and corresponding probabilities) to a stream.
bool strictUpperBound() const
double rand() const
Draw a random number from this distribution.
double getLowerBound() const
methods about the range of the definition
The constraint interface.
std::vector< double > Vdouble
std::map< double, double, Order > distribution_
virtual void discretize()
Discretizes the distribution in equiprobable classes.
virtual double qProb(double x) const =0
Return the quantile of the continuous version of the distribution, ie y such that ...
AbstractDiscreteDistribution(size_t nbClasses, const std::string &prefix="")
AbstractParameterAliasable & operator=(const AbstractParameterAliasable &ap)
double getUpperBound() const
void setNumberOfCategories(size_t nbClasses)
sets the number of categories and discretizes if there is a change in this number.
double getValueCategory(double value) const
Vdouble getCategories() const
double getUpperBound() const
IntervalConstraint intMinMax_
the interval where the distribution is defined/restricted.
size_t numberOfCategories_
virtual void restrictToConstraint(const Constraint &c)
Restricts the distribution to the domain where the constraint is respected, in addition of other pred...
std::vector< double > bounds_