From 707008861c4888fdc071cb1396c51c417b2e1ce1 Mon Sep 17 00:00:00 2001 From: Michael Rapp Date: Mon, 19 Aug 2024 23:20:00 +0200 Subject: [PATCH] Add constructor argument "view" to vectors for storing statistics. --- .../data/vector_statistic_decomposable_bit.hpp | 11 ++++++----- .../data/vector_statistic_decomposable_dense.hpp | 4 +++- .../data/vector_statistic_decomposable_sparse.hpp | 4 +++- .../data/vector_statistic_non_decomposable_dense.hpp | 10 ++++++---- .../data/vector_statistic_decomposable_bit.cpp | 12 +++++++----- .../data/vector_statistic_decomposable_dense.cpp | 6 ++++-- .../data/vector_statistic_decomposable_sparse.cpp | 6 ++++-- .../data/vector_statistic_non_decomposable_dense.cpp | 7 +++++-- .../mlrl/boosting/statistics/statistics_common.hpp | 9 +++++---- 9 files changed, 43 insertions(+), 26 deletions(-) diff --git a/cpp/subprojects/boosting/include/mlrl/boosting/data/vector_statistic_decomposable_bit.hpp b/cpp/subprojects/boosting/include/mlrl/boosting/data/vector_statistic_decomposable_bit.hpp index f9d90b75b2..a94f735b1a 100644 --- a/cpp/subprojects/boosting/include/mlrl/boosting/data/vector_statistic_decomposable_bit.hpp +++ b/cpp/subprojects/boosting/include/mlrl/boosting/data/vector_statistic_decomposable_bit.hpp @@ -20,12 +20,13 @@ namespace boosting { public: /** - * @param numElements The number of gradients and Hessians in the vector - * @param numBitsPerElement The number of bits per element in the bit vector - * @param init True, if all gradients and Hessians in the vector should be initialized with - * zero, false otherwise + * @param view A reference to an object of type `BitDecomposableStatisticView` + * @param numElements The number of gradients and Hessians in the vector + * @param init True, if all gradients and Hessians in the vector should be initialized with zero, + * false otherwise */ - BitDecomposableStatisticVector(uint32 numElements, uint32 numBitsPerElement, bool init = false); + BitDecomposableStatisticVector(const BitDecomposableStatisticView& view, uint32 numElements, + bool init = false); /** * @param other A reference to an object of type `BitDecomposableStatisticVector` to be copied diff --git a/cpp/subprojects/boosting/include/mlrl/boosting/data/vector_statistic_decomposable_dense.hpp b/cpp/subprojects/boosting/include/mlrl/boosting/data/vector_statistic_decomposable_dense.hpp index 6897b33c45..d6eaf3e180 100644 --- a/cpp/subprojects/boosting/include/mlrl/boosting/data/vector_statistic_decomposable_dense.hpp +++ b/cpp/subprojects/boosting/include/mlrl/boosting/data/vector_statistic_decomposable_dense.hpp @@ -21,11 +21,13 @@ namespace boosting { public: /** + * @param view A reference to an object of type `CContiguousView` * @param numElements The number of gradients and Hessians in the vector * @param init True, if all gradients and Hessians in the vector should be initialized with zero, * false otherwise */ - DenseDecomposableStatisticVector(uint32 numElements, bool init = false); + DenseDecomposableStatisticVector(const CContiguousView>& view, uint32 numElements, + bool init = false); /** * @param other A reference to an object of type `DenseDecomposableStatisticVector` to be copied diff --git a/cpp/subprojects/boosting/include/mlrl/boosting/data/vector_statistic_decomposable_sparse.hpp b/cpp/subprojects/boosting/include/mlrl/boosting/data/vector_statistic_decomposable_sparse.hpp index 85cc705bde..069285b04c 100644 --- a/cpp/subprojects/boosting/include/mlrl/boosting/data/vector_statistic_decomposable_sparse.hpp +++ b/cpp/subprojects/boosting/include/mlrl/boosting/data/vector_statistic_decomposable_sparse.hpp @@ -138,11 +138,13 @@ namespace boosting { public: /** + * @param view A reference to an object of type `SparseSetView` * @param numElements The number of gradients and Hessians in the vector * @param init True, if all gradients and Hessians in the vector should be initialized with zero, * false otherwise */ - SparseDecomposableStatisticVector(uint32 numElements, bool init = false); + SparseDecomposableStatisticVector(const SparseSetView>& view, uint32 numElements, + bool init = false); /** * @param other A reference to an object of type `SparseDecomposableStatisticVector` to be copied diff --git a/cpp/subprojects/boosting/include/mlrl/boosting/data/vector_statistic_non_decomposable_dense.hpp b/cpp/subprojects/boosting/include/mlrl/boosting/data/vector_statistic_non_decomposable_dense.hpp index 4cc4132f01..324234157a 100644 --- a/cpp/subprojects/boosting/include/mlrl/boosting/data/vector_statistic_non_decomposable_dense.hpp +++ b/cpp/subprojects/boosting/include/mlrl/boosting/data/vector_statistic_non_decomposable_dense.hpp @@ -23,11 +23,13 @@ namespace boosting { public: /** - * @param numGradients The number of gradients in the vector - * @param init True, if all gradients and Hessians in the vector should be initialized with zero, - * false otherwise + * @param view A reference to an object of type `DenseNonDecomposableStatisticView` + * @param numGradients The number of gradients in the vector + * @param init True, if all gradients and Hessians in the vector should be initialized with zero, + * false otherwise */ - DenseNonDecomposableStatisticVector(uint32 numGradients, bool init = false); + DenseNonDecomposableStatisticVector(const DenseNonDecomposableStatisticView& view, uint32 numGradients, + bool init = false); /** * @param other A reference to an object of type `DenseNonDecomposableStatisticVector` to be copied diff --git a/cpp/subprojects/boosting/src/mlrl/boosting/data/vector_statistic_decomposable_bit.cpp b/cpp/subprojects/boosting/src/mlrl/boosting/data/vector_statistic_decomposable_bit.cpp index 257563694f..fc5c0dbcc5 100644 --- a/cpp/subprojects/boosting/src/mlrl/boosting/data/vector_statistic_decomposable_bit.cpp +++ b/cpp/subprojects/boosting/src/mlrl/boosting/data/vector_statistic_decomposable_bit.cpp @@ -50,14 +50,16 @@ namespace boosting { } } - BitDecomposableStatisticVector::BitDecomposableStatisticVector(uint32 numElements, uint32 numBitsPerElement, - bool init) + BitDecomposableStatisticVector::BitDecomposableStatisticVector(const BitDecomposableStatisticView& view, + uint32 numElements, bool init) : CompositeView, AllocatedBitVector>( - AllocatedBitVector(numElements, numBitsPerElement, init), - AllocatedBitVector(numElements, numBitsPerElement, init)) {} + AllocatedBitVector(numElements, view.firstView.numBitsPerElement, init), + AllocatedBitVector(numElements, view.secondView.numBitsPerElement, init)) {} BitDecomposableStatisticVector::BitDecomposableStatisticVector(const BitDecomposableStatisticVector& other) - : BitDecomposableStatisticVector(other.getNumElements(), other.getNumBitsPerElement()) { + : CompositeView, AllocatedBitVector>( + AllocatedBitVector(other.firstView.numElements, other.firstView.numBitsPerElement), + AllocatedBitVector(other.secondView.numElements, other.secondView.numBitsPerElement)) { copyInternally(other.firstView, this->firstView); copyInternally(other.secondView, this->secondView); } diff --git a/cpp/subprojects/boosting/src/mlrl/boosting/data/vector_statistic_decomposable_dense.cpp b/cpp/subprojects/boosting/src/mlrl/boosting/data/vector_statistic_decomposable_dense.cpp index 0e6523558a..f0aab8efd7 100644 --- a/cpp/subprojects/boosting/src/mlrl/boosting/data/vector_statistic_decomposable_dense.cpp +++ b/cpp/subprojects/boosting/src/mlrl/boosting/data/vector_statistic_decomposable_dense.cpp @@ -2,12 +2,14 @@ namespace boosting { - DenseDecomposableStatisticVector::DenseDecomposableStatisticVector(uint32 numElements, bool init) + DenseDecomposableStatisticVector::DenseDecomposableStatisticVector(const CContiguousView>& view, + uint32 numElements, bool init) : ClearableViewDecorator>>>( AllocatedVector>(numElements, init)) {} DenseDecomposableStatisticVector::DenseDecomposableStatisticVector(const DenseDecomposableStatisticVector& other) - : DenseDecomposableStatisticVector(other.getNumElements()) { + : ClearableViewDecorator>>>( + AllocatedVector>(other.getNumElements())) { util::copyView(other.cbegin(), this->begin(), this->getNumElements()); } diff --git a/cpp/subprojects/boosting/src/mlrl/boosting/data/vector_statistic_decomposable_sparse.cpp b/cpp/subprojects/boosting/src/mlrl/boosting/data/vector_statistic_decomposable_sparse.cpp index 87786ce2c3..23faccd452 100644 --- a/cpp/subprojects/boosting/src/mlrl/boosting/data/vector_statistic_decomposable_sparse.cpp +++ b/cpp/subprojects/boosting/src/mlrl/boosting/data/vector_statistic_decomposable_sparse.cpp @@ -118,13 +118,15 @@ namespace boosting { return iterator_ - rhs.iterator_; } - SparseDecomposableStatisticVector::SparseDecomposableStatisticVector(uint32 numElements, bool init) + SparseDecomposableStatisticVector::SparseDecomposableStatisticVector(const SparseSetView>& view, + uint32 numElements, bool init) : ClearableViewDecorator>>>( AllocatedVector>(numElements, init)), sumOfWeights_(0) {} SparseDecomposableStatisticVector::SparseDecomposableStatisticVector(const SparseDecomposableStatisticVector& other) - : SparseDecomposableStatisticVector(other.getNumElements()) { + : ClearableViewDecorator>>>( + AllocatedVector>(other.getNumElements())) { util::copyView(other.view.cbegin(), this->view.begin(), this->getNumElements()); sumOfWeights_ = other.sumOfWeights_; } diff --git a/cpp/subprojects/boosting/src/mlrl/boosting/data/vector_statistic_non_decomposable_dense.cpp b/cpp/subprojects/boosting/src/mlrl/boosting/data/vector_statistic_non_decomposable_dense.cpp index f3c9ce6f4d..d7a3de0a55 100644 --- a/cpp/subprojects/boosting/src/mlrl/boosting/data/vector_statistic_non_decomposable_dense.cpp +++ b/cpp/subprojects/boosting/src/mlrl/boosting/data/vector_statistic_non_decomposable_dense.cpp @@ -4,7 +4,8 @@ namespace boosting { - DenseNonDecomposableStatisticVector::DenseNonDecomposableStatisticVector(uint32 numGradients, bool init) + DenseNonDecomposableStatisticVector::DenseNonDecomposableStatisticVector( + const DenseNonDecomposableStatisticView& view, uint32 numGradients, bool init) : ClearableViewDecorator, AllocatedVector>>>( CompositeVector, AllocatedVector>( AllocatedVector(numGradients, init), @@ -12,7 +13,9 @@ namespace boosting { DenseNonDecomposableStatisticVector::DenseNonDecomposableStatisticVector( const DenseNonDecomposableStatisticVector& other) - : DenseNonDecomposableStatisticVector(other.getNumGradients()) { + : ClearableViewDecorator, AllocatedVector>>>( + CompositeVector, AllocatedVector>( + AllocatedVector(other.getNumGradients()), AllocatedVector(other.getNumHessians()))) { util::copyView(other.gradients_cbegin(), this->gradients_begin(), this->getNumGradients()); util::copyView(other.hessians_cbegin(), this->hessians_begin(), this->getNumHessians()); } diff --git a/cpp/subprojects/boosting/src/mlrl/boosting/statistics/statistics_common.hpp b/cpp/subprojects/boosting/src/mlrl/boosting/statistics/statistics_common.hpp index 323f34995b..f0bb3db6a6 100644 --- a/cpp/subprojects/boosting/src/mlrl/boosting/statistics/statistics_common.hpp +++ b/cpp/subprojects/boosting/src/mlrl/boosting/statistics/statistics_common.hpp @@ -98,8 +98,8 @@ namespace boosting { */ StatisticsSubset(const StatisticView& statisticView, const RuleEvaluationFactory& ruleEvaluationFactory, const WeightVector& weights, const IndexVector& outputIndices) - : sumVector_(outputIndices.getNumElements(), true), statisticView_(statisticView), weights_(weights), - outputIndices_(outputIndices), + : sumVector_(statisticView, outputIndices.getNumElements(), true), statisticView_(statisticView), + weights_(weights), outputIndices_(outputIndices), ruleEvaluationPtr_(ruleEvaluationFactory.create(sumVector_, outputIndices)) {} /** @@ -182,7 +182,8 @@ namespace boosting { : StatisticsSubset(statistics.statisticView_, statistics.ruleEvaluationFactory_, statistics.weights_, outputIndices), - tmpVector_(outputIndices.getNumElements()), totalSumVector_(&totalSumVector) {} + tmpVector_(statistics.statisticView_, outputIndices.getNumElements()), + totalSumVector_(&totalSumVector) {} /** * @see `IResettableStatisticsSubset::resetSubset` @@ -392,7 +393,7 @@ namespace boosting { const WeightVector& weights) : AbstractWeightedStatistics( statisticView, ruleEvaluationFactory, weights), - totalSumVectorPtr_(std::make_unique(statisticView.numCols, true)) { + totalSumVectorPtr_(std::make_unique(statisticView, statisticView.numCols, true)) { uint32 numStatistics = weights.getNumElements(); for (uint32 i = 0; i < numStatistics; i++) {