pyml.neural_network.layer.activation.sigmoid.Sigmoid#

class Sigmoid[source]#

Bases: _Activation

Sigmoid activation function

The sigmoid function \(\sigma (x)={\frac {1}{1+e^{-x}}}\) is a non-linear activation function.

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 sigmoid function is \(\sigma' (x) = \sigma (x) (1 - \sigma (x))\).

Return type:

None

Parameters:

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

forward(inputs)[source]#

Computes a forward pass

Computes the confidences for each input using this function: \(\sigma (x)={\frac {1}{1+e^{-x}}}={\frac {e^{x}}{e^{x}+1}}=1-\sigma (-x)\).

Return type:

None

Parameters:

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

predictions(outputs)[source]#

Converts outputs to predictions

Decodes the confidences for each prediction to binary predictions, meaning 0 or 1. If single confidence is > 0.5, than 1, true etc. is set for prediction outcome.

TODO check type of outputs, could also be np.array

Return type:

ndarray

Parameters:

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

Returns:

Matrix containing the class predictions; values are either zero or one

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.