Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suche nach Refinements auf der Basis von Bins #254

Merged
merged 16 commits into from
Oct 5, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions python/boomer/common/cpp/rule_refinement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,3 +471,80 @@ 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) {
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<IStatisticsSubset> 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){
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?
michael-rapp marked this conversation as resolved.
Show resolved Hide resolved
float32 currentValue = binArray_->bins[r].minValue;

dynamicCurrentHead = headRefinement->findHead(bestHead, refinement.head, labelIndices,
statisticsSubsetPtr.get(), false, false);
michael-rapp marked this conversation as resolved.
Show resolved Hide resolved

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;
michael-rapp marked this conversation as resolved.
Show resolved Hide resolved
}

dynamicCurrentHead = headRefinement->findHead(bestHead, refinement.head, labelIndices,
statisticsSubsetPtr.get(), false, false);
michael-rapp marked this conversation as resolved.
Show resolved Hide resolved

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;
michael-rapp marked this conversation as resolved.
Show resolved Hide resolved
refinement.covered = false;
}
previousValue = binArray_->bins[r].maxValue;
previousR = r;
statisticsSubsetPtr.get()->addToSubset(r, 1);
}
}
return refinement;
}
19 changes: 19 additions & 0 deletions python/boomer/common/cpp/rule_refinement.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,22 @@ class ExactRuleRefinementImpl : virtual public IRuleRefinement {
uint32 numLabelIndices, const uint32* labelIndices) override;

};

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;

};
5 changes: 5 additions & 0 deletions python/boomer/common/cpp/tuples.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ struct Bin {
float32 maxValue;
};

struct BinArray {
uint32 numBins;
Bin* bins;
};

namespace tuples {

/**
Expand Down