pytagi.nn.activation#

Classes#

ReLU

Applies the Rectified Linear Unit function.

Sigmoid

Applies the Sigmoid function element-wise.

Tanh

Applies the Hyperbolic Tangent function.

MixtureReLU

Applies a probabilistic Rectified Linear Unit approximation.

MixtureSigmoid

Applies a probabilistic picewise-linear Sigmoid-like function.

MixtureTanh

Applies a probabilistic piecewise-linear Hyperbolic Tangent function.

Softplus

Applies the Softplus function element-wise.

LeakyReLU

Applies the Leaky Rectified Linear Unit function element-wise.

Softmax

Applies a Local-Linearization of the Softmax function to an n-dimensional input.

EvenExp

Applies the EvenExp activation function.

Remax

Applies a probabilistic Remax approximation function.

ClosedFormSoftmax

Applies a probabilistic Softmax approximation function.

Module Contents#

class pytagi.nn.activation.ReLU[source]#

Bases: pytagi.nn.base_layer.BaseLayer

Applies the Rectified Linear Unit function.

This layer processes an input Gaussian distribution and outputs the moments for a rectified linear unit. This layer relies on a first-order Taylor-series approximation where the activation function is locally linearized at the input expected value.

\[\text{ReLU}(x) = (x)^+ = \max(0, x)\]
../../../../_images/relu_simplified_gaussian_io.png

Initializes the BaseLayer with a C++ backend instance.

get_layer_info() str[source]#

Retrieves detailed information about the layer.

Returns:

A string containing the layer’s information.

Return type:

str

get_layer_name() str[source]#

Retrieves the name of the layer.

Returns:

The name of the layer.

Return type:

str

class pytagi.nn.activation.Sigmoid[source]#

Bases: pytagi.nn.base_layer.BaseLayer

Applies the Sigmoid function element-wise.

This layer approximates the moments after applying the sigmoid function whose values are constrained to the range (0, 1). This layer relies on a first-order Taylor-series approximation where the activation function is locally linearized at the input expected value.

\[\text{Sigmoid}(x) = \sigma(x) = \frac{1}{1 + e^{-x}}\]
../../../../_images/activation_io_sigmoid.png

Initializes the BaseLayer with a C++ backend instance.

get_layer_info() str[source]#

Retrieves detailed information about the layer.

Returns:

A string containing the layer’s information.

Return type:

str

get_layer_name() str[source]#

Retrieves the name of the layer.

Returns:

The name of the layer.

Return type:

str

class pytagi.nn.activation.Tanh[source]#

Bases: pytagi.nn.base_layer.BaseLayer

Applies the Hyperbolic Tangent function.

This layer approximates the moments after applying the Tanh function whose values are constrained to the range (-1, 1). This layer relies on a first-order Taylor-series approximation where the activation function is locally linearized at the input expected value.

\[\text{Tanh}(x) = \tanh(x) = \frac{e^x - e^{-x}}{e^x + e^{-x}}\]
../../../../_images/activation_io_tanh.png

Initializes the BaseLayer with a C++ backend instance.

get_layer_info() str[source]#

Retrieves detailed information about the layer.

Returns:

A string containing the layer’s information.

Return type:

str

get_layer_name() str[source]#

Retrieves the name of the layer.

Returns:

The name of the layer.

Return type:

str

class pytagi.nn.activation.MixtureReLU[source]#

Bases: pytagi.nn.base_layer.BaseLayer

Applies a probabilistic Rectified Linear Unit approximation.

This layer processes an input Gaussian distribution and outputs the moments for a rectified linear unit. This layer relies on exact moment calculations.

For an input random variable \(X \sim \mathcal{N}(\mu, \sigma^2)\), the output \(Y = \max(0, X)\) results in a rectified Gaussian.

../../../../_images/activation_io_mixture_relu.png

Initializes the BaseLayer with a C++ backend instance.

get_layer_info() str[source]#

Retrieves detailed information about the layer.

Returns:

A string containing the layer’s information.

Return type:

str

get_layer_name() str[source]#

Retrieves the name of the layer.

Returns:

The name of the layer.

Return type:

str

class pytagi.nn.activation.MixtureSigmoid[source]#

Bases: pytagi.nn.base_layer.BaseLayer

Applies a probabilistic picewise-linear Sigmoid-like function.

This layer processes an input Gaussian distribution and outputs the moments for a picewise-linear Sigmoid-like function. This layer relies on exact moment calculations.

../../../../_images/activation_io_mixture_sigmoid.png

Initializes the BaseLayer with a C++ backend instance.

get_layer_info() str[source]#

Retrieves detailed information about the layer.

Returns:

A string containing the layer’s information.

Return type:

str

get_layer_name() str[source]#

Retrieves the name of the layer.

Returns:

The name of the layer.

Return type:

str

class pytagi.nn.activation.MixtureTanh[source]#

Bases: pytagi.nn.base_layer.BaseLayer

Applies a probabilistic piecewise-linear Hyperbolic Tangent function.

This layer processes an input Gaussian distribution and outputs the moments for a picewise-linear Tanh-like function. This layer relies on exact moment calculations.

../../../../_images/activation_io_mixture_tanh.png

Initializes the BaseLayer with a C++ backend instance.

