I'm working on a minimization problem that involves the standard logistic function
$f(x) = \frac{1}{1+e^{-x}}$
along with its simple derivative
$f'(x) = f(x) \cdot (1 - f(x))$
The correctness of this derivative is easily proven, but I wonder how to get to this specific form using Mathematica. Deriving $f(x)$ and simplifying gives me:
In[1]:= f[x_] := 1 / (1 + Exp[-x])
In[2]:= der = Simplify[D[f[x], x]]
x
E
Out[2]= ---------
x 2
(1 + E )
Obviously this is correct, but since I will have to calculate $f(x)$ and $f'(x)$ at the same time, expressing $f'(x)$ in terms of $f(x)$ allows for faster computation.
I tried to use assumptions for Simplify
like this:
Simplify[der, f[x] == fx]
but that doesn't work; neither did similar things with Reduce
. The /.
operator doesn't work either because 1 / (1 + Exp[-x])
doesn't appear in Out[2]
exactly in that form.
I will have to calculate the derivatives of other functions as well and it would be nice to see if those are more easily expressed in terms of $f(x)$.
Simplify[D[f[x], x] - f[x] (1 - f[x])]
$\endgroup$LogisticSigmoid[]
is built-in, FYI. $\endgroup$