CutPoints intervals have at least 2 samples

This commit is contained in:
2022-12-04 10:54:44 +01:00
parent 5cce895177
commit 61e777495b
2 changed files with 16 additions and 17 deletions

View File

@@ -100,7 +100,7 @@ namespace mdlp {
void CPPFImdlp::filterCutPoints() void CPPFImdlp::filterCutPoints()
{ {
cutPoints_t filtered; cutPoints_t filtered;
cutPoint_t rest; cutPoint_t rest, item;
int classNumber = 0; int classNumber = 0;
rest.start = 0; rest.start = 0;
@@ -108,31 +108,30 @@ namespace mdlp {
rest.fromValue = std::numeric_limits<float>::lowest(); rest.fromValue = std::numeric_limits<float>::lowest();
rest.toValue = std::numeric_limits<float>::max(); rest.toValue = std::numeric_limits<float>::max();
rest.classNumber = classNumber; rest.classNumber = classNumber;
bool lastReject = false, first = true; bool first = true;
for (auto item : cutPoints) { for (size_t index = 0; index < size_t(cutPoints.size()); index++) {
item = cutPoints[index];
if (evaluateCutPoint(rest, item)) { if (evaluateCutPoint(rest, item)) {
if (debug) if (debug)
std::cout << "Accepted" << std::endl; std::cout << "Accepted: " << item << std::endl;
if (lastReject) {
//Try to merge rejected intervals
if (first) {
item.fromValue = std::numeric_limits<float>::lowest();
item.start = indices[0];
} else {
item.fromValue = filtered.back().toValue;
item.start = filtered.back().end;
}
}
//Assign class number to the interval (cutpoint) //Assign class number to the interval (cutpoint)
item.classNumber = classNumber++; item.classNumber = classNumber++;
filtered.push_back(item); filtered.push_back(item);
first = false; first = false;
rest.start = item.end; rest.start = item.end;
lastReject = false;
} else { } else {
if (debug) if (debug)
std::cout << "Rejected" << std::endl; std::cout << "Rejected: " << item << std::endl;
lastReject = true; if (index != size_t(cutPoints.size()) - 1) {
// Try to merge the rejected cutpoint with the next one
if (first) {
cutPoints[index + 1].fromValue = std::numeric_limits<float>::lowest();
cutPoints[index + 1].start = indices[0];
} else {
cutPoints[index + 1].fromValue = item.fromValue;
cutPoints[index + 1].start = item.start;
}
}
} }
} }
if (!first) { if (!first) {