File vector_statistic_decomposable_sparse.hpp

namespace boosting
template<typename StatisticType, typename WeightType>
struct SparseStatistic
#include <vector_statistic_decomposable_sparse.hpp>

An individual label space statistic that consists of a gradient, a Hessian and a weight.

Template Parameters:
  • StatisticType – The type of the gradient and Hessian

  • WeightType – The type of the weight

Public Functions

inline SparseStatistic()
inline SparseStatistic(StatisticType gradient, StatisticType hessian, WeightType weight)
Parameters:
  • gradient – The gradient

  • hessian – The Hessian

  • weight – The weight

inline SparseStatistic<StatisticType, WeightType> &operator+=(const SparseStatistic<StatisticType, WeightType> &rhs)

Adds the gradient, Hessian and weight of a given statistic to the gradient, Hessian and weight of this statistic,

Parameters:

rhs – A reference to the statistic, whose gradient, Hessian and weight should be added

Returns:

A reference to the modified statistic

inline SparseStatistic<StatisticType, WeightType> &operator-=(const SparseStatistic<StatisticType, WeightType> &rhs)

Subtracts the gradient, Hessian and weight of a given statistic from the gradient, Hessian and weight of this statistic.

Parameters:

rhs – A reference to the statistic, whose gradient, Hessian and weight should be subtracted

Returns:

A reference to the modified statistic

Public Members

StatisticType gradient

The gradient.

StatisticType hessian

The Hessian.

WeightType weight

The weight.

Friends

inline friend SparseStatistic<StatisticType, WeightType> operator+(SparseStatistic<StatisticType, WeightType> lhs, const SparseStatistic<StatisticType, WeightType> &rhs)

Creates and returns a new statistic that results from adding the gradient, Hessian and weight of a specific statistic to the gradient, Hessian and weight of an existing statistic.

Parameters:
  • lhs – The original statistic

  • rhs – A reference to the statistic, whose gradient, Hessian and weight should be added

Returns:

The statistic that has been created

inline friend SparseStatistic<StatisticType, WeightType> operator-(SparseStatistic<StatisticType, WeightType> lhs, const SparseStatistic<StatisticType, WeightType> &rhs)

Creates and returns a new statistic that results from subtracting the gradient, Hessian and weight of a specific statistic from the gradient, Hessian and weight of an existing statistic.

Parameters:
  • lhs – The original statistic

  • rhs – A reference to the value to be subtracted

Returns:

The statistic that has been created

template<typename StatisticType, typename WeightType>
class SparseDecomposableStatisticVector : public VectorDecorator<AllocatedVector<SparseStatistic<StatisticType, WeightType>>>
#include <vector_statistic_decomposable_sparse.hpp>

An one-dimensional vector that stores aggregated gradients and Hessians that have been calculated using a decomposable loss function in a C-contiguous array. For each element in the vector, a single gradient and Hessian, as well as the sums of the weights of the aggregated gradients and Hessians, is stored.

Template Parameters:
  • StatisticType – The type of the gradients and Hessians

  • WeightType – The type of the weights

Public Types

using statistic_type = StatisticType

The type of the gradients and Hessians.

using const_iterator = ConstIterator

An iterator that provides read-only access to the elements in the vector.

Public Functions

SparseDecomposableStatisticVector(uint32 numElements, bool init = false)
Parameters:
  • numElements – The number of gradients and Hessians in the vector

  • init – True, if all gradients and Hessians in the vector should be initialized with zero, false otherwise

SparseDecomposableStatisticVector(const SparseDecomposableStatisticVector<StatisticType, WeightType> &other)
Parameters:

other – A reference to an object of type SparseDecomposableStatisticVector to be copied

const_iterator cbegin() const

Returns a const_iterator to the beginning of the vector.

Returns:

A const_iterator to the beginning

const_iterator cend() const

Returns a const_iterator to the end of the vector.

Returns:

A const_iterator to the end

void add(const SparseDecomposableStatisticVector<StatisticType, WeightType> &vector)

Adds all gradients and Hessians in another vector to this vector.

Parameters:

vector – A reference to an object of type SparseDecomposableStatisticVector that stores the gradients and Hessians to be added to this vector

void add(const SparseSetView<Statistic<StatisticType>> &view, uint32 row)

Adds all gradients and Hessians in a single row of a SparseSetView to this vector.

Parameters:
  • view – A reference to an object of type SparseSetView that stores the gradients and Hessians to be added to this vector

  • row – The index of the row to be added to this vector

void add(const SparseSetView<Statistic<StatisticType>> &view, uint32 row, WeightType weight)

Adds all gradients and Hessians in a single row of a SparseSetView to this vector. The gradients and Hessians to be added are multiplied by a specific weight.

Parameters:
  • view – A reference to an object of type SparseSetView that stores the gradients and Hessians to be added to this vector

  • row – The index of the row to be added to this vector

  • weight – The weight, the gradients and Hessians should be multiplied by

void remove(const SparseSetView<Statistic<StatisticType>> &view, uint32 row)

Removes all gradients and Hessians in a single row of a SparseSetView from this vector.

Parameters:
  • view – A reference to an object of type SparseSetView that stores the gradients and Hessians to be removed from this vector

  • row – The index of the row to be removed from this vector

void remove(const SparseSetView<Statistic<StatisticType>> &view, uint32 row, WeightType weight)

Removes all gradients and Hessians in a single row of a SparseSetView from this vector. The gradients and Hessians to be added are multiplied by a specific weight.

Parameters:
  • view – A reference to an object of type SparseSetView that stores the gradients and Hessians to be removed from this vector

  • row – The index of the row to be removed from this vector

  • weight – The weight, the gradients and Hessians should be multiplied by

