File math.hpp

namespace boosting

Functions

static inline constexpr uint32 triangularNumber(uint32 n)

Calculates and returns the n-th triangular number, i.e., the number of elements in a n times n triangle.

Parameters:

n – A scalar of type uint32, representing the order of the triangular number

Returns:

A scalar of type uint32, representing the n-th triangular number

template<typename Iterator>
static inline constexpr float64 l1Norm(Iterator iterator, uint32 n)

Computes and returns the L1 norm of a specific vector, i.e., the sum of the absolute values of its elements.

Template Parameters:

Iterator – The type of the iterator that provides access to the elements in the vector

Parameters:
  • iterator – An iterator of template type Iterator that provides random access to the elements in the vector

  • n – The number of elements in the vector

Returns:

The L1 norm

template<typename Iterator, typename WeightIterator>
static inline constexpr float64 l1Norm(Iterator iterator, WeightIterator weightIterator, uint32 n)

Computes and returns the L1 norm of a specific vector, i.e., the sum of the absolute values of its elements, where each element has a specific weight.

Template Parameters:
  • Iterator – The type of the iterator that provides access to the elements in the vector

  • WeightIterator – The type of the iterator that provides access to the weights of the elements

Parameters:
  • iterator – An iterator of template type Iterator that provides random access to the elements in the vector

  • weightIterator – An iterator of template type WeightIterator that provides random access to the weights of the elements

  • n – The number of elements in the vector

Returns:

The L1 norm

template<typename Iterator>
static inline constexpr float64 l2NormPow(Iterator iterator, uint32 n)

Computes and returns the square of the L2 norm of a specific vector, i.e. the sum of the squares of its elements. To obtain the actual L2 norm, the square-root of the result provided by this function must be computed.

Template Parameters:

Iterator – The type of the iterator that provides access to the elements in the vector

Parameters:
  • iterator – An iterator of template type Iterator that provides random access to the elements in the vector

  • n – The number of elements in the vector

Returns:

The square of the L2 norm

template<typename Iterator, typename WeightIterator>
static inline constexpr float64 l2NormPow(Iterator iterator, WeightIterator weightIterator, uint32 n)

Computes and returns the square of the L2 norm of a specific vector, i.e. the sum of the squares of its elements, where each elements has a specific weight. To obtain the actual L2 norm, the square-root of the result provided by this function must be computed.

Template Parameters:
  • Iterator – The type of the iterator that provides access to the elements in the vector

  • WeightIterator – The type of the iterator that provides access to the weights of the elements

Parameters:
  • iterator – An iterator of template type Iterator that provides random access to the elements in the vector

  • weightIterator – An iterator of template type WeightIterator that provides random access to the weights of the elements

  • n – The number of elements in the vector

Returns:

The square of the L2 norm

static inline constexpr float64 logisticFunction(float64 x)

Calculates and returns the logistic function 1 / (1 + exp(-x)), given a specific value x.

This implementation exploits the identity 1 / (1 + exp(-x)) = exp(x) / (1 + exp(x)) to increase numerical stability (see, e.g., section “Numerically stable sigmoid function” in https://timvieira.github.io/blog/post/2014/02/11/exp-normalize-trick/).

Parameters:

x – The value x

Returns:

The value that has been calculated