1 #ifndef __STDAIR_BAS_CATEGORICALATTRIBUTE_HPP
2 #define __STDAIR_BAS_CATEGORICALATTRIBUTE_HPP
11 #include <stdair/STDAIR_Types.hpp>
12 #include <stdair/basic/DictionaryManager.hpp>
42 return _probabilityMassFunction;
49 return _inverseCumulativeDistribution;
57 _probabilityMassFunction = iProbabilityMassFunction;
67 const T&
getValue (
const Probability_T& iCumulativeProbability)
const {
70 DictionaryManager::valueToKey (iCumulativeProbability);
72 InverseCumulativeDistribution_T::const_iterator itT =
73 _inverseCumulativeDistribution.find (lKey);
75 if (itT == _inverseCumulativeDistribution.end()) {
76 std::ostringstream oStr;
77 oStr <<
"The following cumulative probability is out of range: "
79 throw IndexOutOfRangeException (oStr.str());
92 std::ostringstream oStr;
95 for (
typename ProbabilityMassFunction_T::const_iterator it =
96 _probabilityMassFunction.begin();
97 it != _probabilityMassFunction.end(); ++it, ++idx) {
101 oStr << it->first <<
":"
102 << DictionaryManager::keyToValue (it->second);
112 std::ostringstream oStr;
114 for (
typename InverseCumulativeDistribution_T::const_iterator it =
115 _inverseCumulativeDistribution.begin();
116 it != _inverseCumulativeDistribution.end(); ++it) {
117 oStr <<
"cumulative prob: " << DictionaryManager::keyToValue (it->first)
118 <<
" value: " << it->second << std::endl;
130 : _probabilityMassFunction (iProbabilityMassFunction) {
143 : _probabilityMassFunction (iCategoricalAttribute._probabilityMassFunction) {
159 Probability_T cumulative_probability_so_far = 0.0;
160 for (
typename ProbabilityMassFunction_T::const_iterator
161 itProbabilityMassFunction = _probabilityMassFunction.begin();
162 itProbabilityMassFunction != _probabilityMassFunction.end();
163 ++itProbabilityMassFunction) {
165 Probability_T attribute_probability_mass =
166 DictionaryManager::keyToValue (itProbabilityMassFunction->second);
168 if (attribute_probability_mass > 0) {
169 T attribute_value = itProbabilityMassFunction->first;
170 cumulative_probability_so_far += attribute_probability_mass;
173 DictionaryManager::valueToKey (cumulative_probability_so_far);
176 _inverseCumulativeDistribution.
178 value_type (lKey, attribute_value));
196 #endif // __STDAIR_BAS_CATEGORICALATTRIBUTE_HPP