void addToSubset(const SparseSetView<Statistic<StatisticType>> &view, uint32 row, const CompleteIndexVector &indices)

Adds certain gradients and Hessians in a single row of a SparseSetView, whose positions are given as a CompleteIndexVector, to this vector.

Parameters:
  • view – A reference to an object of type SparseSetView that stores the gradients and Hessians to be added to this vector

  • row – The index of the row to be added to this vector

  • indices – A reference to a CompleteIndexVector that provides access to the indices

void addToSubset(const SparseSetView<Statistic<StatisticType>> &view, uint32 row, const PartialIndexVector &indices)

Adds certain gradients and Hessians in a single row of a SparseSetView, whose positions are given as a PartialIndexVector, to this vector.

Parameters:
  • view – A reference to an object of type SparseSetView that stores the gradients and Hessians to be added to this vector

  • row – The index of the row to be added to this vector

  • indices – A reference to a PartialIndexVector that provides access to the indices

void addToSubset(const SparseSetView<Statistic<StatisticType>> &view, uint32 row, const CompleteIndexVector &indices, WeightType weight)

Adds certain gradients and Hessians in a single row of a SparseSetView, whose positions are given as a CompleteIndexVector, to this vector. The gradients and Hessians to be added are multiplied by a specific weight.

Parameters:
  • view – A reference to an object of type SparseSetView that stores the gradients and Hessians to be added to this vector

  • row – The index of the row to be added to this vector

  • indices – A reference to a CompleteIndexVector that provides access to the indices

  • weight – The weight, the gradients and Hessians should be multiplied by

void addToSubset(const SparseSetView<Statistic<StatisticType>> &view, uint32 row, const PartialIndexVector &indices, WeightType weight)

Adds certain gradients and Hessians in a single row of a SparseSetView, whose positions are given as a PartialIndexVector, to this vector. The gradients and Hessians to be added are multiplied by a specific weight.

Parameters:
  • view – A reference to an object of type SparseSetView that stores the gradients and Hessians to be added to this vector

  • row – The index of the row to be added to this vector

  • indices – A reference to a PartialIndexVector that provides access to the indices

  • weight – The weight, the gradients and Hessians should be multiplied by

void difference(const SparseDecomposableStatisticVector<StatisticType, WeightType> &first, const CompleteIndexVector &firstIndices, const SparseDecomposableStatisticVector<StatisticType, WeightType> &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 CompleteIndexVector.

Parameters:
  • first – A reference to an object of type SparseDecomposableStatisticVector that stores the gradients and Hessians in the first vector

  • firstIndices – A reference to an object of type CompleteIndexVector that provides access to the indices

  • second – A reference to an object of type SparseDecomposableStatisticVector that stores the gradients and Hessians in the second vector

void difference(const SparseDecomposableStatisticVector<StatisticType, WeightType> &first, const PartialIndexVector &firstIndices, const SparseDecomposableStatisticVector<StatisticType, WeightType> &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.

Parameters:
  • first – A reference to an object of type SparseDecomposableStatisticVector that stores the gradients and Hessians in the first vector

  • firstIndices – A reference to an object of type PartialIndexVector that provides access to the indices

  • second – A reference to an object of type SparseDecomposableStatisticVector that stores the gradients and Hessians in the second vector

void clear()

Sets all gradients and Hessians stored in this vector to zero.

Private Members

WeightType sumOfWeights_
class ConstIterator

An iterator that provides random read-only access to the statistics in a SparseDecomposableStatisticVector.

Public Types

using difference_type = int

The type that is used to represent the difference between two iterators.

using value_type = const Statistic<StatisticType>

The type of the elements, the iterator provides access to.

using pointer = const Statistic<StatisticType>*

The type of a pointer to an element, the iterator provides access to.

using reference = const Statistic<float64>&

The type of a reference to an element, the iterator provides access to.

using iterator_category = std::random_access_iterator_tag

The tag that specifies the capabilities of the iterator.

Public Functions

ConstIterator(typename View<SparseStatistic<StatisticType, WeightType>>::const_iterator iterator, WeightType sumOfWeights)
Parameters:
  • iterator – An iterator that provides access to the elements in a SparseDecomposableStatisticVector

  • sumOfWeights – The sum of the weights of all statistics that have been added to the vector

value_type operator[](uint32 index) const

Returns the element at a specific index.

Parameters:

index – The index of the element to be returned

Returns:

The element at the given index

value_type operator*() const

Returns the element, the iterator currently refers to.

Returns:

The element, the iterator currently refers to

ConstIterator &operator++()

Returns an iterator to the next element.

Returns:

A reference to an iterator that refers to the next element

ConstIterator &operator++(int n)

Returns an iterator to the next element.

Returns:

A reference to an iterator that refers to the next element

ConstIterator &operator--()

Returns an iterator to the previous element.

Returns:

A reference to an iterator that refers to the previous element

ConstIterator &operator--(int n)

Returns an iterator to the previous element.

Returns:

A reference to an iterator that refers to the previous element

bool operator!=(const ConstIterator &rhs) const

Returns whether this iterator and another one refer to the same element.

Parameters:

rhs – A reference to another iterator

Returns:

True, if the iterators do not refer to the same element, false otherwise

bool operator==(const ConstIterator &rhs) const

Returns whether this iterator and another one refer to the same element.

Parameters:

rhs – A reference to another iterator

Returns:

True, if the iterators refer to the same element, false otherwise

difference_type operator-(const ConstIterator &rhs) const

Returns the difference between this iterator and another one.

Parameters:

rhs – A reference to another iterator

Returns:

The difference between the iterators

Private Members

View<SparseStatistic<StatisticType, WeightType>>::const_iterator iterator_
const WeightType sumOfWeights_