0

In an Udacity machine learning class it is showing the following simplification.

\begin{align} \sigma'(x) & = \frac{\partial}{\partial x} \frac{1}{1+e^{-x}} \\ & = \frac{e^{-x}}{(1+e^{-x})^2} \\ & = \frac{1}{1+e^{-x}} \cdot \frac{e^{-x}}{1+e^{-x}} \\ & = \sigma(x)(1-\sigma(x)) \end{align}

(Original at https://i.stack.imgur.com/9ihZ2.gif)

I am not following the line 1 to 2 and line 3 to 4. For line 1 -> 2, shouldn't that now be 1 / ( - (1 + e^x))?

The for line 3 -> 4, the sigmoid is 1 / (1 + e^x) and so I understand the sigmoid(x) part of the equation. But how does e^x/(1+e^x) become (1 - sigmoid(x))? Shouldn't it be e^-x / sigmoid(x)?

(I knew all this real well 40 years ago when I earned a math degree, but 40 years of never touching this stuff and all that knowledge is gone...)

jjagmath
  • 18,214

1 Answers1

4

From line $1$ to line $2$: This is an application of the chain rule. We have

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

From line $3$ to line $4$: This is a recognition that

\begin{align} \frac{e^{-x}}{1+e^{-x}} & = \frac{1+e^{-x}-1}{1+e^{-x}} \\ & = 1 - \frac{1}{1+e^{-x}} \\ & = 1 - \sigma(x) \end{align}

Brian Tung
  • 34,160
  • I made a slight change to your answer to make clearer the use of the chain rule. – jjagmath Aug 22 '21 at 17:31
  • @jjagmath: Ahh yes, that was not a lack of clarity; that was an actual error! Thanks for the catch. – Brian Tung Aug 22 '21 at 17:33
  • Thank you very much. Not getting 3 -> 4 myself is embarrassing. I think it's going to be a lot more trial and error as I relearn all of this. Thanks for the help. – David Thielen Aug 22 '21 at 17:35
  • @DavidThielen: You're welcome! We've all missed things that we think in retrospect should've been obvious. But the silver lining is that at least we think it's obvious in retrospect; it's objectively worse if we still don't see it afterward. – Brian Tung Aug 22 '21 at 17:48