File math.hpp¶
-
namespace util¶
Functions
-
static inline 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 util::iterator_value<Iterator> 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
Iteratorthat provides random access to the elements in the vectorn – The number of elements in the vector
- Returns:
The L1 norm
-
template<typename Iterator, typename WeightIterator>
static inline util::iterator_value<Iterator> 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
Iteratorthat provides random access to the elements in the vectorweightIterator – An iterator of template type
WeightIteratorthat provides random access to the weights of the elementsn – The number of elements in the vector
- Returns:
The L1 norm
-
template<typename Iterator>
static inline util::iterator_value<Iterator> 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
Iteratorthat provides random access to the elements in the vectorn – The number of elements in the vector
- Returns:
The square of the L2 norm
-
template<typename Iterator, typename WeightIterator>
static inline util::iterator_value<Iterator> 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
Iteratorthat provides random access to the elements in the vectorweightIterator – An iterator of template type
WeightIteratorthat provides random access to the weights of the elementsn – The number of elements in the vector
- Returns:
The square of the L2 norm
-
template<typename T>
static inline T logisticFunction(T x)¶ Calculates and returns the logistic function
1 / (1 + exp(-x)), given a specific valuex.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/).- Template Parameters:
T – The type of the value
x- Parameters:
x – The value
x- Returns:
The value that has been calculated
-
static inline uint32 triangularNumber(uint32 n)¶