diff --git a/src/Learning/DTForest/DTAttributeSelection.cpp b/src/Learning/DTForest/DTAttributeSelection.cpp index aeb9c8acb..c723cce4d 100644 --- a/src/Learning/DTForest/DTAttributeSelection.cpp +++ b/src/Learning/DTForest/DTAttributeSelection.cpp @@ -729,22 +729,17 @@ longint DTTreeAttribute::GetUsedMemory() const int DTTreeAttributeLevelCompare(const void* elem1, const void* elem2) { - longint lLevel1; - longint lLevel2; int nCompare; DTTreeAttribute* i1 = (DTTreeAttribute*)*(Object**)elem1; DTTreeAttribute* i2 = (DTTreeAttribute*)*(Object**)elem2; - // Comparaison des levels des attributs (ramenes a longint) - lLevel1 = longint(floor(i1->dLevel * 1e10)); - lLevel2 = longint(floor(i2->dLevel * 1e10)); - nCompare = -CompareLongint(lLevel1, lLevel2); + // Comparaison selon la precison du type Continuous, pour eviter les differences a epsilon pres + nCompare = -KWContinuous::CompareIndicatorValue(i1->dLevel, i2->dLevel); // Comparaison par nom si match nul if (nCompare == 0) nCompare = DTTreeAttributeCompareName(elem1, elem2); - return nCompare; } diff --git a/src/Learning/DTForest/DTCreationReport.cpp b/src/Learning/DTForest/DTCreationReport.cpp index d2ff88eab..e6ac5f279 100644 --- a/src/Learning/DTForest/DTCreationReport.cpp +++ b/src/Learning/DTForest/DTCreationReport.cpp @@ -397,17 +397,13 @@ void DTCreationReport::ComputeRankIdentifiers(ObjectArray* oaReports) int DTTreeSpecsCompareLevels(const void* elem1, const void* elem2) { - longint lLevel1; - longint lLevel2; int nCompare; DTDecisionTreeSpec* s1 = (DTDecisionTreeSpec*)*(Object**)elem1; DTDecisionTreeSpec* s2 = (DTDecisionTreeSpec*)*(Object**)elem2; - // Comparaison des levels des attributs (ramenes a longint) - lLevel1 = longint(floor(s1->GetLevel() * 1e10)); - lLevel2 = longint(floor(s2->GetLevel() * 1e10)); - nCompare = -CompareLongint(lLevel1, lLevel2); + // Comparaison selon la precison du type Continuous, pour eviter les differences a epsilon pres + nCompare = -KWContinuous::CompareIndicatorValue(s1->GetLevel(), s2->GetLevel()); // Comparaison par nom d'arbre, si match nul if (nCompare == 0) diff --git a/src/Learning/DTForest/DTDecisionTree.h b/src/Learning/DTForest/DTDecisionTree.h index 284f01196..1f829a2e2 100644 --- a/src/Learning/DTForest/DTDecisionTree.h +++ b/src/Learning/DTForest/DTDecisionTree.h @@ -582,11 +582,6 @@ inline int DTSplitCompareSortValue(const void* elem1, const void* elem2) // dSortValue2 = report2->GetTreeCost(); sSortValue1 = report1->GetSplittableNode()->GetNodeIdentifier(); sSortValue2 = report2->GetSplittableNode()->GetNodeIdentifier(); - - // On se base sur un comparaison a dix decimales pres - // lSortValue1 = longint(floor(dSortValue1 * 1e10)); - // lSortValue2 = longint(floor(dSortValue2 * 1e10)); - // nCompare = -CompareLongint(lSortValue1, lSortValue2); nCompare = sSortValue1.Compare(sSortValue2); // Comparaison si necessaire sur le nom diff --git a/src/Learning/KWData/KWContinuous.h b/src/Learning/KWData/KWContinuous.h index 0f11d08b4..c31e74584 100644 --- a/src/Learning/KWData/KWContinuous.h +++ b/src/Learning/KWData/KWContinuous.h @@ -119,6 +119,10 @@ class KWContinuous : public Object // Comparaison static int Compare(Continuous cValue1, Continuous cValue2); + // Comparaison de deux valeurs de type indicateur, en principe entre 0 et 1 + // Permet d'avoir une resultat de comparaison robuste, selon la precision des Continuous + static int CompareIndicatorValue(double dValue1, double dValue2); + // Test des fonctionnalites static void Test(); @@ -535,6 +539,12 @@ inline int KWContinuous::Compare(Continuous cValue1, Continuous cValue2) return (cValue1 == cValue2 ? 0 : (cValue1 > cValue2 ? 1 : -1)); } +inline int KWContinuous::CompareIndicatorValue(double dValue1, double dValue2) +{ + // On ajoute 1 pour avoir une precision de mantisse limitee de facon absolue par rapprt au 0 + return Compare(DoubleToContinuous(1 + dValue1), DoubleToContinuous(1 + dValue2)); +} + // Classe ContinuousObject inline ContinuousObject::ContinuousObject() diff --git a/src/Learning/KWDataPreparation/KWAttributeStats.cpp b/src/Learning/KWDataPreparation/KWAttributeStats.cpp index 7f43d20c2..7cd4c6875 100644 --- a/src/Learning/KWDataPreparation/KWAttributeStats.cpp +++ b/src/Learning/KWDataPreparation/KWAttributeStats.cpp @@ -1954,8 +1954,6 @@ int KWAttributeStatsCompareLevel(const void* elem1, const void* elem2) { KWAttributeStats* attributeStats1; KWAttributeStats* attributeStats2; - longint lLevel1; - longint lLevel2; int nCompare; // Acces aux objects @@ -1966,10 +1964,8 @@ int KWAttributeStatsCompareLevel(const void* elem1, const void* elem2) assert(attributeStats1->Check()); assert(attributeStats2->Check()); - // Comparaison des levels des attributs (ramanes a longint) - lLevel1 = longint(floor(attributeStats1->GetLevel() * 1e10)); - lLevel2 = longint(floor(attributeStats2->GetLevel() * 1e10)); - nCompare = -CompareLongint(lLevel1, lLevel2); + // Comparaison selon la precison du type Continuous, pour eviter les differences a epsilon pres + nCompare = -KWContinuous::CompareIndicatorValue(attributeStats1->GetLevel(), attributeStats2->GetLevel()); // Comparaison par nom si match nul if (nCompare == 0) diff --git a/src/Learning/KWDataPreparation/KWDataGrid.cpp b/src/Learning/KWDataPreparation/KWDataGrid.cpp index 0cd7cf19a..9e46e24ba 100644 --- a/src/Learning/KWDataPreparation/KWDataGrid.cpp +++ b/src/Learning/KWDataPreparation/KWDataGrid.cpp @@ -4762,9 +4762,8 @@ int KWDGSymbolValue::CompareTypicality(const KWDGValue* otherValue) const require(otherValue != NULL); - // Comparaison de la typicalite selon la precison du type Continuous, pour eviter les differences a epsilon pres - nCompare = -KWContinuous::Compare(KWContinuous::DoubleToContinuous(GetTypicality()), - KWContinuous::DoubleToContinuous(otherValue->GetTypicality())); + // Comparaison selon la precison du type Continuous, pour eviter les differences a epsilon pres + nCompare = -KWContinuous::CompareIndicatorValue(GetTypicality(), otherValue->GetTypicality()); // Comparaison par effectif decroissaqnt si egalite if (nCompare == 0) @@ -4847,9 +4846,8 @@ int KWDGVarPartValue::CompareTypicality(const KWDGValue* otherValue) const require(otherValue != NULL); - // Comparaison de la typicalite selon la precison du type Continuous, pour eviter les differences a epsilon pres - nCompare = -KWContinuous::Compare(KWContinuous::DoubleToContinuous(GetTypicality()), - KWContinuous::DoubleToContinuous(otherValue->GetTypicality())); + // Comparaison selon la precison du type Continuous, pour eviter les differences a epsilon pres + nCompare = -KWContinuous::CompareIndicatorValue(GetTypicality(), otherValue->GetTypicality()); // Comparaison par valeur si egalite if (nCompare == 0) diff --git a/src/Learning/KWDataPreparation/KWLearningReport.cpp b/src/Learning/KWDataPreparation/KWLearningReport.cpp index c43857c9e..ae3ecd110 100644 --- a/src/Learning/KWDataPreparation/KWLearningReport.cpp +++ b/src/Learning/KWDataPreparation/KWLearningReport.cpp @@ -104,21 +104,9 @@ int KWLearningReport::CompareName(const KWLearningReport* otherReport) const int KWLearningReport::CompareValue(const KWLearningReport* otherReport) const { int nCompare; - longint lSortValue1; - longint lSortValue2; - // On se base sur un comparaison a dix decimales pres - if (GetSortValue() >= 0) - lSortValue1 = longint(GetSortValue() * 1e10); - else - lSortValue1 = -longint(-GetSortValue() * 1e10); - if (otherReport->GetSortValue() >= 0) - lSortValue2 = longint(otherReport->GetSortValue() * 1e10); - else - lSortValue2 = -longint(-otherReport->GetSortValue() * 1e10); - - // Comparaison sur les valeurs entieres - nCompare = -CompareLongint(lSortValue1, lSortValue2); + // Comparaison selon la precison du type Continuous, pour eviter les differences a epsilon pres + nCompare = -KWContinuous::CompareIndicatorValue(1 + GetSortValue(), 1 + otherReport->GetSortValue()); // En cas d'egalite, on se base sur le nom if (nCompare == 0) diff --git a/src/Learning/KWModeling/KWDataPreparationClass.cpp b/src/Learning/KWModeling/KWDataPreparationClass.cpp index 4ba68338c..e4192a05c 100644 --- a/src/Learning/KWModeling/KWDataPreparationClass.cpp +++ b/src/Learning/KWModeling/KWDataPreparationClass.cpp @@ -1113,10 +1113,6 @@ int KWDataPreparationAttributeCompareSortValue(const void* elem1, const void* el { KWDataPreparationAttribute* dataPreparationAttribute1; KWDataPreparationAttribute* dataPreparationAttribute2; - double dSortValue1; - double dSortValue2; - longint lSortValue1; - longint lSortValue2; int nCompare; check(elem1); @@ -1132,14 +1128,9 @@ int KWDataPreparationAttributeCompareSortValue(const void* elem1, const void* el check(dataPreparationAttribute2); assert(dataPreparationAttribute2->Check()); - // Evaluation univariee des attributs - dSortValue1 = dataPreparationAttribute1->GetPreparedStats()->GetSortValue(); - dSortValue2 = dataPreparationAttribute2->GetPreparedStats()->GetSortValue(); - - // On se base sur un comparaison a dix decimales pres - lSortValue1 = longint(floor(dSortValue1 * 1e10)); - lSortValue2 = longint(floor(dSortValue2 * 1e10)); - nCompare = -CompareLongint(lSortValue1, lSortValue2); + // Comparaison selon la precison du type Continuous, pour eviter les differences a epsilon pres + nCompare = -KWContinuous::CompareIndicatorValue(dataPreparationAttribute1->GetPreparedStats()->GetSortValue(), + dataPreparationAttribute2->GetPreparedStats()->GetSortValue()); // Comparaison si necessaire sur le nom if (nCompare == 0) diff --git a/src/Learning/KWModeling/KWPredictorReport.cpp b/src/Learning/KWModeling/KWPredictorReport.cpp index 3147f2cd9..92d492fec 100644 --- a/src/Learning/KWModeling/KWPredictorReport.cpp +++ b/src/Learning/KWModeling/KWPredictorReport.cpp @@ -424,22 +424,15 @@ int KWSelectedAttributeReport::CompareValue(const KWLearningReport* otherReport) { int nCompare; KWSelectedAttributeReport* otherAttributeReport = cast(KWSelectedAttributeReport*, otherReport); - longint lSortValue1; - longint lSortValue2; - // On se base sur un comparaison a dix decimales pres - lSortValue1 = longint(floor(fabs(GetImportance()) * 1e10)); - lSortValue2 = longint(floor(fabs(otherAttributeReport->GetImportance()) * 1e10)); - assert(lSortValue1 >= 0); - assert(lSortValue2 >= 0); - nCompare = -CompareLongint(lSortValue1, lSortValue2); + // Comparaison selon la precison du type Continuous, pour eviter les differences a epsilon pres + nCompare = -KWContinuous::CompareIndicatorValue(GetImportance(), otherAttributeReport->GetImportance()); // En cas d'egalite, on se base sur l'evaluation univariee if (nCompare == 0) { - lSortValue1 = longint(floor(fabs(GetUnivariateEvaluation()) * 1e10)); - lSortValue2 = longint(floor(fabs(otherAttributeReport->GetUnivariateEvaluation()) * 1e10)); - nCompare = -CompareLongint(lSortValue1, lSortValue2); + nCompare = -KWContinuous::CompareIndicatorValue(GetUnivariateEvaluation(), + otherAttributeReport->GetUnivariateEvaluation()); } // En cas d'egalite, on se base sur le nom