5 #include "../../Text/TextTools.h" 6 #include "../../Utils/MapTools.h" 7 #include "../NumConstants.h" 21 for (map<double, double>::const_iterator i = distribution.begin(); i != distribution.end(); i++)
33 for (map<double, double>::const_iterator i = distribution.begin(); i != distribution.end(); i++)
50 const vector<double>& probas,
57 if (values.size() != probas.size())
61 size_t size = values.size();
63 for (
size_t i = 0; i < size; i++)
66 throw Exception(
"SimpleDiscreteDistribution: two given values are equal");
78 for (
size_t i = 0; i < size - 1; i++)
91 const std::map<
size_t, std::vector<double>>& ranges,
92 const std::vector<double>& probas,
98 if (values.size() != probas.size())
102 size_t size = values.size();
104 for (
size_t i = 0; i < size; i++)
107 throw Exception(
"SimpleDiscreteDistribution: two given values are equal");
119 for (
size_t i = 0; i < size - 1; i++)
121 map<size_t, vector<double>>::const_iterator it = ranges.find(i + 1);
122 if (it == ranges.end())
126 if (values[i] >= it->second[0] && values[i] <= it->second[1])
138 map<size_t, vector<double>>::const_iterator it = ranges.find(size);
139 if (it == ranges.end())
143 if (values[size - 1] >= it->second[0] && values[size - 1] <= it->second[1])
180 for (
size_t i = 0; i < size; i++)
262 vector<double> values = MapTools::getKeys<double, double, AbstractDiscreteDistribution::Order>(
distribution_);
267 bounds_[i] = (values[i] + values[i + 1]) / 2.;
279 throw Exception(
"SimpleDiscreteDistribution::restrictToConstraint: Non-interval exception");
281 map<double, double>::const_iterator it;
292 for (
size_t i = 0; i < size; i++)
294 map<size_t, vector<double>>::const_iterator itr =
givenRanges_.find(i + 1);
virtual void restrictToConstraint(const ConstraintInterface &c)
Restricts the distribution to the domain where the constraint is respected, in addition of other pred...
Partial implementation of the DiscreteDistribution interface.
std::map< size_t, std::vector< double > > givenRanges_
double qProb(double x) const
Return the quantile of the continuous version of the distribution, ie y such that ...
An interval, either bounded or not, which can also have infinite bounds.
The constraint interface.
double pProb(double x) const
Return the cumulative quantile of the continuous version of the distribution, ie .
void setConstraint(const std::string &name, std::shared_ptr< ConstraintInterface > constraint) override
Set/Change the constraint associated with one parameter.
SimpleDiscreteDistribution & operator=(const SimpleDiscreteDistribution &)
This class is designed to facilitate the manipulation of parameters.
void addParameter_(Parameter *parameter)
virtual void setConstraint(std::shared_ptr< ConstraintInterface > constraint)
Set a constraint to this parameter.
double getParameterValue(const std::string &name) const override
Get the value for parameter of name 'name'.
The parameter list object.
virtual void fireParameterChanged(const ParameterList ¶meters)
Notify the class when one or several parameters have changed.
A Discrete distribution object, where some specific probabilities are assigned to a finite set of val...
AbstractDiscreteDistribution & operator=(const AbstractDiscreteDistribution &adde)
std::shared_ptr< IntervalConstraint > intMinMax_
the interval where the distribution is defined/restricted.
void discretize()
Discretizes the distribution in equiprobable classes.
double Expectation(double a) const
Return a primitive function used for the expectation of the continuous version of the distribution...
std::map< double, double, Order > distribution_
static const std::shared_ptr< IntervalConstraint > PROP_CONSTRAINT_IN
void fireParameterChanged(const ParameterList ¶meters)
Notify the class when one or several parameters have changed.
Exception base class. Overload exception constructor (to control the exceptions mechanism). Destructor is already virtual (from std::exception)
SimpleDiscreteDistribution(const std::map< double, double > &distribution, double precision=NumConstants::TINY(), bool fixed=false)
Builds a new SimpleDiscreteDistribution object from a map<double,double> object. With this constructo...
Parameter & getParameter_(const std::string &name)
std::string toString(T t)
General template method to convert to a string.
double getUpperBound() const
size_t getNumberOfParameters() const override
Get the number of parameters.
virtual std::shared_ptr< ConstraintInterface > removeConstraint()
Remove the constraint associated to this parameter.
size_t numberOfCategories_
void restrictToConstraint(const ConstraintInterface &c)
Restricts the distribution to the domain where the constraint is respected, in addition of other pred...
virtual bool isCorrect(double value) const override
Tell if a given value is correct.
std::vector< double > bounds_