pyml.neural_network.layer.activation.softmax.Softmax#

class Softmax[source]#

Bases: _Activation

Softmax activation function

The softmax activation function is defined as \(\sigma (\mathbf {z} )_{j}={\frac {e^{z_{j}}}{\sum _{k=1}^{K}e^{z_{k}}}}\).

Methods

__init__

backward

Computes the backward step

forward

Computes a forward pass

predictions

Converts outputs to predictions

set_adjacent_layers

Set adjacent layers which are needed for the model to iterate through the layers.

backward(dvalues)[source]#

Computes the backward step

The derivative of the softmax function will be calculated as follows: \(\frac {\partial S(z_{i})}{\partial z_{j}} = {\begin{cases} S(z_{i}) \cdot (1 - S(z_{i})) & \text{if } i = j \\ - S(z_{i}) \cdot S(z_{j}) & \text{if } i \neq j \end{cases}}\).

Return type:

None

Parameters:

dvalues (numpy.ndarray) – Derived gradient from the previous layers (reversed order).

forward(inputs)[source]#

Computes a forward pass

The softmax activation function is defined as \(\sigma (\mathbf {z} )_{j}={\frac {e^{z_{j}}}{\sum _{k=1}^{K}e^{z_{k}}}}\).

Return type:

None

Parameters:

inputs (np.ndarray) – Input values from previous neural layer.

predictions(outputs)[source]#

Converts outputs to predictions

The softmax activation function calculates the confidence for each class. Since the the softmax function does not only support binary tasks, but also multiclass problems, the user must receive the index of the class with the highest confidence score.

Return type:

ndarray

Parameters:

outputs (numpy.ndarray) – Output computed by the softmax activation function

Returns:

Matrix containing the class indices with the highest confidence

Return type:

numpy.ndarray

set_adjacent_layers(previous_layer, next_layer)#

Set adjacent layers which are needed for the model to iterate through the layers.

Parameters:
  • previous_layer (_Layer) – Layer that is previous to this layer.

  • next_layer (_Layer) – Layer that is subsequent to this layer.