search
Search
Unlock 100+ guides
search toc
close
Cancel
Post
account_circle
Profile
exit_to_app
Sign out
search
keyboard_voice
close
Searching Tips
Search for a recipe:
"Creating a table in MySQL"
Search for an API documentation: "@append"
Search for code: "!dataframe"
Apply a tag filter: "#python"
Useful Shortcuts
/ to open search panel
Esc to close search panel
to navigate between search results
d to clear all current filters
Enter to expand content preview
Doc Search
Code Search Beta
SORRY NOTHING FOUND!
mic
Start speaking...
Voice search is only supported in Safari and Chrome.
Shrink
Navigate to
smart_toy
Machine Learning
32 guides
keyboard_arrow_down
chevron_leftActivation functions
check_circle
Mark as learned
thumb_up
0
thumb_down
0
auto_stories Bi-column layout
settings

# Comprehensive Guide on Sigmoid Function

schedule May 20, 2023
Last updated
local_offer
Machine LearningPython
Tags
mode_heat
Master the mathematics behind data science with 100+ top-tier guides
Start your free 7-days trial now!
Definition.

# What is the sigmoid function?

The sigmoid function, often denoted as $\sigma(x)$, is defined as follows:

$$\sigma(x)=\frac{1}{1+e^{-x}}=\frac{e^x}{1+e^x}$$

The sigmoid function is named as such because it is S-shaped, as can be seen from its graph:

Note the following:

• the domain of the sigmoid function is unbounded from $-\infty$ to $\infty$.

• the range is bounded between $0$ and $1$; the output can become extremely close to $0$ or $1$, but it will never reach the boundaries.

Theorem.

# Derivative of Sigmoid Function

The beauty of the sigmoid function is that its derivative is extremely clean:

$$\sigma'(x)=\sigma(x)\cdot\left[1-\sigma(x)\right]$$

This is a very useful property because we often encounter situations in machine learning where we need to compute the derivative of the sigmoid function. For instance, the update rule for gradient descent in logistic regression requires this derivative.

The proof does not require any advanced calculus:

\begin{align*} \frac{d\sigma(x)}{dx}&=\frac{d}{dx}\left(\frac{1}{1+e^{-x}}\right) \\ &=\frac{d}{dx}(1+e^{-x})^{-1} \\ &=-(1+e^{-x})^{-2}\cdot \frac{d}{dx}(1+e^{-x}) \\ &=-(1+e^{-x})^{-2}\cdot (-e^{-x}) \\ &=\frac{e^{-x}}{(1+e^{-x})^2} \\ &=\frac{1}{1+e^{-x}}\left(\frac{e^{-x}}{1+e^{-x}}\right) \\ &=\frac{1}{1+e^{-x}}\left(\frac{1+e^{-x}-1}{1+e^{-x}}\right) \\ &=\frac{1}{1+e^{-x}}\left(\frac{1+e^{-x}}{1+e^{-x}}-\frac{1}{1+e^{-x}}\right) \\ &=\frac{1}{1+e^{-x}}\left(1-\frac{1}{1+e^{-x}}\right) \\ &=\sigma(x)\cdot \left(1-\sigma (x)\right) \\ \end{align*}

## Graph of Sigmoid function and its derivative

Here's a graph of the sigmoid function and its derivative:

# Implementation using Python

Here's the sigmoid function as well as its derivative implemented in Python using NumPy:

import numpy as np

def sigmoid(x):
return np.exp(x) / (1 + np.exp(x))

def sigmoid_derivative(x):
return sigmoid(x) * (1 - sigmoid(x))
Edited by 0 others
thumb_up
thumb_down
Comment
Citation
Ask a question or leave a feedback...
thumb_up
0
thumb_down
0
settings
Enjoy our search
Hit / to insta-search docs and recipes!