diff --git a/cpp/subprojects/seco/include/mlrl/seco/data/matrix_coverage_dense.hpp b/cpp/subprojects/seco/include/mlrl/seco/data/matrix_coverage_dense.hpp index 206d38f032..ecaa4f061b 100644 --- a/cpp/subprojects/seco/include/mlrl/seco/data/matrix_coverage_dense.hpp +++ b/cpp/subprojects/seco/include/mlrl/seco/data/matrix_coverage_dense.hpp @@ -39,15 +39,18 @@ namespace seco { * Increases the number of times the elements at a specific row of this matrix are covered, given the * predictions of a rule that predicts for all available labels. * - * @param row The row - * @param majorityLabelIndices A reference to an object of type `VectorConstView` that stores the indices - * of the labels that are relevant to the majority of the training examples - * @param predictionBegin An iterator to the beginning of the predictions - * @param predictionEnd An iterator to the end of the predictions - * @param indicesBegin An iterator to the beginning of the label indices - * @param indicesEnd An iterator to the end of the label indices + * @param row The row + * @param majorityLabelIndicesBegin An iterator to the beginning of the indices of the labels that are + * relevant to the majority of the training examples + * @param majorityLabelIndicesEnd An iterator to the end of the indices of the labels that are relevant + * to the majority of the training examples + * @param predictionBegin An iterator to the beginning of the predictions + * @param predictionEnd An iterator to the end of the predictions + * @param indicesBegin An iterator to the beginning of the label indices + * @param indicesEnd An iterator to the end of the label indices */ - void increaseCoverage(uint32 row, const VectorConstView& majorityLabelIndices, + void increaseCoverage(uint32 row, VectorConstView::const_iterator majorityLabelIndicesBegin, + VectorConstView::const_iterator majorityLabelIndicesEnd, VectorView::const_iterator predictionBegin, VectorView::const_iterator predictionEnd, CompleteIndexVector::const_iterator indicesBegin, @@ -57,15 +60,18 @@ namespace seco { * Increases the number of times the elements at a specific row of this matrix are covered, given the * predictions of a rule that predicts for a subset of the available labels. * - * @param row The row - * @param majorityLabelIndices A reference to an object of type `VectorConstView` that stores the indices - * of the labels that are relevant to the majority of the training examples - * @param predictionBegin An iterator to the beginning of the predictions - * @param predictionEnd An iterator to the end of the predictions - * @param indicesBegin An iterator to the beginning of the label indices - * @param indicesEnd An iterator to the end of the label indices + * @param row The row + * @param majorityLabelIndicesBegin An iterator to the beginning of the indices of the labels that are + * relevant to the majority of the training examples + * @param majorityLabelIndicesEnd An iterator to the end of the indices of the labels that are relevant + * to the majority of the training examples + * @param predictionBegin An iterator to the beginning of the predictions + * @param predictionEnd An iterator to the end of the predictions + * @param indicesBegin An iterator to the beginning of the label indices + * @param indicesEnd An iterator to the end of the label indices */ - void increaseCoverage(uint32 row, const VectorConstView& majorityLabelIndices, + void increaseCoverage(uint32 row, VectorConstView::const_iterator majorityLabelIndicesBegin, + VectorConstView::const_iterator majorityLabelIndicesEnd, VectorView::const_iterator predictionBegin, VectorView::const_iterator predictionEnd, PartialIndexVector::const_iterator indicesBegin, @@ -75,15 +81,18 @@ namespace seco { * Decreases the number of times the elements at a specific row of this matrix are covered, given the * predictions of a rule that predicts for all available labels. * - * @param row The row - * @param majorityLabelIndices A reference to an object of type `VectorConstView` that stores the indices - * of the labels that are relevant to the majority of the training examples - * @param predictionBegin An iterator to the beginning of the predictions - * @param predictionEnd An iterator to the end of the predictions - * @param indicesBegin An iterator to the beginning of the label indices - * @param indicesEnd An iterator to the end of the label indices + * @param row The row + * @param majorityLabelIndicesBegin An iterator to the beginning of the indices of the labels that are + * relevant to the majority of the training examples + * @param majorityLabelIndicesEnd An iterator to the end of the indices of the labels that are relevant + * to the majority of the training examples + * @param predictionBegin An iterator to the beginning of the predictions + * @param predictionEnd An iterator to the end of the predictions + * @param indicesBegin An iterator to the beginning of the label indices + * @param indicesEnd An iterator to the end of the label indices */ - void decreaseCoverage(uint32 row, const VectorConstView& majorityLabelIndices, + void decreaseCoverage(uint32 row, VectorConstView::const_iterator majorityLabelIndicesBegin, + VectorConstView::const_iterator majorityLabelIndicesEnd, VectorView::const_iterator predictionBegin, VectorView::const_iterator predictionEnd, CompleteIndexVector::const_iterator indicesBegin, @@ -93,15 +102,18 @@ namespace seco { * Decreases the number of times the elements at a specific row of this matrix are covered, given the * predictions of a rule that predicts for a subset of the available labels. * - * @param row The row - * @param majorityLabelIndices A reference to an object of type `VectorConstView` that stores the indices - * of the labels that are relevant to the majority of the training examples - * @param predictionBegin An iterator to the beginning of the predictions - * @param predictionEnd An iterator to the end of the predictions - * @param indicesBegin An iterator to the beginning of the label indices - * @param indicesEnd An iterator to the end of the label indices + * @param row The row + * @param majorityLabelIndicesBegin An iterator to the beginning of the indices of the labels that are + * relevant to the majority of the training examples + * @param majorityLabelIndicesEnd An iterator to the end of the indices of the labels that are relevant + * to the majority of the training examples + * @param predictionBegin An iterator to the beginning of the predictions + * @param predictionEnd An iterator to the end of the predictions + * @param indicesBegin An iterator to the beginning of the label indices + * @param indicesEnd An iterator to the end of the label indices */ - void decreaseCoverage(uint32 row, const VectorConstView& majorityLabelIndices, + void decreaseCoverage(uint32 row, VectorConstView::const_iterator majorityLabelIndicesBegin, + VectorConstView::const_iterator majorityLabelIndicesEnd, VectorView::const_iterator predictionBegin, VectorView::const_iterator predictionEnd, PartialIndexVector::const_iterator indicesBegin, diff --git a/cpp/subprojects/seco/include/mlrl/seco/data/vector_confusion_matrix_dense.hpp b/cpp/subprojects/seco/include/mlrl/seco/data/vector_confusion_matrix_dense.hpp index b3c9e73898..4f07aa4121 100644 --- a/cpp/subprojects/seco/include/mlrl/seco/data/vector_confusion_matrix_dense.hpp +++ b/cpp/subprojects/seco/include/mlrl/seco/data/vector_confusion_matrix_dense.hpp @@ -102,87 +102,103 @@ namespace seco { * Adds the confusion matrix elements that correspond to an example at a specific index to this vector. The * confusion matrix elements to be added are multiplied by a specific weight. * - * @param exampleIndex The index of the example - * @param labelMatrix A reference to an object of type `CContiguousConstView` that provides random - * access to the labels of the training examples - * @param majorityLabelIndices A reference to an object of type `VectorConstView` that stores the indices - * of the labels that are relevant to the majority of the training examples - * @param coverageMatrix A reference to an object of type `DenseCoverageMatrix` that stores how often - * individual examples and labels have been covered - * @param weight The weight, the confusion matrix elements should be multiplied by + * @param exampleIndex The index of the example + * @param labelMatrix A reference to an object of type `CContiguousConstView` that provides + * random access to the labels of the training examples + * @param majorityLabelIndicesBegin An iterator to the beginning of the indices of the labels that are + * relevant to the majority of the training examples + * @param majorityLabelIndicesEnd An iterator to the end of the indices of the labels that are relevant to + * the majority of the training examples + * @param coverageMatrix A reference to an object of type `DenseCoverageMatrix` that stores how + * often individual examples and labels have been covered + * @param weight The weight, the confusion matrix elements should be multiplied by */ void add(uint32 exampleIndex, const CContiguousConstView& labelMatrix, - const VectorConstView& majorityLabelIndices, const DenseCoverageMatrix& coverageMatrix, - float64 weight); + VectorConstView::const_iterator majorityLabelIndicesBegin, + VectorConstView::const_iterator majorityLabelIndicesEnd, + const DenseCoverageMatrix& coverageMatrix, float64 weight); /** * Adds the confusion matrix elements that correspond to an example at a specific index to this vector. The * confusion matrix elements to be added are multiplied by a specific weight. * - * @param exampleIndex The index of the example - * @param labelMatrix A reference to an object of type `BinaryCsrConstView` that provides row-wise - * access to the labels of the training examples - * @param majorityLabelIndices A reference to an object of type `VectorConstView` that stores the indices - * of the labels that are relevant to the majority of the training examples - * @param coverageMatrix A reference to an object of type `DenseCoverageMatrix` that stores how often - * individual examples and labels have been covered - * @param weight The weight, the confusion matrix elements should be multiplied by + * @param exampleIndex The index of the example + * @param labelMatrix A reference to an object of type `BinaryCsrConstView` that provides + * row-wise access to the labels of the training examples + * @param majorityLabelIndicesBegin An iterator to the beginning of the indices of the labels that are + * relevant to the majority of the training examples + * @param majorityLabelIndicesEnd An iterator to the end of the indices of the labels that are relevant to + * the majority of the training examples + * @param coverageMatrix A reference to an object of type `DenseCoverageMatrix` that stores how + * often individual examples and labels have been covered + * @param weight The weight, the confusion matrix elements should be multiplied by */ void add(uint32 exampleIndex, const BinaryCsrConstView& labelMatrix, - const VectorConstView& majorityLabelIndices, const DenseCoverageMatrix& coverageMatrix, - float64 weight); + VectorConstView::const_iterator majorityLabelIndicesBegin, + VectorConstView::const_iterator majorityLabelIndicesEnd, + const DenseCoverageMatrix& coverageMatrix, float64 weight); /** * Removes the confusion matrix elements that correspond to an example at a specific index from this vector. * The confusion matrix elements to be added are multiplied by a specific weight. * - * @param exampleIndex The index of the example - * @param labelMatrix A reference to an object of type `CContiguousConstView` that provides random - * access to the labels of the training examples - * @param majorityLabelIndices A reference to an object of type `VectorConstView` that stores the indices - * of the labels that are relevant to the majority of the training examples - * @param coverageMatrix A reference to an object of type `DenseCoverageMatrix` that stores how often - * individual examples and labels have been covered - * @param weight The weight, the confusion matrix elements should be multiplied by + * @param exampleIndex The index of the example + * @param labelMatrix A reference to an object of type `CContiguousConstView` that provides + * random access to the labels of the training examples + * @param majorityLabelIndicesBegin An iterator to the beginning of the indices of the labels that are + * relevant to the majority of the training examples + * @param majorityLabelIndicesEnd An iterator to the end of the indices of the labels that are relevant to + * the majority of the training examples + * @param coverageMatrix A reference to an object of type `DenseCoverageMatrix` that stores how + * often individual examples and labels have been covered + * @param weight The weight, the confusion matrix elements should be multiplied by */ void remove(uint32 exampleIndex, const CContiguousConstView& labelMatrix, - const VectorConstView& majorityLabelIndices, const DenseCoverageMatrix& coverageMatrix, - float64 weight); + VectorConstView::const_iterator majorityLabelIndicesBegin, + VectorConstView::const_iterator majorityLabelIndicesEnd, + const DenseCoverageMatrix& coverageMatrix, float64 weight); /** * Removes the confusion matrix elements that correspond to an example at a specific index from this vector. * The confusion matrix elements to be added are multiplied by a specific weight. * - * @param exampleIndex The index of the example - * @param labelMatrix A reference to an object of type `BinaryCsrConstView` that provides row-wise - * access to the labels of the training examples - * @param majorityLabelIndices A reference to an object of type `VectorConstView` that stores the indices - * of the labels that are relevant to the majority of the training examples - * @param coverageMatrix A reference to an object of type `DenseCoverageMatrix` that stores how often - * individual examples and labels have been covered - * @param weight The weight, the confusion matrix elements should be multiplied by + * @param exampleIndex The index of the example + * @param labelMatrix A reference to an object of type `BinaryCsrConstView` that provides + * row-wise access to the labels of the training examples + * @param majorityLabelIndicesBegin An iterator to the beginning of the indices of the labels that are + * relevant to the majority of the training examples + * @param majorityLabelIndicesEnd An iterator to the end of the indices of the labels that are relevant to + * the majority of the training examples + * @param coverageMatrix A reference to an object of type `DenseCoverageMatrix` that stores how + * often individual examples and labels have been covered + * @param weight The weight, the confusion matrix elements should be multiplied by */ void remove(uint32 exampleIndex, const BinaryCsrConstView& labelMatrix, - const VectorConstView& majorityLabelIndices, const DenseCoverageMatrix& coverageMatrix, - float64 weight); + VectorConstView::const_iterator majorityLabelIndicesBegin, + VectorConstView::const_iterator majorityLabelIndicesEnd, + const DenseCoverageMatrix& coverageMatrix, float64 weight); /** * Adds certain confusion matrix elements in another vector, whose positions are given as a * `CompleteIndexVector`, to this vector. The confusion matrix elements to be added are multiplied by a * specific weight. * - * @param exampleIndex The index of the example - * @param labelMatrix A reference to an object of type `CContiguousConstView` that provides random - * access to the labels of the training examples - * @param majorityLabelIndices A reference to an object of type `VectorConstView` that stores the indices - * of the labels that are relevant to the majority of the training examples - * @param coverageMatrix A reference to an object of type `DenseCoverageMatrix` that stores how often - * individual examples and labels have been covered - * @param indices A reference to a `CompleteIndexVector' that provides access to the indices - * @param weight The weight, the confusion matrix elements should be multiplied by + * @param exampleIndex The index of the example + * @param labelMatrix A reference to an object of type `CContiguousConstView` that provides + * random access to the labels of the training examples + * @param majorityLabelIndicesBegin An iterator to the beginning of the indices of the labels that are + * relevant to the majority of the training examples + * @param majorityLabelIndicesEnd An iterator to the end of the indices of the labels that are relevant to + * the majority of the training examples + * @param coverageMatrix A reference to an object of type `DenseCoverageMatrix` that stores how + * often individual examples and labels have been covered + * @param indices A reference to a `CompleteIndexVector' that provides access to the + * indices + * @param weight The weight, the confusion matrix elements should be multiplied by */ void addToSubset(uint32 exampleIndex, const CContiguousConstView& labelMatrix, - const VectorConstView& majorityLabelIndices, + VectorConstView::const_iterator majorityLabelIndicesBegin, + VectorConstView::const_iterator majorityLabelIndicesEnd, const DenseCoverageMatrix& coverageMatrix, const CompleteIndexVector& indices, float64 weight); @@ -191,18 +207,22 @@ namespace seco { * `CompleteIndexVector`, to this vector. The confusion matrix elements to be added are multiplied by a * specific weight. * - * @param exampleIndex The index of the example - * @param labelMatrix A reference to an object of type `BinaryCsrConstView` that provides row-wise - * access to the labels of the training examples - * @param majorityLabelIndices A reference to an object of type `VectorConstView` that stores the indices - * of the labels that are relevant to the majority of the training examples - * @param coverageMatrix A reference to an object of type `DenseCoverageMatrix` that stores how often - * individual examples and labels have been covered - * @param indices A reference to a `CompleteIndexVector' that provides access to the indices - * @param weight The weight, the confusion matrix elements should be multiplied by + * @param exampleIndex The index of the example + * @param labelMatrix A reference to an object of type `BinaryCsrConstView` that provides + * row-wise access to the labels of the training examples + * @param majorityLabelIndicesBegin An iterator to the beginning of the indices of the labels that are + * relevant to the majority of the training examples + * @param majorityLabelIndicesEnd An iterator to the end of the indices of the labels that are relevant to + * the majority of the training examples + * @param coverageMatrix A reference to an object of type `DenseCoverageMatrix` that stores how + * often individual examples and labels have been covered + * @param indices A reference to a `CompleteIndexVector' that provides access to the + * indices + * @param weight The weight, the confusion matrix elements should be multiplied by */ void addToSubset(uint32 exampleIndex, const BinaryCsrConstView& labelMatrix, - const VectorConstView& majorityLabelIndices, + VectorConstView::const_iterator majorityLabelIndicesBegin, + VectorConstView::const_iterator majorityLabelIndicesEnd, const DenseCoverageMatrix& coverageMatrix, const CompleteIndexVector& indices, float64 weight); @@ -211,18 +231,22 @@ namespace seco { * `CompleteIndexVector`, to this vector. The confusion matrix elements to be added are multiplied by a * specific weight. * - * @param exampleIndex The index of the example - * @param labelMatrix A reference to an object of type `CContiguousConstView` that provides random - * access to the labels of the training examples - * @param majorityLabelIndices A reference to an object of type `VectorConstView` that stores the indices - * of the labels that are relevant to the majority of the training examples - * @param coverageMatrix A reference to an object of type `DenseCoverageMatrix` that stores how often - * individual examples and labels have been covered - * @param indices A reference to a `PartialIndexVector' that provides access to the indices - * @param weight The weight, the confusion matrix elements should be multiplied by + * @param exampleIndex The index of the example + * @param labelMatrix A reference to an object of type `CContiguousConstView` that provides + * random access to the labels of the training examples + * @param majorityLabelIndicesBegin An iterator to the beginning of the indices of the labels that are + * relevant to the majority of the training examples + * @param majorityLabelIndicesEnd An iterator to the end of the indices of the labels that are relevant to + * the majority of the training examples + * @param coverageMatrix A reference to an object of type `DenseCoverageMatrix` that stores how + * often individual examples and labels have been covered + * @param indices A reference to a `PartialIndexVector' that provides access to the + * indices + * @param weight The weight, the confusion matrix elements should be multiplied by */ void addToSubset(uint32 exampleIndex, const CContiguousConstView& labelMatrix, - const VectorConstView& majorityLabelIndices, + VectorConstView::const_iterator majorityLabelIndicesBegin, + VectorConstView::const_iterator majorityLabelIndicesEnd, const DenseCoverageMatrix& coverageMatrix, const PartialIndexVector& indices, float64 weight); @@ -231,18 +255,22 @@ namespace seco { * `PartialIndexVector`, to this vector. The confusion matrix elements to be added are multiplied by a * specific weight. * - * @param exampleIndex The index of the example - * @param labelMatrix A reference to an object of type `BinaryCsrConstView` that provides row-wise - * access to the labels of the training examples - * @param majorityLabelIndices A reference to an object of type `VectorConstView` that stores the indices - * of the labels that are relevant to the majority of the training examples - * @param coverageMatrix A reference to an object of type `DenseCoverageMatrix` that stores how often - * individual examples and labels have been covered - * @param indices A reference to a `PartialIndexVector' that provides access to the indices - * @param weight The weight, the confusion matrix elements should be multiplied by + * @param exampleIndex The index of the example + * @param labelMatrix A reference to an object of type `BinaryCsrConstView` that provides + * row-wise access to the labels of the training examples + * @param majorityLabelIndicesBegin An iterator to the beginning of the indices of the labels that are + * relevant to the majority of the training examples + * @param majorityLabelIndicesEnd An iterator to the end of the indices of the labels that are relevant to + * to the majority of the training examples + * @param coverageMatrix A reference to an object of type `DenseCoverageMatrix` that stores how + * often individual examples and labels have been covered + * @param indices A reference to a `PartialIndexVector' that provides access to the + * indices + * @param weight The weight, the confusion matrix elements should be multiplied by */ void addToSubset(uint32 exampleIndex, const BinaryCsrConstView& labelMatrix, - const VectorConstView& majorityLabelIndices, + VectorConstView::const_iterator majorityLabelIndicesBegin, + VectorConstView::const_iterator majorityLabelIndicesEnd, const DenseCoverageMatrix& coverageMatrix, const PartialIndexVector& indices, float64 weight); diff --git a/cpp/subprojects/seco/include/mlrl/seco/rule_evaluation/rule_evaluation.hpp b/cpp/subprojects/seco/include/mlrl/seco/rule_evaluation/rule_evaluation.hpp index 26ec322627..e05fefc81b 100644 --- a/cpp/subprojects/seco/include/mlrl/seco/rule_evaluation/rule_evaluation.hpp +++ b/cpp/subprojects/seco/include/mlrl/seco/rule_evaluation/rule_evaluation.hpp @@ -22,9 +22,10 @@ namespace seco { * Calculates the scores to be predicted by a rule, as well as their overall quality, based on label-wise * confusion matrices. * - * @param majorityLabelIndices A reference to an object of type `VectorConstView` that stores the - * indices of the labels that are relevant to the majority of the training - * examples + * @param majorityLabelIndicesBegin An iterator to the beginning of the indices of the labels that are + * relevant to the majority of the training examples + * @param majorityLabelIndicesEnd An iterator to the end of the indices of the labels that are relevant + * to the majority of the training examples * @param confusionMatricesTotal A reference to an object of type `DenseConfusionMatrixVector` that * stores confusion matrices that take into account all examples * @param confusionMatricesCovered A reference to an object of type `DenseConfusionMatrixVector` that @@ -33,9 +34,11 @@ namespace seco { * @return A reference to an object of type `IScoreVector` that stores the * predicted scores, as well as their overall quality */ - virtual const IScoreVector& calculateScores(const VectorConstView& majorityLabelIndices, - const DenseConfusionMatrixVector& confusionMatricesTotal, - const DenseConfusionMatrixVector& confusionMatricesCovered) = 0; + virtual const IScoreVector& calculateScores( + VectorConstView::const_iterator majorityLabelIndicesBegin, + VectorConstView::const_iterator majorityLabelIndicesEnd, + const DenseConfusionMatrixVector& confusionMatricesTotal, + const DenseConfusionMatrixVector& confusionMatricesCovered) = 0; }; } diff --git a/cpp/subprojects/seco/src/mlrl/seco/data/matrix_coverage_dense.cpp b/cpp/subprojects/seco/src/mlrl/seco/data/matrix_coverage_dense.cpp index 00cedf31e5..0a3cb211ee 100644 --- a/cpp/subprojects/seco/src/mlrl/seco/data/matrix_coverage_dense.cpp +++ b/cpp/subprojects/seco/src/mlrl/seco/data/matrix_coverage_dense.cpp @@ -11,15 +11,16 @@ namespace seco { return sumOfUncoveredWeights_; } - void DenseCoverageMatrix::increaseCoverage(uint32 row, const VectorConstView& majorityLabelIndices, + void DenseCoverageMatrix::increaseCoverage(uint32 row, + VectorConstView::const_iterator majorityLabelIndicesBegin, + VectorConstView::const_iterator majorityLabelIndicesEnd, VectorView::const_iterator predictionBegin, VectorView::const_iterator predictionEnd, CompleteIndexVector::const_iterator indicesBegin, CompleteIndexVector::const_iterator indicesEnd) { uint32 numCols = this->getNumCols(); value_iterator coverageIterator = this->values_begin(row); - auto majorityIterator = - make_binary_forward_iterator(majorityLabelIndices.cbegin(), majorityLabelIndices.cend()); + auto majorityIterator = make_binary_forward_iterator(majorityLabelIndicesBegin, majorityLabelIndicesEnd); for (uint32 i = 0; i < numCols; i++) { bool predictedLabel = predictionBegin[i]; @@ -39,15 +40,16 @@ namespace seco { } } - void DenseCoverageMatrix::increaseCoverage(uint32 row, const VectorConstView& majorityLabelIndices, + void DenseCoverageMatrix::increaseCoverage(uint32 row, + VectorConstView::const_iterator majorityLabelIndicesBegin, + VectorConstView::const_iterator majorityLabelIndicesEnd, VectorView::const_iterator predictionBegin, VectorView::const_iterator predictionEnd, PartialIndexVector::const_iterator indicesBegin, PartialIndexVector::const_iterator indicesEnd) { uint32 numPredictions = indicesEnd - indicesBegin; value_iterator coverageIterator = this->values_begin(row); - auto majorityIterator = - make_binary_forward_iterator(majorityLabelIndices.cbegin(), majorityLabelIndices.cend()); + auto majorityIterator = make_binary_forward_iterator(majorityLabelIndicesBegin, majorityLabelIndicesEnd); uint32 previousIndex = 0; for (uint32 i = 0; i < numPredictions; i++) { @@ -70,15 +72,16 @@ namespace seco { } } - void DenseCoverageMatrix::decreaseCoverage(uint32 row, const VectorConstView& majorityLabelIndices, + void DenseCoverageMatrix::decreaseCoverage(uint32 row, + VectorConstView::const_iterator majorityLabelIndicesBegin, + VectorConstView::const_iterator majorityLabelIndicesEnd, VectorView::const_iterator predictionBegin, VectorView::const_iterator predictionEnd, CompleteIndexVector::const_iterator indicesBegin, CompleteIndexVector::const_iterator indicesEnd) { uint32 numCols = this->getNumCols(); value_iterator coverageIterator = this->values_begin(row); - auto majorityIterator = - make_binary_forward_iterator(majorityLabelIndices.cbegin(), majorityLabelIndices.cend()); + auto majorityIterator = make_binary_forward_iterator(majorityLabelIndicesBegin, majorityLabelIndicesEnd); for (uint32 i = 0; i < numCols; i++) { bool predictedLabel = predictionBegin[i]; @@ -98,15 +101,16 @@ namespace seco { } } - void DenseCoverageMatrix::decreaseCoverage(uint32 row, const VectorConstView& majorityLabelIndices, + void DenseCoverageMatrix::decreaseCoverage(uint32 row, + VectorConstView::const_iterator majorityLabelIndicesBegin, + VectorConstView::const_iterator majorityLabelIndicesEnd, VectorView::const_iterator predictionBegin, VectorView::const_iterator predictionEnd, PartialIndexVector::const_iterator indicesBegin, PartialIndexVector::const_iterator indicesEnd) { uint32 numPredictions = indicesEnd - indicesBegin; value_iterator coverageIterator = this->values_begin(row); - auto majorityIterator = - make_binary_forward_iterator(majorityLabelIndices.cbegin(), majorityLabelIndices.cend()); + auto majorityIterator = make_binary_forward_iterator(majorityLabelIndicesBegin, majorityLabelIndicesEnd); uint32 previousIndex = 0; for (uint32 i = 0; i < numPredictions; i++) { diff --git a/cpp/subprojects/seco/src/mlrl/seco/data/vector_confusion_matrix_dense.cpp b/cpp/subprojects/seco/src/mlrl/seco/data/vector_confusion_matrix_dense.cpp index b7bc57cf8d..8b51ea0823 100644 --- a/cpp/subprojects/seco/src/mlrl/seco/data/vector_confusion_matrix_dense.cpp +++ b/cpp/subprojects/seco/src/mlrl/seco/data/vector_confusion_matrix_dense.cpp @@ -9,11 +9,12 @@ namespace seco { template - static inline void addInternally(LabelIterator labelIterator, const VectorConstView& majorityLabelIndices, + static inline void addInternally(LabelIterator labelIterator, + VectorConstView::const_iterator majorityLabelIndicesBegin, + VectorConstView::const_iterator majorityLabelIndicesEnd, DenseCoverageMatrix::value_const_iterator coverageIterator, float64 weight, ConfusionMatrix* confusionMatrices, uint32 numLabels) { - auto majorityIterator = - make_binary_forward_iterator(majorityLabelIndices.cbegin(), majorityLabelIndices.cend()); + auto majorityIterator = make_binary_forward_iterator(majorityLabelIndicesBegin, majorityLabelIndicesEnd); for (uint32 i = 0; i < numLabels; i++) { uint32 coverage = coverageIterator[i]; @@ -77,63 +78,69 @@ namespace seco { } void DenseConfusionMatrixVector::add(uint32 exampleIndex, const CContiguousConstView& labelMatrix, - const VectorConstView& majorityLabelIndices, + VectorConstView::const_iterator majorityLabelIndicesBegin, + VectorConstView::const_iterator majorityLabelIndicesEnd, const DenseCoverageMatrix& coverageMatrix, float64 weight) { - addInternally(labelMatrix.values_cbegin(exampleIndex), majorityLabelIndices, + addInternally(labelMatrix.values_cbegin(exampleIndex), majorityLabelIndicesBegin, majorityLabelIndicesEnd, coverageMatrix.values_cbegin(exampleIndex), weight, array_, numElements_); } void DenseConfusionMatrixVector::add(uint32 exampleIndex, const BinaryCsrConstView& labelMatrix, - const VectorConstView& majorityLabelIndices, + VectorConstView::const_iterator majorityLabelIndicesBegin, + VectorConstView::const_iterator majorityLabelIndicesEnd, const DenseCoverageMatrix& coverageMatrix, float64 weight) { auto labelIterator = make_binary_forward_iterator(labelMatrix.indices_cbegin(exampleIndex), labelMatrix.indices_cend(exampleIndex)); - addInternally(labelIterator, majorityLabelIndices, coverageMatrix.values_cbegin(exampleIndex), weight, array_, - numElements_); + addInternally(labelIterator, majorityLabelIndicesBegin, majorityLabelIndicesEnd, + coverageMatrix.values_cbegin(exampleIndex), weight, array_, numElements_); } void DenseConfusionMatrixVector::remove(uint32 exampleIndex, const CContiguousConstView& labelMatrix, - const VectorConstView& majorityLabelIndices, + VectorConstView::const_iterator majorityLabelIndicesBegin, + VectorConstView::const_iterator majorityLabelIndicesEnd, const DenseCoverageMatrix& coverageMatrix, float64 weight) { - addInternally(labelMatrix.values_cbegin(exampleIndex), majorityLabelIndices, + addInternally(labelMatrix.values_cbegin(exampleIndex), majorityLabelIndicesBegin, majorityLabelIndicesEnd, coverageMatrix.values_cbegin(exampleIndex), -weight, array_, numElements_); } void DenseConfusionMatrixVector::remove(uint32 exampleIndex, const BinaryCsrConstView& labelMatrix, - const VectorConstView& majorityLabelIndices, + VectorConstView::const_iterator majorityLabelIndicesBegin, + VectorConstView::const_iterator majorityLabelIndicesEnd, const DenseCoverageMatrix& coverageMatrix, float64 weight) { auto labelIterator = make_binary_forward_iterator(labelMatrix.indices_cbegin(exampleIndex), labelMatrix.indices_cend(exampleIndex)); - addInternally(labelIterator, majorityLabelIndices, coverageMatrix.values_cbegin(exampleIndex), -weight, array_, - numElements_); + addInternally(labelIterator, majorityLabelIndicesBegin, majorityLabelIndicesEnd, + coverageMatrix.values_cbegin(exampleIndex), -weight, array_, numElements_); } void DenseConfusionMatrixVector::addToSubset(uint32 exampleIndex, const CContiguousConstView& labelMatrix, - const VectorConstView& majorityLabelIndices, + VectorConstView::const_iterator majorityLabelIndicesBegin, + VectorConstView::const_iterator majorityLabelIndicesEnd, const DenseCoverageMatrix& coverageMatrix, const CompleteIndexVector& indices, float64 weight) { - addInternally(labelMatrix.values_cbegin(exampleIndex), majorityLabelIndices, + addInternally(labelMatrix.values_cbegin(exampleIndex), majorityLabelIndicesBegin, majorityLabelIndicesEnd, coverageMatrix.values_cbegin(exampleIndex), weight, array_, numElements_); } void DenseConfusionMatrixVector::addToSubset(uint32 exampleIndex, const BinaryCsrConstView& labelMatrix, - const VectorConstView& majorityLabelIndices, + VectorConstView::const_iterator majorityLabelIndicesBegin, + VectorConstView::const_iterator majorityLabelIndicesEnd, const DenseCoverageMatrix& coverageMatrix, const CompleteIndexVector& indices, float64 weight) { auto labelIterator = make_binary_forward_iterator(labelMatrix.indices_cbegin(exampleIndex), labelMatrix.indices_cend(exampleIndex)); - addInternally(labelIterator, majorityLabelIndices, coverageMatrix.values_cbegin(exampleIndex), weight, array_, - numElements_); + addInternally(labelIterator, majorityLabelIndicesBegin, majorityLabelIndicesEnd, + coverageMatrix.values_cbegin(exampleIndex), weight, array_, numElements_); } void DenseConfusionMatrixVector::addToSubset(uint32 exampleIndex, const CContiguousConstView& labelMatrix, - const VectorConstView& majorityLabelIndices, + VectorConstView::const_iterator majorityLabelIndicesBegin, + VectorConstView::const_iterator majorityLabelIndicesEnd, const DenseCoverageMatrix& coverageMatrix, const PartialIndexVector& indices, float64 weight) { - auto majorityIterator = - make_binary_forward_iterator(majorityLabelIndices.cbegin(), majorityLabelIndices.cend()); + auto majorityIterator = make_binary_forward_iterator(majorityLabelIndicesBegin, majorityLabelIndicesEnd); typename DenseCoverageMatrix::value_const_iterator coverageIterator = coverageMatrix.values_cbegin(exampleIndex); CContiguousConstView::value_const_iterator labelIterator = labelMatrix.values_cbegin(exampleIndex); @@ -158,11 +165,11 @@ namespace seco { } void DenseConfusionMatrixVector::addToSubset(uint32 exampleIndex, const BinaryCsrConstView& labelMatrix, - const VectorConstView& majorityLabelIndices, + VectorConstView::const_iterator majorityLabelIndicesBegin, + VectorConstView::const_iterator majorityLabelIndicesEnd, const DenseCoverageMatrix& coverageMatrix, const PartialIndexVector& indices, float64 weight) { - auto majorityIterator = - make_binary_forward_iterator(majorityLabelIndices.cbegin(), majorityLabelIndices.cend()); + auto majorityIterator = make_binary_forward_iterator(majorityLabelIndicesBegin, majorityLabelIndicesEnd); typename DenseCoverageMatrix::value_const_iterator coverageIterator = coverageMatrix.values_cbegin(exampleIndex); BinaryCsrConstView::index_const_iterator labelIndexIterator = labelMatrix.indices_cbegin(exampleIndex); diff --git a/cpp/subprojects/seco/src/mlrl/seco/rule_evaluation/rule_evaluation_label_wise_majority.hpp b/cpp/subprojects/seco/src/mlrl/seco/rule_evaluation/rule_evaluation_label_wise_majority.hpp index 97aba4dfac..223e699b98 100644 --- a/cpp/subprojects/seco/src/mlrl/seco/rule_evaluation/rule_evaluation_label_wise_majority.hpp +++ b/cpp/subprojects/seco/src/mlrl/seco/rule_evaluation/rule_evaluation_label_wise_majority.hpp @@ -32,13 +32,13 @@ namespace seco { scoreVector_.quality = 0; } - const IScoreVector& calculateScores(const VectorConstView& majorityLabelIndices, + const IScoreVector& calculateScores(VectorConstView::const_iterator majorityLabelIndicesBegin, + VectorConstView::const_iterator majorityLabelIndicesEnd, const DenseConfusionMatrixVector& confusionMatricesTotal, const DenseConfusionMatrixVector& confusionMatricesCovered) override { typename DenseScoreVector::value_iterator valueIterator = scoreVector_.values_begin(); typename DenseScoreVector::index_const_iterator indexIterator = scoreVector_.indices_cbegin(); - auto labelIterator = - make_binary_forward_iterator(majorityLabelIndices.cbegin(), majorityLabelIndices.cend()); + auto labelIterator = make_binary_forward_iterator(majorityLabelIndicesBegin, majorityLabelIndicesEnd); uint32 numElements = scoreVector_.getNumElements(); uint32 previousIndex = 0; diff --git a/cpp/subprojects/seco/src/mlrl/seco/rule_evaluation/rule_evaluation_label_wise_partial.cpp b/cpp/subprojects/seco/src/mlrl/seco/rule_evaluation/rule_evaluation_label_wise_partial.cpp index d104a92d76..ddf3b95a26 100644 --- a/cpp/subprojects/seco/src/mlrl/seco/rule_evaluation/rule_evaluation_label_wise_partial.cpp +++ b/cpp/subprojects/seco/src/mlrl/seco/rule_evaluation/rule_evaluation_label_wise_partial.cpp @@ -46,7 +46,8 @@ namespace seco { : scoreVector_(labelIndices, true), heuristicPtr_(std::move(heuristicPtr)), liftFunctionPtr_(std::move(liftFunctionPtr)) {} - const IScoreVector& calculateScores(const VectorConstView& majorityLabelIndices, + const IScoreVector& calculateScores(VectorConstView::const_iterator majorityLabelIndicesBegin, + VectorConstView::const_iterator majorityLabelIndicesEnd, const DenseConfusionMatrixVector& confusionMatricesTotal, const DenseConfusionMatrixVector& confusionMatricesCovered) override { uint32 numElements = scoreVector_.getNumElements(); @@ -54,8 +55,7 @@ namespace seco { scoreVector_.indices_cbegin(); DenseConfusionMatrixVector::const_iterator totalIterator = confusionMatricesTotal.cbegin(); DenseConfusionMatrixVector::const_iterator coveredIterator = confusionMatricesCovered.cbegin(); - auto labelIterator = - make_binary_forward_iterator(majorityLabelIndices.cbegin(), majorityLabelIndices.cend()); + auto labelIterator = make_binary_forward_iterator(majorityLabelIndicesBegin, majorityLabelIndicesEnd); DenseScoreVector::value_iterator valueIterator = scoreVector_.values_begin(); float64 sumOfQualities = 0; uint32 previousIndex = 0; @@ -113,15 +113,15 @@ namespace seco { scoreVector_(indexVector_, false), sortedVector_(labelIndices.getNumElements()), heuristicPtr_(std::move(heuristicPtr)), liftFunctionPtr_(std::move(liftFunctionPtr)) {} - const IScoreVector& calculateScores(const VectorConstView& majorityLabelIndices, + const IScoreVector& calculateScores(VectorConstView::const_iterator majorityLabelIndicesBegin, + VectorConstView::const_iterator majorityLabelIndicesEnd, const DenseConfusionMatrixVector& confusionMatricesTotal, const DenseConfusionMatrixVector& confusionMatricesCovered) override { uint32 numElements = labelIndices_.getNumElements(); typename T::const_iterator indexIterator = labelIndices_.cbegin(); DenseConfusionMatrixVector::const_iterator totalIterator = confusionMatricesTotal.cbegin(); DenseConfusionMatrixVector::const_iterator coveredIterator = confusionMatricesCovered.cbegin(); - auto labelIterator = - make_binary_forward_iterator(majorityLabelIndices.cbegin(), majorityLabelIndices.cend()); + auto labelIterator = make_binary_forward_iterator(majorityLabelIndicesBegin, majorityLabelIndicesEnd); SparseArrayVector>::iterator sortedIterator = sortedVector_.begin(); uint32 previousIndex = 0; diff --git a/cpp/subprojects/seco/src/mlrl/seco/rule_evaluation/rule_evaluation_label_wise_single.cpp b/cpp/subprojects/seco/src/mlrl/seco/rule_evaluation/rule_evaluation_label_wise_single.cpp index 5f752a81da..bdf363497d 100644 --- a/cpp/subprojects/seco/src/mlrl/seco/rule_evaluation/rule_evaluation_label_wise_single.cpp +++ b/cpp/subprojects/seco/src/mlrl/seco/rule_evaluation/rule_evaluation_label_wise_single.cpp @@ -37,7 +37,8 @@ namespace seco { : labelIndices_(labelIndices), indexVector_(1), scoreVector_(indexVector_, true), heuristicPtr_(std::move(heuristicPtr)) {} - const IScoreVector& calculateScores(const VectorConstView& majorityLabelIndices, + const IScoreVector& calculateScores(VectorConstView::const_iterator majorityLabelIndicesBegin, + VectorConstView::const_iterator majorityLabelIndicesEnd, const DenseConfusionMatrixVector& confusionMatricesTotal, const DenseConfusionMatrixVector& confusionMatricesCovered) override { uint32 numElements = labelIndices_.getNumElements(); @@ -59,8 +60,7 @@ namespace seco { } } - auto labelIterator = - make_binary_forward_iterator(majorityLabelIndices.cbegin(), majorityLabelIndices.cend()); + auto labelIterator = make_binary_forward_iterator(majorityLabelIndicesBegin, majorityLabelIndicesEnd); std::advance(labelIterator, bestIndex); scoreVector_.values_begin()[0] = (float64) !(*labelIterator); indexVector_.begin()[0] = bestIndex; diff --git a/cpp/subprojects/seco/src/mlrl/seco/statistics/statistics_label_wise_common.hpp b/cpp/subprojects/seco/src/mlrl/seco/statistics/statistics_label_wise_common.hpp index 72953e1874..3be88743d4 100644 --- a/cpp/subprojects/seco/src/mlrl/seco/statistics/statistics_label_wise_common.hpp +++ b/cpp/subprojects/seco/src/mlrl/seco/statistics/statistics_label_wise_common.hpp @@ -23,7 +23,8 @@ namespace seco { const CoverageMatrix& coverageMatrix, ConfusionMatrixVector& vector, const IndexVector& labelIndices, uint32 statisticIndex) { - vector.addToSubset(statisticIndex, labelMatrix, majorityLabelVector, coverageMatrix, labelIndices, 1); + vector.addToSubset(statisticIndex, labelMatrix, majorityLabelVector.cbegin(), majorityLabelVector.cend(), + coverageMatrix, labelIndices, 1); } templatecalculateScores(majorityLabelVector_, totalSumVector_, sumVector_); + return ruleEvaluationPtr_->calculateScores(majorityLabelVector_.cbegin(), majorityLabelVector_.cend(), + totalSumVector_, sumVector_); } }; @@ -167,7 +170,8 @@ namespace seco { uint32 numStatistics = weights.getNumElements(); for (uint32 i = 0; i < numStatistics; i++) { - statisticVector.add(i, labelMatrix, majorityLabelVector, coverageMatrix, 1); + statisticVector.add(i, labelMatrix, majorityLabelVector.cbegin(), majorityLabelVector.cend(), + coverageMatrix, 1); } } @@ -180,7 +184,8 @@ namespace seco { for (uint32 i = 0; i < numStatistics; i++) { float64 weight = weights[i]; - statisticVector.add(i, labelMatrix, majorityLabelVector, coverageMatrix, weight); + statisticVector.add(i, labelMatrix, majorityLabelVector.cbegin(), majorityLabelVector.cend(), + coverageMatrix, weight); } } @@ -249,7 +254,8 @@ namespace seco { const BinarySparseArrayVector& majorityLabelVector, const CoverageMatrix& coverageMatrix, ConfusionMatrixVector& vector, uint32 statisticIndex) { - vector.add(statisticIndex, labelMatrix, majorityLabelVector, coverageMatrix, 1); + vector.add(statisticIndex, labelMatrix, majorityLabelVector.cbegin(), majorityLabelVector.cend(), + coverageMatrix, 1); } template @@ -258,7 +264,8 @@ namespace seco { const CoverageMatrix& coverageMatrix, ConfusionMatrixVector& vector, uint32 statisticIndex) { float64 weight = weights[statisticIndex]; - vector.add(statisticIndex, labelMatrix, majorityLabelVector, coverageMatrix, weight); + vector.add(statisticIndex, labelMatrix, majorityLabelVector.cbegin(), majorityLabelVector.cend(), + coverageMatrix, weight); } template @@ -266,7 +273,8 @@ namespace seco { const BinarySparseArrayVector& majorityLabelVector, const CoverageMatrix& coverageMatrix, ConfusionMatrixVector& vector, uint32 statisticIndex) { - vector.remove(statisticIndex, labelMatrix, majorityLabelVector, coverageMatrix, 1); + vector.remove(statisticIndex, labelMatrix, majorityLabelVector.cbegin(), majorityLabelVector.cend(), + coverageMatrix, 1); } template @@ -275,7 +283,8 @@ namespace seco { const CoverageMatrix& coverageMatrix, ConfusionMatrixVector& vector, uint32 statisticIndex) { float64 weight = weights[statisticIndex]; - vector.remove(statisticIndex, labelMatrix, majorityLabelVector, coverageMatrix, weight); + vector.remove(statisticIndex, labelMatrix, majorityLabelVector.cbegin(), majorityLabelVector.cend(), + coverageMatrix, weight); } /** @@ -376,7 +385,8 @@ namespace seco { */ const IScoreVector& calculateScoresAccumulated() override { return this->ruleEvaluationPtr_->calculateScores( - this->majorityLabelVector_, this->totalSumVector_, *accumulatedSumVectorPtr_); + this->majorityLabelVector_.cbegin(), this->majorityLabelVector_.cend(), this->totalSumVector_, + *accumulatedSumVectorPtr_); } /** @@ -385,7 +395,8 @@ namespace seco { const IScoreVector& calculateScoresUncovered() override { tmpVector_.difference(subsetSumVector_->cbegin(), subsetSumVector_->cend(), this->labelIndices_, this->sumVector_.cbegin(), this->sumVector_.cend()); - return this->ruleEvaluationPtr_->calculateScores(this->majorityLabelVector_, + return this->ruleEvaluationPtr_->calculateScores(this->majorityLabelVector_.cbegin(), + this->majorityLabelVector_.cend(), this->totalSumVector_, tmpVector_); } @@ -395,7 +406,8 @@ namespace seco { const IScoreVector& calculateScoresUncoveredAccumulated() override { tmpVector_.difference(subsetSumVector_->cbegin(), subsetSumVector_->cend(), this->labelIndices_, accumulatedSumVectorPtr_->cbegin(), accumulatedSumVectorPtr_->cend()); - return this->ruleEvaluationPtr_->calculateScores(this->majorityLabelVector_, + return this->ruleEvaluationPtr_->calculateScores(this->majorityLabelVector_.cbegin(), + this->majorityLabelVector_.cend(), this->totalSumVector_, tmpVector_); } }; @@ -537,21 +549,23 @@ namespace seco { }; template - static inline void applyLabelWisePredictionInternally(uint32 statisticIndex, const Prediction& prediction, - CoverageMatrix& coverageMatrix, - const VectorConstView& majorityLabelIndices) { - coverageMatrix.increaseCoverage(statisticIndex, majorityLabelIndices, prediction.values_cbegin(), - prediction.values_cend(), prediction.indices_cbegin(), - prediction.indices_cend()); + static inline void applyLabelWisePredictionInternally( + uint32 statisticIndex, const Prediction& prediction, CoverageMatrix& coverageMatrix, + VectorConstView::const_iterator majorityLabelIndicesBegin, + VectorConstView::const_iterator majorityLabelIndicesEnd) { + coverageMatrix.increaseCoverage(statisticIndex, majorityLabelIndicesBegin, majorityLabelIndicesEnd, + prediction.values_cbegin(), prediction.values_cend(), + prediction.indices_cbegin(), prediction.indices_cend()); } template - static inline void revertLabelWisePredictionInternally(uint32 statisticIndex, const Prediction& prediction, - CoverageMatrix& coverageMatrix, - const VectorConstView& majorityLabelIndices) { - coverageMatrix.decreaseCoverage(statisticIndex, majorityLabelIndices, prediction.values_cbegin(), - prediction.values_cend(), prediction.indices_cbegin(), - prediction.indices_cend()); + static inline void revertLabelWisePredictionInternally( + uint32 statisticIndex, const Prediction& prediction, CoverageMatrix& coverageMatrix, + VectorConstView::const_iterator majorityLabelIndicesBegin, + VectorConstView::const_iterator majorityLabelIndicesEnd) { + coverageMatrix.decreaseCoverage(statisticIndex, majorityLabelIndicesBegin, majorityLabelIndicesEnd, + prediction.values_cbegin(), prediction.values_cend(), + prediction.indices_cbegin(), prediction.indices_cend()); } template( - statisticIndex, prediction, *coverageMatrixPtr_, *majorityLabelVectorPtr_); + statisticIndex, prediction, *coverageMatrixPtr_, majorityLabelVectorPtr_->cbegin(), + majorityLabelVectorPtr_->cend()); } /** @@ -657,7 +672,8 @@ namespace seco { */ void applyPrediction(uint32 statisticIndex, const PartialPrediction& prediction) override final { applyLabelWisePredictionInternally( - statisticIndex, prediction, *coverageMatrixPtr_, *majorityLabelVectorPtr_); + statisticIndex, prediction, *coverageMatrixPtr_, majorityLabelVectorPtr_->cbegin(), + majorityLabelVectorPtr_->cend()); } /** @@ -665,7 +681,8 @@ namespace seco { */ void revertPrediction(uint32 statisticIndex, const CompletePrediction& prediction) override final { revertLabelWisePredictionInternally( - statisticIndex, prediction, *coverageMatrixPtr_, *majorityLabelVectorPtr_); + statisticIndex, prediction, *coverageMatrixPtr_, majorityLabelVectorPtr_->cbegin(), + majorityLabelVectorPtr_->cend()); } /** @@ -673,7 +690,8 @@ namespace seco { */ void revertPrediction(uint32 statisticIndex, const PartialPrediction& prediction) override final { revertLabelWisePredictionInternally( - statisticIndex, prediction, *coverageMatrixPtr_, *majorityLabelVectorPtr_); + statisticIndex, prediction, *coverageMatrixPtr_, majorityLabelVectorPtr_->cbegin(), + majorityLabelVectorPtr_->cend()); } /**