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

Quantized learning #1025

Draft
wants to merge 37 commits into
base: feature
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
6d67504
Add classes IQuantization, IQuantizationFactory and IQuantizationConfig.
michael-rapp Jul 31, 2024
8a46075
Add class NoQuantizationConfig.
michael-rapp Jul 31, 2024
061ed21
Add function "getQuantizationConfig" to class IBoostedRuleLearnerConfig.
michael-rapp Jul 31, 2024
348ab86
Add class INoQuantizationMixin.
michael-rapp Jul 31, 2024
0d1cd7a
Add class StochasticQuantizationConfig.
michael-rapp Jul 31, 2024
01f7829
Add class IStochasticQuantizationMixin.
michael-rapp Jul 31, 2024
90e5e68
Add parameter "quantization" to BoomerClassifier.
michael-rapp Jul 31, 2024
06404e0
Add member "quantizationPtr_" to class AbstractStatistics.
michael-rapp Jul 31, 2024
87daa7a
Edit comments.
michael-rapp Aug 11, 2024
b99a071
Add function "commit" to class IStatisticsUpdate.
michael-rapp Aug 11, 2024
cbdb212
Remove inline functions.
michael-rapp Aug 11, 2024
e00bd5e
Add function "getIndexVector" to classes CompletePrediction and Parti…
michael-rapp Aug 11, 2024
44b7818
Add function "quantize" to class IQuantization.
michael-rapp Aug 11, 2024
f543e93
Add "create" functions that accept different types of statistic matri…
michael-rapp Aug 11, 2024
2976254
Add class IQuantizationMatrix.
michael-rapp Aug 11, 2024
dd83d2b
Use function "visitQuantizationMatrix".
michael-rapp Aug 12, 2024
2867c50
Add template argument "QuantizationMatrix" to class AbstractStatistics.
michael-rapp Aug 12, 2024
30c6239
Pass argument of type IQuantizationMatrix to constructor of the class…
michael-rapp Aug 12, 2024
d09e5a4
Let IQuantizationMatrix inherit from IQuantizationFactory.
michael-rapp Aug 14, 2024
594bc1a
Pass quantization matrix when creating objects of type IStatisticsSub…
michael-rapp Aug 14, 2024
b26a018
Use std::optional for the arguments of visitor functions.
michael-rapp Aug 14, 2024
dad9158
Rename class BitVector to BinaryBitVector.
michael-rapp Aug 15, 2024
53b1651
Add classes BitView, BitVector, BitVectorAllocator and BinaryBitVecto…
michael-rapp Aug 15, 2024
fa7e1d9
Add classes BitMatrix and BitMatrixAllocator.
michael-rapp Aug 17, 2024
8a6f801
Add class IntegerBitMatrix.
michael-rapp Aug 17, 2024
7fd8e91
Add functions "operator[]" and "set" to class BitVector.
michael-rapp Aug 18, 2024
a6e849f
Add function "operator[]" to class BitMatrix.
michael-rapp Aug 18, 2024
7e97408
Remove obsolete functions.
michael-rapp Aug 18, 2024
cb7d5d8
Replace class IntegerBitMatrix with new class BitDecomposableStatisti…
michael-rapp Aug 18, 2024
a1c2c5c
Add missing DLL exports.
michael-rapp Aug 18, 2024
457e7db
Add visitor for handling views of type BitDecomposableMatrixVisitor t…
michael-rapp Aug 19, 2024
1171d48
Add class BitDecomposableStatisticVector.
michael-rapp Aug 19, 2024
6d300f3
Add create functions that accept arguments of type BitDecomposableSta…
michael-rapp Aug 19, 2024
9d7d048
Add template argument StatisticVector to class DenseDecomposableStati…
michael-rapp Aug 19, 2024
7070088
Add constructor argument "view" to vectors for storing statistics.
michael-rapp Aug 19, 2024
de5aae4
Implement visitors for creating statistics backed by a `BitDecomposab…
michael-rapp Aug 19, 2024
d00c5b6
Add shared pointer of type RNG as a member of the class StochasticQua…
michael-rapp Aug 23, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
/*
* @author Michael Rapp ([email protected])
*/
#pragma once

#include "mlrl/boosting/data/view_statistic_decomposable_bit.hpp"
#include "mlrl/common/data/view_composite.hpp"
#include "mlrl/common/indices/index_vector_complete.hpp"
#include "mlrl/common/indices/index_vector_partial.hpp"

namespace boosting {

/**
* An one-dimensional vector that stores aggregated gradients and Hessians that have been calculated using a
* decomposable loss function in a bit vector. For each element in the vector a single gradient and Hessian is
* stored.
*/
class BitDecomposableStatisticVector final
: public CompositeView<AllocatedBitVector<uint32>, AllocatedBitVector<uint32>> {
public:

/**
* @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(const BitDecomposableStatisticView& view, uint32 numElements,
bool init = false);

/**
* @param other A reference to an object of type `BitDecomposableStatisticVector` to be copied
*/
BitDecomposableStatisticVector(const BitDecomposableStatisticVector& other);

/**
* Returns the number of gradients and Hessians in the vector.
*
* @return The number of gradients and Hessians
*/
uint32 getNumElements() const;

/**
* Returns the number of bits per gradient or Hessian in the vector.
*
* @return The number of bits per gradient or Hessian
*/
uint32 getNumBitsPerElement() const;

/**
* Adds all gradients and Hessians in another vector to this vector.
*
* @param vector A reference to an object of type `BitDecomposableStatisticVector` that stores the gradients
* and Hessians to be added to this vector
*/
void add(const BitDecomposableStatisticVector& vector);

/**
* Adds all gradients and Hessians in a single row of a `BitDecomposableStatisticView` to this vector.
*
* @param view A reference to an object of type `BitDecomposableStatisticView` that stores the gradients
* and Hessians to be added to this vector
* @param row The index of the row to be added to this vector
*/
void add(const BitDecomposableStatisticView& view, uint32 row);

/**
* Adds all gradients and Hessians in a single row of a `CContiguousView` to this vector. The gradients and
* Hessians to be added are multiplied by a specific weight.
*
* @param view A reference to an object of type `CContiguousView` that stores the gradients and
* Hessians to be added to this vector
* @param row The index of the row to be added to this vector
* @param weight The weight, the gradients and Hessians should be multiplied by
*/
void add(const BitDecomposableStatisticView& view, uint32 row, float64 weight);

/**
* Removes all gradients and Hessians in a single row of a `CContiguousView` from this vector.
*
* @param view A reference to an object of type `CContiguousView` that stores the gradients and Hessians to
* be removed from this vector
* @param row The index of the row to be removed from this vector
*/
void remove(const BitDecomposableStatisticView& view, uint32 row);

/**
* Removes all gradients and Hessians in a single row of a `CContiguousView` from this vector. The gradients
* and Hessians to be removed are multiplied by a specific weight.
*
* @param view A reference to an object of type `CContiguousView` that stores the gradients and
* Hessians to be removed from this vector
* @param row The index of the row to be removed from this vector
* @param weight The weight, the gradients and Hessians should be multiplied by
*/
void remove(const BitDecomposableStatisticView& view, uint32 row, float64 weight);

/**
* Adds certain gradients and Hessians in a single row of a `CContiguousView`, whose positions are given as
* a `CompleteIndexVector`, to this vector.
*
* @param view A reference to an object of type `CContiguousView` that stores the gradients and
* Hessians to be added to this vector
* @param row The index of the row to be added to this vector
* @param indices A reference to a `CompleteIndexVector' that provides access to the indices
*/
void addToSubset(const BitDecomposableStatisticView& view, uint32 row, const CompleteIndexVector& indices);

