42 #include "../../Text/TextTools.h"
43 #include "../../Utils/MapTools.h"
44 #include "../NumConstants.h"
51 const vector<double>& probas ) :
57 if (distributions.size() != probas.size())
62 size_t size = distributions.size();
63 for (
size_t i = 0; i < size; i++)
65 if (distributions[i] == 0)
69 for (
size_t i = 0; i < size; i++)
79 for (
size_t i = 0; i < size - 1; i++)
86 for (
size_t i = 0; i < size; i++)
88 vdd_.push_back(distributions[i]->
clone());
93 for (
size_t i = 0; i < size; i++)
98 for (
size_t i = 0; i < size; i++)
103 for (
size_t i = 0; i < size; i++)
117 for (
size_t i = 0; i < mdd.
vdd_.size(); i++)
120 vdd_.push_back(mdd.
vdd_[i]->clone());
132 for (
size_t i = 0; i < mdd.
vdd_.size(); i++)
135 vdd_.push_back(mdd.
vdd_[i]->clone());
144 for (
size_t i = 0; i <
vdd_.size(); i++)
154 for (
size_t i = 0; i <
vdd_.size(); i++)
156 vdd_[i]->setNumberOfCategories(nbClasses);
166 size_t size =
vdd_.size();
168 for (
size_t i = 0; i < size - 1; i++)
177 for (
size_t i = 0; i < size; i++)
179 vdd_[i]->matchParametersValues(parameters);
187 size_t size =
vdd_.size();
191 for (
size_t i = 0; i < size; i++)
193 vector<double> values =
vdd_[i]->getCategories();
194 for (
size_t j = 0; j < values.size(); j++)
200 for (
size_t i = 0; i < size; i++)
202 vector<double> values =
vdd_[i]->getCategories();
203 vector<double> probas2 =
vdd_[i]->getProbabilities();
204 for (
size_t j = 0; j < values.size(); j++)
218 bool suB =
true, slB =
true;
220 for (
size_t i = 0; i < size; i++)
224 lB =
vdd_[i]->getLowerBound();
225 slB =
vdd_[i]->strictLowerBound();
229 uB =
vdd_[i]->getUpperBound();
230 suB =
vdd_[i]->strictUpperBound();
238 vector<double> values = MapTools::getKeys<double, double, AbstractDiscreteDistribution::Order>(
distribution_);
245 bounds_[i] = (values[i] + values[i + 1]) / 2.;
254 for (
size_t i = 0; i <
vdd_.size(); i++)
256 vdd_[i]->setMedian(median);
263 for (
size_t i = 0; i <
vdd_.size(); i++)
265 vdd_[i]->discretize();
274 for (
size_t i = 0; i <
vdd_.size(); i++)
283 throw Exception(
"MixtureOfDiscreteDistributions::qProb to difficult to compute: not implemented");
290 for (
size_t i = 0; i <
vdd_.size(); i++)
299 for (
size_t i = 0; i <
vdd_.size(); i++)
301 vdd_[i]->restrictToConstraint(c);
313 for (
size_t i = 0; i <
vdd_.size(); i++)
Partial implementation of the DiscreteDistribution interface.
double getUpperBound() const
std::vector< double > bounds_
std::map< double, double, Order > distribution_
double getLowerBound() const
methods about the range of the definition
size_t numberOfCategories_
AbstractDiscreteDistribution & operator=(const AbstractDiscreteDistribution &adde)
std::shared_ptr< IntervalConstraint > intMinMax_
the interval where the distribution is defined/restricted.
void addParameters_(const ParameterList ¶meters)
void addParameter_(Parameter *parameter)
void setNamespace(const std::string &prefix)
Set the namespace for the parameter names.
virtual void fireParameterChanged(const ParameterList ¶meters)
Notify the class when one or several parameters have changed.
const ParameterList & getParameters() const
Get all parameters available.
std::string getNamespace() const
double getParameterValue(const std::string &name) const
Get the value for parameter of name 'name'.
The constraint interface.
Exception base class. Overload exception constructor (to control the exceptions mechanism)....
A Discrete distribution object defined by a vector of Discrete Distributions and a set of probabiliti...
void updateDistribution()
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...
void restrictToConstraint(const Constraint &c)
Restricts the distribution to the domain where the constraint is respected, in addition of other pred...
std::vector< DiscreteDistribution * > vdd_
double Expectation(double a) const
Return a primitive function used for the expectation of the continuous version of the distribution,...
double qProb(double x) const
Return the quantile of the continuous version of the distribution, ie y such that .
void discretize()
Discretizes the distribution in equiprobable classes.
MixtureOfDiscreteDistributions * clone() const
Create a copy of this object and send a pointer to it.
MixtureOfDiscreteDistributions(const std::vector< DiscreteDistribution * > &distributions, const std::vector< double > &probas)
Builds a new MixtureOfDiscreteDistributions object from a vector of Discrete Distributions and a vect...
~MixtureOfDiscreteDistributions()
std::vector< double > probas_
std::vector< std::string > vNestedPrefix_
MixtureOfDiscreteDistributions & operator=(const MixtureOfDiscreteDistributions &mdd)
double pProb(double x) const
Return the cumulative quantile of the continuous version of the distribution, ie .
void fireParameterChanged(const ParameterList ¶meters)
Notify the class when one or several parameters have changed.
void setNamespace(const std::string &prefix)
Set the namespace for the parameter names.
void setNumberOfCategories(size_t nbClasses)
sets the number of categories of EACH submodel to nbClasses, so the number of categories of the mixtu...
The parameter list object.
This class is designed to facilitate the manipulation of parameters.
static const std::shared_ptr< IntervalConstraint > PROP_CONSTRAINT_IN
std::string toString(T t)
General template method to convert to a string.