get_layer_info() str[source]#

Retrieves detailed information about the layer.

Returns:

A string containing the layer’s information.

Return type:

str

get_layer_name() str[source]#

Retrieves the name of the layer.

Returns:

The name of the layer.

Return type:

str

class pytagi.nn.activation.Softplus[source]#

Bases: pytagi.nn.base_layer.BaseLayer

Applies the Softplus function element-wise.

Softplus is a smooth approximation of the ReLU function. This layer relies on a first-order Taylor-series approximation where the activation function is locally linearized at the input expected value.

\[\text{Softplus}(x) = \log(1 + e^{x})\]
../../../../_images/activation_io_softplus.png

Initializes the BaseLayer with a C++ backend instance.

get_layer_info() str[source]#

Retrieves detailed information about the layer.

Returns:

A string containing the layer’s information.

Return type:

str

get_layer_name() str[source]#

Retrieves the name of the layer.

Returns:

The name of the layer.

Return type:

str

class pytagi.nn.activation.LeakyReLU[source]#

Bases: pytagi.nn.base_layer.BaseLayer

Applies the Leaky Rectified Linear Unit function element-wise.

This is a variant of ReLU that allows a small, non-zero gradient when the unit is not active. This layer relies on a first-order Taylor-series approximation where the activation function is locally linearized at the input expected value.

\[\begin{split}\text{LeakyReLU}(x) = \begin{cases} x & \text{if } x \geq 0 \\ \alpha x & \text{ otherwise } \end{cases}\end{split}\]

Where \(\alpha\) is the negative_slope and is set to 0.1.

../../../../_images/activation_io_leaky_relu.png

Initializes the BaseLayer with a C++ backend instance.

get_layer_info() str[source]#

Retrieves detailed information about the layer.

Returns:

A string containing the layer’s information.

Return type:

str

get_layer_name() str[source]#

Retrieves the name of the layer.

Returns:

The name of the layer.

Return type:

str

class pytagi.nn.activation.Softmax[source]#

Bases: pytagi.nn.base_layer.BaseLayer

Applies a Local-Linearization of the Softmax function to an n-dimensional input.

The Softmax function rescales the input so that the elements of the output lie in the range [0,1] and sum to 1. It is commonly used as the final activation function in a classification network to produce probability distributions over classes.

\[\text{Softmax}(x_{i}) = \frac{\exp(x_i)}{\sum_j \exp(x_j)}\]

Initializes the BaseLayer with a C++ backend instance.

get_layer_info() str[source]#

Retrieves detailed information about the layer.

Returns:

A string containing the layer’s information.

Return type:

str

get_layer_name() str[source]#

Retrieves the name of the layer.

Returns:

The name of the layer.

Return type:

str

class pytagi.nn.activation.EvenExp[source]#

Bases: pytagi.nn.base_layer.BaseLayer

Applies the EvenExp activation function.

This function allows passing only the odd postions of the output layer through an exponential activation function. This is used for going from V2_bar to V2_bar_tilde for the aleatoric uncertainty inference in the case of heteroscedastic regression.

\[\begin{split}\text{EvenExp}(x) = \begin{cases} \exp(x) & \text{if } x \text{ is at an odd position}\\ x & \text{if } x \text{ is at an even position} \end{cases}\end{split}\]

Initializes the BaseLayer with a C++ backend instance.

get_layer_info() str[source]#

Retrieves detailed information about the layer.

Returns:

A string containing the layer’s information.

Return type:

str

get_layer_name() str[source]#

Retrieves the name of the layer.

Returns:

The name of the layer.

Return type:

str

class pytagi.nn.activation.Remax[source]#

Bases: pytagi.nn.base_layer.BaseLayer

Applies a probabilistic Remax approximation function.

Remax is a softmax-like activation function which replaces the exponential function by a mixtureRelu. It rescales the input so that the elements of the output lie in the range [0,1] and sum to 1. It is commonly used as the final activation function in a classification network to produce probability distributions over classes.

\[\text{Remax}(x_{i}) = \frac{\text{ReLU}(x_i)}{\sum_j \text{ReLU}(x_j)}\]

Initializes the BaseLayer with a C++ backend instance.

get_layer_info() str[source]#

Retrieves detailed information about the layer.

Returns:

A string containing the layer’s information.

Return type:

str

get_layer_name() str[source]#

Retrieves the name of the layer.

Returns:

The name of the layer.

Return type:

str

class pytagi.nn.activation.ClosedFormSoftmax[source]#

Bases: pytagi.nn.base_layer.BaseLayer

Applies a probabilistic Softmax approximation function.

Closed-form softmax is an approximation of the deterministic softmax function that provides a closed-form solution for the output moments of Gaussian inputs. It is commonly used as the final activation function in a classification network to produce probability distributions over classes.

\[\text{Softmax}(x_{i}) = \frac{\exp(x_i)}{\sum_j \exp(x_j)}\]

Initializes the BaseLayer with a C++ backend instance.

get_layer_info() str[source]#

Retrieves detailed information about the layer.

Returns:

A string containing the layer’s information.

Return type:

str

get_layer_name() str[source]#

Retrieves the name of the layer.

Returns:

The name of the layer.

Return type:

str