5 #include "../../Text/TextTools.h" 6 #include "../../Utils/MapTools.h" 7 #include "../NumConstants.h" 14 const vector<unique_ptr<DiscreteDistributionInterface>>& distributions,
15 const vector<double>& probas ) :
21 if (distributions.size() != probas.size())
26 size_t size = distributions.size();
27 for (
size_t i = 0; i < size; i++)
29 if (distributions[i] == 0)
33 for (
size_t i = 0; i < size; i++)
43 for (
size_t i = 0; i < size - 1; i++)
50 for (
size_t i = 0; i < size; i++)
52 vdd_.push_back(unique_ptr<DiscreteDistributionInterface>(distributions[i]->
clone()));
57 for (
size_t i = 0; i < size; i++)
62 for (
size_t i = 0; i < size; i++)
67 for (
size_t i = 0; i < size; i++)
81 for (
size_t i = 0; i < mdd.
vdd_.size(); i++)
84 vdd_.push_back(unique_ptr<DiscreteDistributionInterface>(mdd.
vdd_[i]->clone()));
96 for (
size_t i = 0; i < mdd.
vdd_.size(); i++)
99 vdd_.push_back(unique_ptr<DiscreteDistributionInterface>(mdd.
vdd_[i]->clone()));
113 for (
size_t i = 0; i <
vdd_.size(); i++)
115 vdd_[i]->setNumberOfCategories(nbClasses);
125 size_t size =
vdd_.size();
127 for (
size_t i = 0; i < size - 1; i++)
136 for (
size_t i = 0; i < size; i++)
138 vdd_[i]->matchParametersValues(parameters);
146 size_t size =
vdd_.size();
150 for (
size_t i = 0; i < size; i++)
152 vector<double> values =
vdd_[i]->getCategories();
153 for (
size_t j = 0; j < values.size(); j++)
159 for (
size_t i = 0; i < size; i++)
161 vector<double> values =
vdd_[i]->getCategories();
162 vector<double> probas2 =
vdd_[i]->getProbabilities();
163 for (
size_t j = 0; j < values.size(); j++)
177 bool suB =
true, slB =
true;
179 for (
size_t i = 0; i < size; i++)
183 lB =
vdd_[i]->getLowerBound();
184 slB =
vdd_[i]->strictLowerBound();
188 uB =
vdd_[i]->getUpperBound();
189 suB =
vdd_[i]->strictUpperBound();
197 vector<double> values = MapTools::getKeys<double, double, AbstractDiscreteDistribution::Order>(
distribution_);
204 bounds_[i] = (values[i] + values[i + 1]) / 2.;
213 for (
size_t i = 0; i <
vdd_.size(); i++)
215 vdd_[i]->setMedian(median);
222 for (
size_t i = 0; i <
vdd_.size(); i++)
224 vdd_[i]->discretize();
233 for (
size_t i = 0; i <
vdd_.size(); i++)
242 throw Exception(
"MixtureOfDiscreteDistributions::qProb to difficult to compute: not implemented");
249 for (
size_t i = 0; i <
vdd_.size(); i++)
258 for (
size_t i = 0; i <
vdd_.size(); i++)
260 vdd_[i]->restrictToConstraint(c);
272 for (
size_t i = 0; i <
vdd_.size(); i++)
MixtureOfDiscreteDistributions & operator=(const MixtureOfDiscreteDistributions &mdd)
std::string getNamespace() const override
virtual ~MixtureOfDiscreteDistributions()
void setNumberOfCategories(size_t nbClasses)
sets the number of categories of EACH submodel to nbClasses, so the number of categories of the mixtu...
Partial implementation of the DiscreteDistribution interface.
The constraint interface.
void setNamespace(const std::string &prefix)
Set the namespace for the parameter names.
void fireParameterChanged(const ParameterList ¶meters)
Notify the class when one or several parameters have changed.
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...
This class is designed to facilitate the manipulation of parameters.
double qProb(double x) const
Return the quantile of the continuous version of the distribution, ie y such that ...
void addParameter_(Parameter *parameter)
void updateDistribution()
double getParameterValue(const std::string &name) const override
Get the value for parameter of name 'name'.
A Discrete distribution object defined by a vector of Discrete Distributions and a set of probabiliti...
The parameter list object.
virtual void fireParameterChanged(const ParameterList ¶meters)
Notify the class when one or several parameters have changed.
void restrictToConstraint(const ConstraintInterface &c)
Restricts the distribution to the domain where the constraint is respected, in addition of other pred...
AbstractDiscreteDistribution & operator=(const AbstractDiscreteDistribution &adde)
std::shared_ptr< IntervalConstraint > intMinMax_
the interval where the distribution is defined/restricted.
void addParameters_(const ParameterList ¶meters)
double getLowerBound() const
methods about the range of the definition
std::map< double, double, Order > distribution_
static const std::shared_ptr< IntervalConstraint > PROP_CONSTRAINT_IN
double getUpperBound() const
Exception base class. Overload exception constructor (to control the exceptions mechanism). Destructor is already virtual (from std::exception)
MixtureOfDiscreteDistributions(const std::vector< std::unique_ptr< DiscreteDistributionInterface >> &distributions, const std::vector< double > &probas)
Builds a new MixtureOfDiscreteDistributions object from a vector of Discrete Distributions and a vect...
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 setNamespace(const std::string &prefix)
Set the namespace for the parameter names.
MixtureOfDiscreteDistributions * clone() const
Create a copy of this object and send a pointer to it.
std::string toString(T t)
General template method to convert to a string.
void discretize()
Discretizes the distribution in equiprobable classes.
std::vector< double > probas_
std::vector< std::unique_ptr< DiscreteDistributionInterface > > vdd_
std::vector< std::string > vNestedPrefix_
const ParameterList & getParameters() const override
Get all parameters available.
size_t numberOfCategories_
std::vector< double > bounds_