/**
* Adds certain gradients and Hessians in single row of a `CContiguousView`, whose positions are given as a
* `PartialIndexVector`, to this vector.
*
* @param view A reference to an object of type `CContiguousView` that stores the gradients and
* Hessians to be added to this vector
* @param row The index of the row to be added to this vector
* @param indices A reference to a `PartialIndexVector' that provides access to the indices
*/
void addToSubset(const BitDecomposableStatisticView& view, uint32 row, const PartialIndexVector& indices);

/**
* Adds certain gradients and Hessians in a single row of a `CContiguousView`, whose positions are given as
* a `CompleteIndexVector`, to this vector. The gradients and Hessians to be added are multiplied by a
* specific weight.
*
* @param view A reference to an object of type `CContiguousView` that stores the gradients and
* Hessians to be added to this vector
* @param row The index of the row to be added to this vector
* @param indices A reference to a `CompleteIndexVector' that provides access to the indices
* @param weight The weight, the gradients and Hessians should be multiplied by
*/
void addToSubset(const BitDecomposableStatisticView& view, uint32 row, const CompleteIndexVector& indices,
float64 weight);

/**
* Adds certain gradients and Hessians in single row of a `CContiguousView`, whose positions are given as a
* `PartialIndexVector`, to this vector. The gradients and Hessians to be added are multiplied by a specific
* weight.
*
* @param view A reference to an object of type `CContiguousView` that stores the gradients and
* Hessians to be added to this vector
* @param row The index of the row to be added to this vector
* @param indices A reference to a `PartialIndexVector' that provides access to the indices
* @param weight The weight, the gradients and Hessians should be multiplied by
*/
void addToSubset(const BitDecomposableStatisticView& view, uint32 row, const PartialIndexVector& indices,
float64 weight);

