Skip to content

Commit

Permalink
WIP Step 13
Browse files Browse the repository at this point in the history
Correction dans les algoithme d'optimisation:
- partout, tester l'amelioration du cout en remplacant ~if (dCost < dBestCost)~ par ~if (dCost < dBestCost - dEpsilon)~
- impacts:
  - DTDiscretizerMODL::DiscretizeNEW
  - DTDiscretizerMODL::DiscretizeOLD
  - DTDiscretizerMODL::DiscretizeGranularizedFrequencyTableNEW (pour le nul cost: < dBestCost + dEpsilon)
  - DTGrouperMODL::GroupPreprocessedTable
  - DTGrouperMODL::SmallSourceNumberGroup
  - KWDiscretizerMODL::Discretize
  - KWGrouperMODL::GroupPreprocessedTable
  - KWGrouperMODL::SmallSourceNumberGroup
  - KWDensityEstimationTest::SearchBestInstanceGridSize
  - MHDiscretizerHistogramMODL::GranularizedDiscretizeValues
  - MHDiscretizerHistogramMODL_fp::OptimizeGranularity
  - MHFloatingPointFrequencyTableBuilder::InitializeDomainBounds
  • Loading branch information
marcboulle committed Jan 17, 2024
1 parent 230d40f commit 0cc0940
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 18 deletions.
8 changes: 4 additions & 4 deletions src/Learning/DTForest/DTDiscretizerMODL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ void DTDiscretizerMODL::DiscretizeNEW(KWFrequencyTable* kwftSource, KWFrequencyT
// delete kwftMergedTable;
// kwftMergedTable = NULL;

if (dCost < dBestCost)
if (dCost < dBestCost - dEpsilon)
{
dBestCost = dCost;
// Destruction de l'optimum precedent
Expand Down Expand Up @@ -469,7 +469,7 @@ void DTDiscretizerMODL::DiscretizeOLD(KWFrequencyTable* kwftSource, KWFrequencyT
delete kwftMergedTable;
kwftMergedTable = NULL;

if (dCost < dBestCost)
if (dCost < dBestCost - dEpsilon)
{
dBestCost = dCost;
// Destruction de l'optimum precedent
Expand Down Expand Up @@ -630,7 +630,7 @@ void DTDiscretizerMODL::DiscretizeGranularizedFrequencyTableNEW(KWFrequencyTable
kwdfvSourceFrequencyVectortarget1->CopyFrom(kwdfvSourceFrequencyVector1);
nvfmax = nfv;
}
if (dCost < dBestCost)
if (dCost < dBestCost - dEpsilon)
{
// cout << "cout best " << nfv + 1 << " : " << dCost << endl;
dBestCost = dCost;
Expand All @@ -643,7 +643,7 @@ void DTDiscretizerMODL::DiscretizeGranularizedFrequencyTableNEW(KWFrequencyTable

// cout << "nvfmax / nsourcesize : " << nvfmax << " / " << nsourcesize << endl;

if (dCostnull < dBestCost)
if (dCostnull < dBestCost + dEpsilon)
{
// cout << "NULL Cost" << endl;
// cout << "cout best " << nfv + 1 << " : " << dCost << endl;
Expand Down
8 changes: 4 additions & 4 deletions src/Learning/DTForest/DTGrouperMODL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ void DTGrouperMODL::GroupPreprocessedTable(KWFrequencyTable* kwftSource, KWFrequ
dCost = ComputeGroupingCost(kwftOptimizedGranularizedTable, nCurrentPartileNumber);

// Cas de l'amelioration du cout
if (dCost < dBestCost)
if (dCost < dBestCost - dEpsilon)
{
// Memorisation du cout optimal
dBestCost = dCost;
Expand Down Expand Up @@ -715,7 +715,7 @@ void DTGrouperMODL::SmallSourceNumberGroup(KWFrequencyTable* kwftSource, KWFrequ
MergeFrequencyVectors(workingFrequencyVector, kwftSource->GetFrequencyVectorAt(1),
kwftSource->GetFrequencyVectorAt(2));
dCost = ComputeGroupCost(workingFrequencyVector) + dCostGroup0;
if (dCost < dBestCost)
if (dCost < dBestCost - dEpsilon)
{
dBestCost = dCost;
nBestTwoGroupsIndex = 0;
Expand All @@ -724,7 +724,7 @@ void DTGrouperMODL::SmallSourceNumberGroup(KWFrequencyTable* kwftSource, KWFrequ
MergeFrequencyVectors(workingFrequencyVector, kwftSource->GetFrequencyVectorAt(0),
kwftSource->GetFrequencyVectorAt(2));
dCost = ComputeGroupCost(workingFrequencyVector) + dCostGroup1;
if (dCost < dBestCost)
if (dCost < dBestCost - dEpsilon)
{
dBestCost = dCost;
nBestTwoGroupsIndex = 1;
Expand All @@ -733,7 +733,7 @@ void DTGrouperMODL::SmallSourceNumberGroup(KWFrequencyTable* kwftSource, KWFrequ
MergeFrequencyVectors(workingFrequencyVector, kwftSource->GetFrequencyVectorAt(0),
kwftSource->GetFrequencyVectorAt(1));
dCost = ComputeGroupCost(workingFrequencyVector) + dCostGroup2;
if (dCost < dBestCost)
if (dCost < dBestCost - dEpsilon)
{
dBestCost = dCost;
nBestTwoGroupsIndex = 2;
Expand Down
2 changes: 1 addition & 1 deletion src/Learning/KWDataPreparation/KWDiscretizerMODL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ void KWDiscretizerMODL::Discretize(KWFrequencyTable* kwftSource, KWFrequencyTabl
delete kwftMergedTable;
kwftMergedTable = NULL;

if (dCost < dBestCost)
if (dCost < dBestCost - dEpsilon)
{
dBestCost = dCost;
// Destruction de l'optimum precedent
Expand Down
8 changes: 4 additions & 4 deletions src/Learning/KWDataPreparation/KWGrouperMODL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ void KWGrouperMODL::GroupPreprocessedTable(KWFrequencyTable* kwftSource, KWFrequ
dCost = ComputeGroupingCost(kwftOptimizedGranularizedTable, nCurrentPartileNumber);

// Cas de l'amelioration du cout
if (dCost < dBestCost)
if (dCost < dBestCost - dEpsilon)
{
// Memorisation du cout optimal
dBestCost = dCost;
Expand Down Expand Up @@ -813,7 +813,7 @@ void KWGrouperMODL::SmallSourceNumberGroup(KWFrequencyTable* kwftSource, KWFrequ
MergeFrequencyVectors(workingFrequencyVector, kwftSource->GetFrequencyVectorAt(1),
kwftSource->GetFrequencyVectorAt(2));
dCost = ComputeGroupCost(workingFrequencyVector) + dCostGroup0;
if (dCost < dBestCost)
if (dCost < dBestCost - dEpsilon)
{
dBestCost = dCost;
nBestTwoGroupsIndex = 0;
Expand All @@ -822,7 +822,7 @@ void KWGrouperMODL::SmallSourceNumberGroup(KWFrequencyTable* kwftSource, KWFrequ
MergeFrequencyVectors(workingFrequencyVector, kwftSource->GetFrequencyVectorAt(0),
kwftSource->GetFrequencyVectorAt(2));
dCost = ComputeGroupCost(workingFrequencyVector) + dCostGroup1;
if (dCost < dBestCost)
if (dCost < dBestCost - dEpsilon)
{
dBestCost = dCost;
nBestTwoGroupsIndex = 1;
Expand All @@ -831,7 +831,7 @@ void KWGrouperMODL::SmallSourceNumberGroup(KWFrequencyTable* kwftSource, KWFrequ
MergeFrequencyVectors(workingFrequencyVector, kwftSource->GetFrequencyVectorAt(0),
kwftSource->GetFrequencyVectorAt(1));
dCost = ComputeGroupCost(workingFrequencyVector) + dCostGroup2;
if (dCost < dBestCost)
if (dCost < dBestCost - dEpsilon)
{
dBestCost = dCost;
nBestTwoGroupsIndex = 2;
Expand Down
2 changes: 1 addition & 1 deletion src/Learning/KWTest/KWDensityEstimationTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ int KWDensityEstimationTest::SearchBestInstanceGridSize(ContinuousVector* cvXVal
cout << nAxisCellNumber << "\t" << dCost << endl;

// Test si amelioration
if (dCost < dBestCost)
if (dCost < dBestCost - dEpsilon)
{
dBestCost = dCost;
nBestAxisCellNumber = nAxisCellNumber;
Expand Down
2 changes: 1 addition & 1 deletion src/Learning/MHHistograms/MHDiscretizerHistogramMODL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ void MHDiscretizerHistogramMODL::GranularizedDiscretizeValues(const ContinuousVe
<< KWContinuous::ContinuousToString(dCost) << endl;

// Memorisation si amelioration du cout
if (dCost < dBestCost)
if (dCost < dBestCost - dEpsilon)
{
dBestCost = dCost;
if (optimizedHistogramFrequencyTable != NULL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ void MHDiscretizerHistogramMODL_fp::OptimizeGranularity(MHHistogram*& optimizedH
delete optimizedHistogramFrequencyTable;

// Memorisation si amelioration du cout
if (dCost < dBestCost)
if (dCost < dBestCost - dEpsilon)
{
dBestCost = dCost;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2127,6 +2127,7 @@ int MHFloatingPointFrequencyTableBuilder::SearchBinIndex(int nSearchedCumulative
void MHFloatingPointFrequencyTableBuilder::InitializeDomainBounds()
{
boolean bDisplay = false;
const double dEpsilon = 1e-7;
int nTotalFrequency;
int i;
double dBestCost;
Expand Down Expand Up @@ -2172,13 +2173,13 @@ void MHFloatingPointFrequencyTableBuilder::InitializeDomainBounds()
cout << KWContinuous::ContinuousToString(cUpperBound - GetMaxValue()) << "\t";
cout << dCost << "\t";
cout << dBestCost << "\t";
if (dCost < dBestCost)
if (dCost < dBestCost - dEpsilon)
cout << "Best";
cout << "\n";
}

// Memorisation si amelioration
if (dCost < dBestCost)
if (dCost < dBestCost - dEpsilon)
{
dBestCost = dCost;

Expand Down

0 comments on commit 0cc0940

Please sign in to comment.