File scalar_math.hpp

namespace math

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 T>
static inline T logisticFunction(T 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/).

Template Parameters:

T – The type of the value x

Parameters:

x – The value x

Returns:

The value that has been calculated