42 #include "../Random/RandomTools.h"
43 #include "../VectorTools.h"
52 numberOfCategories_(nbClasses),
54 bounds_(nbClasses - 1),
61 numberOfCategories_(nbClasses),
62 distribution_(
Order(delta)),
63 bounds_(nbClasses - 1),
70 numberOfCategories_(adde.numberOfCategories_),
71 distribution_(adde.distribution_),
72 bounds_(adde.bounds_),
73 intMinMax_(adde.intMinMax_->clone()),
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++)
313 for (
unsigned int i = 1; i <
bounds_.size(); i++)
348 bounds_[i - 1] =
qProb(minX +
static_cast<double>(i) * ec);
358 values[i] =
qProb(minX + (
static_cast<double>(i) + 0.5) * ec);
370 values[i] *= mean / t / ec;
381 values[i] = (b - a) / ec;
442 if (values[i - 1] >
intMinMax_->getUpperBound())
489 throw Exception(
"AbstractDiscreteDistribution::restrictToConstraint: the constraint is not an interval");
Comparator class for AbstractDiscreteDistribution.
Partial implementation of the DiscreteDistribution interface.
size_t getCategoryIndex(double value) const
double getCategory(size_t categoryIndex) const
double getIInfCumulativeProbability(double category) const
void set(double category, double probability)
Set the probability associated to a class.
double getUpperBound() const
std::vector< double > bounds_
Vdouble getCategories() const
void add(double category, double probability)
Modify the probability associated to a class.
double getSSupCumulativeProbability(double category) const
Vdouble getProbabilities() const
double rand() const
Draw a random number from this distribution.
double getProbability(size_t categoryIndex) const
double getValueCategory(double value) const
virtual void restrictToConstraint(const Constraint &c)
Restricts the distribution to the domain where the constraint is respected, in addition of other pred...
size_t getNumberOfCategories() const
std::map< double, double, Order > distribution_
double getLowerBound() const
methods about the range of the definition
double getInfCumulativeProbability(double category) const
void setNumberOfCategories(size_t nbClasses)
sets the number of categories and discretizes if there is a change in this number.
double getSupCumulativeProbability(double category) const
size_t numberOfCategories_
Vdouble getBounds() const
AbstractDiscreteDistribution(size_t nbClasses, const std::string &prefix="")
void print(OutputStream &out) const
Print the distribution (categories and corresponding probabilities) to a stream.
AbstractDiscreteDistribution & operator=(const AbstractDiscreteDistribution &adde)
double getBound(size_t i) const
virtual void discretize()
Discretizes the distribution in equiprobable classes.
std::shared_ptr< IntervalConstraint > intMinMax_
the interval where the distribution is defined/restricted.
A partial implementation of the Parametrizable interface.
AbstractParameterAliasable & operator=(const AbstractParameterAliasable &ap)
The constraint interface.
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 .
Exception base class. Overload exception constructor (to control the exceptions mechanism)....
An interval, either bounded or not, which can also have infinite bounds.
this static class contains several useful constant values.
std::string toString(T t)
General template method to convert to a string.
std::vector< double > Vdouble