- Deep Learning Essentials
- Wei Di Anurag Bhardwaj Jianing Wei
- 129字
- 2025-02-28 20:00:27
Sigmoid or logistic function
A sigmoid function has a distinctive S shape and it is a differentiable real function for any real input value. Its range is between 0 and 1. It is an activation function in the following form:
Its first derivative, which is used during backpropagation of the training step, has the following form:
The implementation is as follows:
def sigmoid(x):
return tf.div(tf.constant(1.0),
tf.add(tf.constant(1.0), tf.exp(tf.neg(x))))
The derivative of a sigmoid function is as follows:
def sigmoidprime(x):
return tf.multiply(sigmoid(x), tf.subtract(tf.constant(1.0), sigmoid(x)))
However, a sigmoid function can cause the gradient vanishing problem or saturation of the gradient. It is also known to have a slow convergence. Therefore, in practical use, it is not recommended to use a sigmoid as the activation function, ReLU has become more popular.