From a74efeffb84b76b5b61ebf7f370187863871793c Mon Sep 17 00:00:00 2001 From: Lukas E Date: Thu, 1 Oct 2020 14:29:38 +0200 Subject: [PATCH 01/15] Added BinArray Struct --- python/boomer/common/cpp/tuples.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/python/boomer/common/cpp/tuples.h b/python/boomer/common/cpp/tuples.h index d5585a0c89..4625c65d51 100644 --- a/python/boomer/common/cpp/tuples.h +++ b/python/boomer/common/cpp/tuples.h @@ -56,6 +56,11 @@ struct Bin { float32 maxValue; }; +struct BinArray { + uint32 numBins; + Bin* bins; +}; + namespace tuples { /** From 99b65818c18cd61151a3bddd9bfdadca174c5b71 Mon Sep 17 00:00:00 2001 From: Lukas E Date: Thu, 1 Oct 2020 14:36:14 +0200 Subject: [PATCH 02/15] Added ApproximateRuleRefinementImpl Class --- python/boomer/common/cpp/rule_refinement.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/python/boomer/common/cpp/rule_refinement.h b/python/boomer/common/cpp/rule_refinement.h index 038c9c7372..77a84fce66 100644 --- a/python/boomer/common/cpp/rule_refinement.h +++ b/python/boomer/common/cpp/rule_refinement.h @@ -107,3 +107,7 @@ class ExactRuleRefinementImpl : virtual public IRuleRefinement { uint32 numLabelIndices, const uint32* labelIndices) override; }; + +class ApproximateRuleRefinementImpl : virtual public IRuleRefinement { + +}; From 860d38ee99c0ac64aa61816f428df375880821ac Mon Sep 17 00:00:00 2001 From: Lukas E Date: Thu, 1 Oct 2020 15:34:09 +0200 Subject: [PATCH 03/15] Implemented basic structure of ApproximateRuleRefinementImpl --- python/boomer/common/cpp/rule_refinement.cpp | 14 ++++++++++++++ python/boomer/common/cpp/rule_refinement.h | 15 +++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/python/boomer/common/cpp/rule_refinement.cpp b/python/boomer/common/cpp/rule_refinement.cpp index c00a2a7ef2..4b5c9ada84 100644 --- a/python/boomer/common/cpp/rule_refinement.cpp +++ b/python/boomer/common/cpp/rule_refinement.cpp @@ -471,3 +471,17 @@ Refinement ExactRuleRefinementImpl::findRefinement(IHeadRefinement* headRefineme return refinement; } + +ApproximateRuleRefinementImpl::ApproximateRuleRefinementImpl(AbstractStatistics* statistics, BinArray* binArray, + uint32 featureIndex) { + statistics_ = statistics; + binArray_ = binArray; + featureIndex_ = featureIndex; +} + +Refinement ApproximateRuleRefinementImpl::findRefinement(IHeadRefinement* headRefinement, + PredictionCandidate* currentHead, + uint32 numLabelIndices, const uint32* labelIndices) { + Refinement refinement; + return refinement; +} diff --git a/python/boomer/common/cpp/rule_refinement.h b/python/boomer/common/cpp/rule_refinement.h index 77a84fce66..9f11138483 100644 --- a/python/boomer/common/cpp/rule_refinement.h +++ b/python/boomer/common/cpp/rule_refinement.h @@ -110,4 +110,19 @@ class ExactRuleRefinementImpl : virtual public IRuleRefinement { class ApproximateRuleRefinementImpl : virtual public IRuleRefinement { + private: + + AbstractStatistics* statistics_; + + BinArray* binArray_; + + uint32 featureIndex_; + + public: + + ApproximateRuleRefinementImpl(AbstractStatistics* statistics, BinArray* binArray, uint32 featureIndex); + + Refinement findRefinement(IHeadRefinement* headRefinement, PredictionCandidate* currentHead, + uint32 numLabelIndices, const uint32* labelIndices) override; + }; From 6f9af06d8e68fb46d19e94fb27ca0a6eb81032ee Mon Sep 17 00:00:00 2001 From: Lukas E Date: Fri, 2 Oct 2020 13:05:12 +0200 Subject: [PATCH 04/15] Implemented the main part of issue #252 --- python/boomer/common/cpp/rule_refinement.cpp | 66 ++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/python/boomer/common/cpp/rule_refinement.cpp b/python/boomer/common/cpp/rule_refinement.cpp index 4b5c9ada84..f135778ff5 100644 --- a/python/boomer/common/cpp/rule_refinement.cpp +++ b/python/boomer/common/cpp/rule_refinement.cpp @@ -482,6 +482,72 @@ ApproximateRuleRefinementImpl::ApproximateRuleRefinementImpl(AbstractStatistics* Refinement ApproximateRuleRefinementImpl::findRefinement(IHeadRefinement* headRefinement, PredictionCandidate* currentHead, uint32 numLabelIndices, const uint32* labelIndices) { + uint32 numBins = binArray_->numBins; Refinement refinement; + refinement.featureIndex = featureIndex_; + refinement.head = NULL; + refinement.indexedArray = NULL; + refinement.indexedArrayWrapper = NULL; + + PredictionCandidate* dynamicCurrentHead = currentHead; + + PredictionCandidate* bestHead = currentHead; + + std::unique_ptr statisticsSubsetPtr; + statisticsSubsetPtr.reset(statistics_->createSubset(numLabelIndices, labelIndices)); + + uint32 r = 0; + while(binArray_->bins[r].numExamples == 0 && r < numBins){ + r++; + } + statisticsSubsetPtr.get()->addToSubset(r, 1); + uint32 previousR = r; + float32 previousValue = binArray_->bins[r].maxValue; + uint32 numCoveredExamples = binArray_->bins[r].numExamples; + + r += 1; + for(r; r < numBins; r++){ + uint32 numExamples = binArray_->bins[r].numExamples; + + if(numExamples > 0){ + numCoveredExamples += numExamples; //Das sollten wir, anders wie im Pseudo Code, besser schon hier machen, oder? + float32 currentValue = binArray_->bins[r].minValue; + dynamicCurrentHead = headRefinement->findHead(bestHead, refinement.head, labelIndices, + statisticsSubsetPtr.get(), false, false); + + if(dynamicCurrentHead != NULL){ + bestHead = dynamicCurrentHead; + refinement.comparator = LEQ; + refinement.threshold = (previousValue + currentValue)/2.0; + refinement.start = 0; + refinement.end = r; + refinement.previous = previousR; + refinement.coveredWeights = numCoveredExamples; + refinement.covered = true; + } + + dynamicCurrentHead = headRefinement->findHead(bestHead, refinement.head, labelIndices, + statisticsSubsetPtr.get(), false, false); + + if(dynamicCurrentHead != NULL){ + bestHead = dynamicCurrentHead; + refinement.comparator = GR; + refinement.threshold = (previousValue + currentValue)/2.0; + refinement.start = 0; + refinement.end = r; + refinement.previous = previousR; + refinement.coveredWeights = numCoveredExamples; + refinement.covered = false; + } + + previousValue = binArray_->bins[r].maxValue; + previousR = r; + statisticsSubsetPtr.get()->addToSubset(r, 1); + + } + + } + + return refinement; } From a87cc21bdf6b84df0dbe2e354a6be80996cdbb78 Mon Sep 17 00:00:00 2001 From: Lukas E Date: Fri, 2 Oct 2020 13:09:28 +0200 Subject: [PATCH 05/15] Minor clean up and added a comment --- python/boomer/common/cpp/rule_refinement.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/python/boomer/common/cpp/rule_refinement.cpp b/python/boomer/common/cpp/rule_refinement.cpp index f135778ff5..b339718d94 100644 --- a/python/boomer/common/cpp/rule_refinement.cpp +++ b/python/boomer/common/cpp/rule_refinement.cpp @@ -497,6 +497,7 @@ Refinement ApproximateRuleRefinementImpl::findRefinement(IHeadRefinement* headRe statisticsSubsetPtr.reset(statistics_->createSubset(numLabelIndices, labelIndices)); uint32 r = 0; + //Search for the first not empty bin while(binArray_->bins[r].numExamples == 0 && r < numBins){ r++; } @@ -512,6 +513,7 @@ Refinement ApproximateRuleRefinementImpl::findRefinement(IHeadRefinement* headRe if(numExamples > 0){ numCoveredExamples += numExamples; //Das sollten wir, anders wie im Pseudo Code, besser schon hier machen, oder? float32 currentValue = binArray_->bins[r].minValue; + dynamicCurrentHead = headRefinement->findHead(bestHead, refinement.head, labelIndices, statisticsSubsetPtr.get(), false, false); @@ -539,15 +541,10 @@ Refinement ApproximateRuleRefinementImpl::findRefinement(IHeadRefinement* headRe refinement.coveredWeights = numCoveredExamples; refinement.covered = false; } - previousValue = binArray_->bins[r].maxValue; previousR = r; statisticsSubsetPtr.get()->addToSubset(r, 1); - } - } - - return refinement; } From 9865488b5e0dcef5114c55d671a5963c40cf7b98 Mon Sep 17 00:00:00 2001 From: Lukas E Date: Fri, 2 Oct 2020 14:52:00 +0200 Subject: [PATCH 06/15] Git Feedback --- python/boomer/common/cpp/rule_refinement.cpp | 23 ++++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/python/boomer/common/cpp/rule_refinement.cpp b/python/boomer/common/cpp/rule_refinement.cpp index b339718d94..fce015a36b 100644 --- a/python/boomer/common/cpp/rule_refinement.cpp +++ b/python/boomer/common/cpp/rule_refinement.cpp @@ -488,8 +488,7 @@ Refinement ApproximateRuleRefinementImpl::findRefinement(IHeadRefinement* headRe refinement.head = NULL; refinement.indexedArray = NULL; refinement.indexedArrayWrapper = NULL; - - PredictionCandidate* dynamicCurrentHead = currentHead; + refinement.start = 0; PredictionCandidate* bestHead = currentHead; @@ -511,31 +510,30 @@ Refinement ApproximateRuleRefinementImpl::findRefinement(IHeadRefinement* headRe uint32 numExamples = binArray_->bins[r].numExamples; if(numExamples > 0){ - numCoveredExamples += numExamples; //Das sollten wir, anders wie im Pseudo Code, besser schon hier machen, oder? float32 currentValue = binArray_->bins[r].minValue; - dynamicCurrentHead = headRefinement->findHead(bestHead, refinement.head, labelIndices, + PredictionCandidate* currentHead = headRefinement->findHead(bestHead, refinement.head, labelIndices, statisticsSubsetPtr.get(), false, false); - if(dynamicCurrentHead != NULL){ - bestHead = dynamicCurrentHead; + if(currentHead != NULL){ + bestHead = currentHead; + refinement.head = currentHead; refinement.comparator = LEQ; refinement.threshold = (previousValue + currentValue)/2.0; - refinement.start = 0; refinement.end = r; refinement.previous = previousR; refinement.coveredWeights = numCoveredExamples; refinement.covered = true; } - dynamicCurrentHead = headRefinement->findHead(bestHead, refinement.head, labelIndices, - statisticsSubsetPtr.get(), false, false); + currentHead = headRefinement->findHead(bestHead, refinement.head, labelIndices, + statisticsSubsetPtr.get(), true, false); - if(dynamicCurrentHead != NULL){ - bestHead = dynamicCurrentHead; + if(currentHead != NULL){ + bestHead = currentHead; + refinement.head = currentHead; refinement.comparator = GR; refinement.threshold = (previousValue + currentValue)/2.0; - refinement.start = 0; refinement.end = r; refinement.previous = previousR; refinement.coveredWeights = numCoveredExamples; @@ -543,6 +541,7 @@ Refinement ApproximateRuleRefinementImpl::findRefinement(IHeadRefinement* headRe } previousValue = binArray_->bins[r].maxValue; previousR = r; + numCoveredExamples += numExamples; statisticsSubsetPtr.get()->addToSubset(r, 1); } } From f6e4b94406261414860277a3738fc947af4d3b61 Mon Sep 17 00:00:00 2001 From: Lukas E Date: Fri, 2 Oct 2020 15:01:50 +0200 Subject: [PATCH 07/15] removed useless variable call --- python/boomer/common/cpp/rule_refinement.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/boomer/common/cpp/rule_refinement.cpp b/python/boomer/common/cpp/rule_refinement.cpp index fce015a36b..75dafc128f 100644 --- a/python/boomer/common/cpp/rule_refinement.cpp +++ b/python/boomer/common/cpp/rule_refinement.cpp @@ -506,7 +506,7 @@ Refinement ApproximateRuleRefinementImpl::findRefinement(IHeadRefinement* headRe uint32 numCoveredExamples = binArray_->bins[r].numExamples; r += 1; - for(r; r < numBins; r++){ + for(; r < numBins; r++){ uint32 numExamples = binArray_->bins[r].numExamples; if(numExamples > 0){ From 915a51f30625101d4b5c004c61b5e47f71a86410 Mon Sep 17 00:00:00 2001 From: Lukas E Date: Fri, 2 Oct 2020 18:13:06 +0200 Subject: [PATCH 08/15] First Part of Conflict elimination --- python/boomer/common/cpp/rule_refinement.cpp | 10 +++++----- python/boomer/common/cpp/rule_refinement.h | 9 ++++++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/python/boomer/common/cpp/rule_refinement.cpp b/python/boomer/common/cpp/rule_refinement.cpp index 9b9ac53f24..96999a4488 100644 --- a/python/boomer/common/cpp/rule_refinement.cpp +++ b/python/boomer/common/cpp/rule_refinement.cpp @@ -471,21 +471,21 @@ void ExactRuleRefinementImpl::findRefinement(IHeadRefinement* headRefinement, Pr } ApproximateRuleRefinementImpl::ApproximateRuleRefinementImpl(AbstractStatistics* statistics, BinArray* binArray, - uint32 featureIndex) { + uint32 featureIndex, + IRuleRefinementCallback* callback) { statistics_ = statistics; binArray_ = binArray; featureIndex_ = featureIndex; + callback_ = callback; } -Refinement ApproximateRuleRefinementImpl::findRefinement(IHeadRefinement* headRefinement, +void ApproximateRuleRefinementImpl::findRefinement(IHeadRefinement* headRefinement, PredictionCandidate* currentHead, uint32 numLabelIndices, const uint32* labelIndices) { uint32 numBins = binArray_->numBins; Refinement refinement; refinement.featureIndex = featureIndex_; refinement.head = NULL; - refinement.indexedArray = NULL; - refinement.indexedArrayWrapper = NULL; refinement.start = 0; PredictionCandidate* bestHead = currentHead; @@ -543,5 +543,5 @@ Refinement ApproximateRuleRefinementImpl::findRefinement(IHeadRefinement* headRe statisticsSubsetPtr.get()->addToSubset(r, 1); } } - return refinement; + bestRefinement_ = refinement; } diff --git a/python/boomer/common/cpp/rule_refinement.h b/python/boomer/common/cpp/rule_refinement.h index 5f29e62177..5c8c27f010 100644 --- a/python/boomer/common/cpp/rule_refinement.h +++ b/python/boomer/common/cpp/rule_refinement.h @@ -127,7 +127,7 @@ class ExactRuleRefinementImpl : public AbstractRuleRefinement { }; -class ApproximateRuleRefinementImpl : virtual public IRuleRefinement { +class ApproximateRuleRefinementImpl : public AbstractRuleRefinement { private: @@ -137,11 +137,14 @@ class ApproximateRuleRefinementImpl : virtual public IRuleRefinement { uint32 featureIndex_; + IRuleRefinementCallback* callback_; + public: - ApproximateRuleRefinementImpl(AbstractStatistics* statistics, BinArray* binArray, uint32 featureIndex); + ApproximateRuleRefinementImpl(AbstractStatistics* statistics, BinArray* binArray, uint32 featureIndex, + IRuleRefinementCallback* callback); - Refinement findRefinement(IHeadRefinement* headRefinement, PredictionCandidate* currentHead, + void findRefinement(IHeadRefinement* headRefinement, PredictionCandidate* currentHead, uint32 numLabelIndices, const uint32* labelIndices) override; }; From d332c6d8ecbdce1ceef3b5ed2f84d77cdc2b576b Mon Sep 17 00:00:00 2001 From: Lukas E Date: Sat, 3 Oct 2020 11:46:53 +0200 Subject: [PATCH 09/15] Faulty Commit, Question in issue #254 --- python/boomer/common/cpp/rule_refinement.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/python/boomer/common/cpp/rule_refinement.cpp b/python/boomer/common/cpp/rule_refinement.cpp index 96999a4488..009bc29280 100644 --- a/python/boomer/common/cpp/rule_refinement.cpp +++ b/python/boomer/common/cpp/rule_refinement.cpp @@ -470,11 +470,9 @@ void ExactRuleRefinementImpl::findRefinement(IHeadRefinement* headRefinement, Pr } } -ApproximateRuleRefinementImpl::ApproximateRuleRefinementImpl(AbstractStatistics* statistics, BinArray* binArray, - uint32 featureIndex, +ApproximateRuleRefinementImpl::ApproximateRuleRefinementImpl(AbstractStatistics* statistics, uint32 featureIndex, IRuleRefinementCallback* callback) { statistics_ = statistics; - binArray_ = binArray; featureIndex_ = featureIndex; callback_ = callback; } @@ -482,7 +480,8 @@ ApproximateRuleRefinementImpl::ApproximateRuleRefinementImpl(AbstractStatistics* void ApproximateRuleRefinementImpl::findRefinement(IHeadRefinement* headRefinement, PredictionCandidate* currentHead, uint32 numLabelIndices, const uint32* labelIndices) { - uint32 numBins = binArray_->numBins; + BinArray* binArray = callback_->get(0); + uint32 numBins = binArray->numBins; Refinement refinement; refinement.featureIndex = featureIndex_; refinement.head = NULL; @@ -495,20 +494,20 @@ void ApproximateRuleRefinementImpl::findRefinement(IHeadRefinement* headRefineme uint32 r = 0; //Search for the first not empty bin - while(binArray_->bins[r].numExamples == 0 && r < numBins){ + while(binArray->bins[r].numExamples == 0 && r < numBins){ r++; } statisticsSubsetPtr.get()->addToSubset(r, 1); uint32 previousR = r; - float32 previousValue = binArray_->bins[r].maxValue; - uint32 numCoveredExamples = binArray_->bins[r].numExamples; + float32 previousValue = binArray->bins[r].maxValue; + uint32 numCoveredExamples = binArray->bins[r].numExamples; r += 1; for(; r < numBins; r++){ - uint32 numExamples = binArray_->bins[r].numExamples; + uint32 numExamples = binArray->bins[r].numExamples; if(numExamples > 0){ - float32 currentValue = binArray_->bins[r].minValue; + float32 currentValue = binArray->bins[r].minValue; PredictionCandidate* currentHead = headRefinement->findHead(bestHead, refinement.head, labelIndices, statisticsSubsetPtr.get(), false, false); @@ -537,7 +536,7 @@ void ApproximateRuleRefinementImpl::findRefinement(IHeadRefinement* headRefineme refinement.coveredWeights = numCoveredExamples; refinement.covered = false; } - previousValue = binArray_->bins[r].maxValue; + previousValue = binArray->bins[r].maxValue; previousR = r; numCoveredExamples += numExamples; statisticsSubsetPtr.get()->addToSubset(r, 1); From c6d0c6391604719b07957722cd949decdc80bf93 Mon Sep 17 00:00:00 2001 From: Lukas E Date: Sat, 3 Oct 2020 13:12:03 +0200 Subject: [PATCH 10/15] Corrected callback --- python/boomer/common/cpp/rule_refinement.cpp | 2 +- python/boomer/common/cpp/rule_refinement.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/python/boomer/common/cpp/rule_refinement.cpp b/python/boomer/common/cpp/rule_refinement.cpp index 009bc29280..46967af368 100644 --- a/python/boomer/common/cpp/rule_refinement.cpp +++ b/python/boomer/common/cpp/rule_refinement.cpp @@ -471,7 +471,7 @@ void ExactRuleRefinementImpl::findRefinement(IHeadRefinement* headRefinement, Pr } ApproximateRuleRefinementImpl::ApproximateRuleRefinementImpl(AbstractStatistics* statistics, uint32 featureIndex, - IRuleRefinementCallback* callback) { + IRuleRefinementCallback* callback) { statistics_ = statistics; featureIndex_ = featureIndex; callback_ = callback; diff --git a/python/boomer/common/cpp/rule_refinement.h b/python/boomer/common/cpp/rule_refinement.h index 5c8c27f010..8831436d13 100644 --- a/python/boomer/common/cpp/rule_refinement.h +++ b/python/boomer/common/cpp/rule_refinement.h @@ -137,12 +137,12 @@ class ApproximateRuleRefinementImpl : public AbstractRuleRefinement { uint32 featureIndex_; - IRuleRefinementCallback* callback_; + IRuleRefinementCallback* callback_; public: - ApproximateRuleRefinementImpl(AbstractStatistics* statistics, BinArray* binArray, uint32 featureIndex, - IRuleRefinementCallback* callback); + ApproximateRuleRefinementImpl(AbstractStatistics* statistics, uint32 featureIndex, + IRuleRefinementCallback* callback); void findRefinement(IHeadRefinement* headRefinement, PredictionCandidate* currentHead, uint32 numLabelIndices, const uint32* labelIndices) override; From a59c53f7aea1e18352926d053f02234bc4ffd37a Mon Sep 17 00:00:00 2001 From: Michael Rapp Date: Mon, 5 Oct 2020 13:31:19 +0200 Subject: [PATCH 11/15] Add comment. --- python/boomer/common/cpp/tuples.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/python/boomer/common/cpp/tuples.h b/python/boomer/common/cpp/tuples.h index 4625c65d51..75c4a1d184 100644 --- a/python/boomer/common/cpp/tuples.h +++ b/python/boomer/common/cpp/tuples.h @@ -56,6 +56,10 @@ struct Bin { float32 maxValue; }; +/** + * A structs that contains a pointer to an array of type `Bin`. The attribute `numBins` specifies how many elements the + * array contains. + */ struct BinArray { uint32 numBins; Bin* bins; From 3947db8e1450f55fa686e6da109712a550ff4938 Mon Sep 17 00:00:00 2001 From: Michael Rapp Date: Mon, 5 Oct 2020 13:31:35 +0200 Subject: [PATCH 12/15] Add author. --- python/boomer/common/cpp/rule_refinement.h | 1 + 1 file changed, 1 insertion(+) diff --git a/python/boomer/common/cpp/rule_refinement.h b/python/boomer/common/cpp/rule_refinement.h index 8831436d13..d325de538d 100644 --- a/python/boomer/common/cpp/rule_refinement.h +++ b/python/boomer/common/cpp/rule_refinement.h @@ -2,6 +2,7 @@ * Implements classes that allow to find the best refinement of rules. * * @author Michael Rapp (mrapp@ke.tu-darmstadt.de) + * @author Lukas Johannes Eberle (lukasjohannes.eberle@stud.tu-darmstadt.de) */ #pragma once From 07a7b519a2d700b39716f7a8aeb369fb26cd92e8 Mon Sep 17 00:00:00 2001 From: Michael Rapp Date: Mon, 5 Oct 2020 13:31:59 +0200 Subject: [PATCH 13/15] Add comments. --- python/boomer/common/cpp/rule_refinement.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/python/boomer/common/cpp/rule_refinement.h b/python/boomer/common/cpp/rule_refinement.h index d325de538d..f001ba6af2 100644 --- a/python/boomer/common/cpp/rule_refinement.h +++ b/python/boomer/common/cpp/rule_refinement.h @@ -128,6 +128,11 @@ class ExactRuleRefinementImpl : public AbstractRuleRefinement { }; +/** + * Allows to find the best refinements of existing rules, which result from adding a new condition that correspond to a + * certain feature. The thresholds that may be used by the new condition result from the bins that have been created + * using a binning method. + */ class ApproximateRuleRefinementImpl : public AbstractRuleRefinement { private: @@ -142,6 +147,13 @@ class ApproximateRuleRefinementImpl : public AbstractRuleRefinement { public: + /** + * @param statistics A pointer to an object of type `AbstractStatistics` that provides access to the + * statistics which serve as the basis for evaluating the potential refinements of rules + * @param featureIndex The index of the feature, the new condition corresponds to + * @param callback A pointer to an object of type `IRuleRefinementCallback` that allows to + * retrieve the information that is required to identify potential refinements + */ ApproximateRuleRefinementImpl(AbstractStatistics* statistics, uint32 featureIndex, IRuleRefinementCallback* callback); From 5813cf29d401ed7c2f73cf12d8869a6fa0426631 Mon Sep 17 00:00:00 2001 From: Michael Rapp Date: Mon, 5 Oct 2020 13:32:23 +0200 Subject: [PATCH 14/15] Add missing destructor. --- python/boomer/common/cpp/rule_refinement.cpp | 9 ++++++--- python/boomer/common/cpp/rule_refinement.h | 2 ++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/python/boomer/common/cpp/rule_refinement.cpp b/python/boomer/common/cpp/rule_refinement.cpp index 46967af368..2bec5f29e1 100644 --- a/python/boomer/common/cpp/rule_refinement.cpp +++ b/python/boomer/common/cpp/rule_refinement.cpp @@ -477,9 +477,12 @@ ApproximateRuleRefinementImpl::ApproximateRuleRefinementImpl(AbstractStatistics* callback_ = callback; } -void ApproximateRuleRefinementImpl::findRefinement(IHeadRefinement* headRefinement, - PredictionCandidate* currentHead, - uint32 numLabelIndices, const uint32* labelIndices) { +~ApproximateRuleRefinementImpl::ApproximateRuleRefinementImpl() { + delete callback_; +} + +void ApproximateRuleRefinementImpl::findRefinement(IHeadRefinement* headRefinement, PredictionCandidate* currentHead, + uint32 numLabelIndices, const uint32* labelIndices) { BinArray* binArray = callback_->get(0); uint32 numBins = binArray->numBins; Refinement refinement; diff --git a/python/boomer/common/cpp/rule_refinement.h b/python/boomer/common/cpp/rule_refinement.h index f001ba6af2..8f378a740c 100644 --- a/python/boomer/common/cpp/rule_refinement.h +++ b/python/boomer/common/cpp/rule_refinement.h @@ -157,6 +157,8 @@ class ApproximateRuleRefinementImpl : public AbstractRuleRefinement { ApproximateRuleRefinementImpl(AbstractStatistics* statistics, uint32 featureIndex, IRuleRefinementCallback* callback); + ~ApproximateRuleRefinementImpl(); + void findRefinement(IHeadRefinement* headRefinement, PredictionCandidate* currentHead, uint32 numLabelIndices, const uint32* labelIndices) override; From fc678d57728b10659daa7a0f92f1806e4a32c4b1 Mon Sep 17 00:00:00 2001 From: Michael Rapp Date: Mon, 5 Oct 2020 13:37:49 +0200 Subject: [PATCH 15/15] Format code. --- python/boomer/common/cpp/rule_refinement.cpp | 27 +++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/python/boomer/common/cpp/rule_refinement.cpp b/python/boomer/common/cpp/rule_refinement.cpp index 2bec5f29e1..043e5a0927 100644 --- a/python/boomer/common/cpp/rule_refinement.cpp +++ b/python/boomer/common/cpp/rule_refinement.cpp @@ -495,55 +495,58 @@ void ApproximateRuleRefinementImpl::findRefinement(IHeadRefinement* headRefineme std::unique_ptr statisticsSubsetPtr; statisticsSubsetPtr.reset(statistics_->createSubset(numLabelIndices, labelIndices)); - uint32 r = 0; //Search for the first not empty bin - while(binArray->bins[r].numExamples == 0 && r < numBins){ + uint32 r = 0; + + while (binArray->bins[r].numExamples == 0 && r < numBins) { r++; } + statisticsSubsetPtr.get()->addToSubset(r, 1); uint32 previousR = r; float32 previousValue = binArray->bins[r].maxValue; uint32 numCoveredExamples = binArray->bins[r].numExamples; - r += 1; - for(; r < numBins; r++){ + for (r = r + 1; r < numBins; r++) { uint32 numExamples = binArray->bins[r].numExamples; - if(numExamples > 0){ + if (numExamples > 0) { float32 currentValue = binArray->bins[r].minValue; PredictionCandidate* currentHead = headRefinement->findHead(bestHead, refinement.head, labelIndices, - statisticsSubsetPtr.get(), false, false); + statisticsSubsetPtr.get(), false, false); - if(currentHead != NULL){ + if (currentHead != NULL) { bestHead = currentHead; refinement.head = currentHead; refinement.comparator = LEQ; - refinement.threshold = (previousValue + currentValue)/2.0; + refinement.threshold = (previousValue + currentValue) / 2.0; refinement.end = r; refinement.previous = previousR; refinement.coveredWeights = numCoveredExamples; refinement.covered = true; } - currentHead = headRefinement->findHead(bestHead, refinement.head, labelIndices, - statisticsSubsetPtr.get(), true, false); + currentHead = headRefinement->findHead(bestHead, refinement.head, labelIndices, statisticsSubsetPtr.get(), + true, false); - if(currentHead != NULL){ + if (currentHead != NULL) { bestHead = currentHead; refinement.head = currentHead; refinement.comparator = GR; - refinement.threshold = (previousValue + currentValue)/2.0; + refinement.threshold = (previousValue + currentValue) / 2.0; refinement.end = r; refinement.previous = previousR; refinement.coveredWeights = numCoveredExamples; refinement.covered = false; } + previousValue = binArray->bins[r].maxValue; previousR = r; numCoveredExamples += numExamples; statisticsSubsetPtr.get()->addToSubset(r, 1); } } + bestRefinement_ = refinement; }