Class Sigmoid
- Namespace
- NeuralNetworks.Operations.ActivationFunctions
- Assembly
- NeuralNetworks.dll
Sigmoid (Logistic) activation function.
public class Sigmoid : ActivationFunction<float[,], float[,]>
- Inheritance
-
Sigmoid
- Inherited Members
Remarks
Formula: f(x) = 1 / (1 + exp(-x)) = σ(x)
Input Gradient Formula: ∂L/∂x = ∂L/∂y · f(x) · (1 - f(x)) = ∂L/∂y · σ(x) · (1 - σ(x))
Output Range: (0, 1)
Description: The sigmoid function is a smooth, S-shaped curve that squashes input values into the range (0, 1). It is commonly used in binary classification tasks, especially in the output layer for predicting probabilities. The function is differentiable everywhere, making it suitable for gradient-based optimization methods.
Remarks: The sigmoid function suffers from vanishing gradient problems for large positive or negative inputs, as the gradient approaches zero at the extremes. This can slow down training in deep networks. For hidden layers, alternatives like ReLU2D or Tanh2D are often preferred. The sigmoid is computationally more expensive than ReLU due to the exponential operation.
Methods
CalcInputGradient(float[,])
Calculates input gradient.
protected override float[,] CalcInputGradient(float[,] outputGradient)
Parameters
outputGradientfloat[,]
Returns
- float[,]
Remarks
Based on outputGradient, calculates changes in input.
CalcOutput(bool)
Calculates the output of the Sigmoid activation function. The range is (0, 1).
protected override float[,] CalcOutput(bool inference)
Parameters
inferenceboolIndicates whether the calculation is for inference or training.
Returns
- float[,]
A two-dimensional array of floating-point values representing the output of the Sigmoid activation function.
ToString()
Returns a string that represents the current operation.
public override string ToString()
Returns
- string
A string that represents the current operation.
Remarks
It is used in a layer/model description.