42 #include "../../Text/TextTools.h"
43 #include "../../Utils/MapTools.h"
44 #include "../NumConstants.h"
58 for (map<double, double>::const_iterator i = distribution.begin(); i != distribution.end(); i++)
70 for (map<double, double>::const_iterator i = distribution.begin(); i != distribution.end(); i++)
87 const vector<double>& probas,
94 if (values.size() != probas.size())
98 size_t size = values.size();
100 for (
size_t i = 0; i < size; i++)
103 throw Exception(
"SimpleDiscreteDistribution: two given values are equal");
115 for (
size_t i = 0; i < size - 1; i++)
128 const std::map<
size_t, std::vector<double> >& ranges,
129 const std::vector<double>& probas,
135 if (values.size() != probas.size())
139 size_t size = values.size();
141 for (
size_t i = 0; i < size; i++)
144 throw Exception(
"SimpleDiscreteDistribution: two given values are equal");
156 for (
size_t i = 0; i < size - 1; i++)
158 map<size_t, vector<double> >::const_iterator it = ranges.find(i + 1);
159 if (it == ranges.end())
163 if (values[i] >= it->second[0] && values[i] <= it->second[1])
175 map<size_t, vector<double> >::const_iterator it = ranges.find(size);
176 if (it == ranges.end())
180 if (values[size - 1] >= it->second[0] && values[size - 1] <= it->second[1])
196 givenRanges_(sdd.givenRanges_)
217 for (
size_t i = 0; i < size; i++)
299 vector<double> values = MapTools::getKeys<double, double, AbstractDiscreteDistribution::Order>(
distribution_);
304 bounds_[i] = (values[i] + values[i + 1]) / 2.;
316 throw Exception(
"SimpleDiscreteDistribution::restrictToConstraint: Non-interval exception");
318 map<double, double>::const_iterator it;
329 for (
size_t i = 0; i < size; i++)
331 map<size_t, vector<double> >::const_iterator itr =
givenRanges_.find(i + 1);
Partial implementation of the DiscreteDistribution interface.
std::vector< double > bounds_
virtual void restrictToConstraint(const Constraint &c)
Restricts the distribution to the domain where the constraint is respected, in addition of other pred...
std::map< double, double, Order > distribution_
size_t numberOfCategories_
AbstractDiscreteDistribution & operator=(const AbstractDiscreteDistribution &adde)
std::shared_ptr< IntervalConstraint > intMinMax_
the interval where the distribution is defined/restricted.
void addParameter_(Parameter *parameter)
virtual void fireParameterChanged(const ParameterList ¶meters)
Notify the class when one or several parameters have changed.
size_t getNumberOfParameters() const
Get the number of parameters.
double getParameterValue(const std::string &name) const
Get the value for parameter of name 'name'.
Parameter & getParameter_(const std::string &name)
The constraint interface.
Exception base class. Overload exception constructor (to control the exceptions mechanism)....
An interval, either bounded or not, which can also have infinite bounds.
virtual bool isCorrect(double value) const
Tell if a given value is correct.
The parameter list object.
This class is designed to facilitate the manipulation of parameters.
virtual std::shared_ptr< Constraint > removeConstraint()
Remove the constraint associated to this parameter.
static const std::shared_ptr< IntervalConstraint > PROP_CONSTRAINT_IN
virtual void setConstraint(std::shared_ptr< Constraint > constraint)
Set a constraint to this parameter.
A Discrete distribution object, where some specific probabilities are assigned to a finite set of val...
SimpleDiscreteDistribution & operator=(const SimpleDiscreteDistribution &)
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,...
std::map< size_t, std::vector< double > > givenRanges_
void fireParameterChanged(const ParameterList ¶meters)
Notify the class when one or several parameters have changed.
void discretize()
Discretizes the distribution in equiprobable classes.
void restrictToConstraint(const Constraint &c)
Restricts the distribution to the domain where the constraint is respected, in addition of other pred...
double getUpperBound() const
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...
double qProb(double x) const
Return the quantile of the continuous version of the distribution, ie y such that .
std::string toString(T t)
General template method to convert to a string.