/**
* Sets the gradients and Hessians in this vector to the difference `first - second` between the gradients
* and Hessians in two other vectors, considering only the gradients and Hessians in the first vector that
* correspond to the positions provided by a `CompleteIndexVector`.
*
* @param first A reference to an object of type `BitDecomposableStatisticVector` that stores the
* gradients and Hessians in the first vector
* @param firstIndices A reference to an object of type `CompleteIndexVector` that provides access to the
* indices
* @param second A reference to an object of type `BitDecomposableStatisticVector` that stores the
* gradients and Hessians in the second vector
*/
void difference(const BitDecomposableStatisticVector& first, const CompleteIndexVector& firstIndices,
const BitDecomposableStatisticVector& second);

/**
* Sets the gradients and Hessians in this vector to the difference `first - second` between the gradients
* and Hessians in two other vectors, considering only the gradients and Hessians in the first vector that
* correspond to the positions provided by a `PartialIndexVector`.
*
* @param first A reference to an object of type `BitDecomposableStatisticVector` that stores the
* gradients and Hessians in the first vector
* @param firstIndices A reference to an object of type `PartialIndexVector` that provides access to the
* indices
* @param second A reference to an object of type `BitDecomposableStatisticVector` that stores the
* gradients and Hessians in the second vector
*/
void difference(const BitDecomposableStatisticVector& first, const PartialIndexVector& firstIndices,
const BitDecomposableStatisticVector& second);

/**
* Sets all gradients and Hessians stored in the vector to zero.
*/
void clear();
};

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Tuple<float64>>& view, uint32 numElements,
bool init = false);

/**
* @param other A reference to an object of type `DenseDecomposableStatisticVector` to be copied
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Tuple<float64>>& view, uint32 numElements,
bool init = false);

/**
* @param other A reference to an object of type `SparseDecomposableStatisticVector` to be copied
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* @author Michael Rapp ([email protected])
*/
#pragma once

#include "mlrl/boosting/util/dll_exports.hpp"
#include "mlrl/common/data/view_matrix_bit.hpp"
#include "mlrl/common/data/view_matrix_composite.hpp"

namespace boosting {

/**
* Implements row-wise read and write access to the gradients and Hessians that have been calculated using a
* decomposable loss function and are stored in pre-allocated bit matrices.
*/
class MLRLBOOSTING_API BitDecomposableStatisticView
: public CompositeMatrix<AllocatedBitMatrix<uint32>, AllocatedBitMatrix<uint32>> {
public:

/**
* @param numRows The number of rows in the view
* @param numCols The number of columns in the view
* @param numBits The number of bits per statistic in the view
*/
BitDecomposableStatisticView(uint32 numRows, uint32 numCols, uint32 numBits);

/**
* @param other A reference to an object of type `BitDecomposableStatisticView` that should be copied
*/
BitDecomposableStatisticView(BitDecomposableStatisticView&& other);

virtual ~BitDecomposableStatisticView() override {}
};

}
Loading
Loading