Logistic function: Difference between revisions

From Calculus
 
(3 intermediate revisions by the same user not shown)
Line 18: Line 18:
===Probabilistic interpretation===
===Probabilistic interpretation===


The logistic function transforms the logarithm of the odds to the actual probability. Explicitly, given a probability <math>p</math> (strictly between 0 and 1)of an event occurring, the odds in favor of <math>p</math> are given as:
The logistic function transforms the logarithm of the odds to the actual probability. Explicitly, given a probability <math>p</math> (strictly between 0 and 1) of an event occurring, the odds in favor of <math>p</math> are given as:


<math>\frac{p}{1 - p}</math>
<math>\frac{p}{1 - p}</math>
Line 39: Line 39:
| [[range]] || the [[open interval]] <math>(0,1)</math>, i.e., the set <math>\{ x \mid 0 \le x \le 1 \}</math>
| [[range]] || the [[open interval]] <math>(0,1)</math>, i.e., the set <math>\{ x \mid 0 \le x \le 1 \}</math>
|-
|-
| [[derivative]] || the derivative is <math>\frac{-e^{-x}}{(1 + e^{-x})^2}</math>.<br>If we denote the logistic function by the letter <math>g</math>, then we can also write the derivative as <math>g'(x) = g(x)g(-x) = g(x)(1 - g(x))</math>
| [[derivative]] || the derivative is <math>\frac{e^{-x}}{(1 + e^{-x})^2}</math>.<br>If we denote the logistic function by the letter <math>g</math>, then we can also write the derivative as <math>g'(x) = g(x)g(-x) = g(x)(1 - g(x))</math>
|-
|-
| [[second derivative]] || If we denote the logistic function by the letter <math>g</math>, then we can also write the derivative as <math>g''(x) = g'(x)(1 - 2g(x)) = g(x)(1 - g(x))(1 - 2g(x)) = g(x)g(-x)(1 - 2g(x)) = g(x)g(-x)(g(x) - g(-x))</math>
| [[second derivative]] || If we denote the logistic function by the letter <math>g</math>, then we can also write the derivative as <math>g''(x) = g'(x)(1 - 2g(x)) = g(x)(1 - g(x))(1 - 2g(x)) = g(x)g(-x)(1 - 2g(x)) = g(x)g(-x)(g(-x) - g(x))</math>
|-
|-
| [[logarithmic derivative]] || the logarithmic derivative is <math>\frac{e^{-x}}{1 + e^{-x}}</math><br>If we denote the logistic function by <math>g</math>, the logarithmic derivative is <math>g(-x)</math>
| [[logarithmic derivative]] || the logarithmic derivative is <math>\frac{e^{-x}}{1 + e^{-x}}</math><br>If we denote the logistic function by <math>g</math>, the logarithmic derivative is <math>g(-x)</math>
Line 85: Line 85:


<math>g'(x) = g(x)(1 - g(x))</math>
<math>g'(x) = g(x)(1 - g(x))</math>
===Second derivative===
====Using the expression <math>g(x)(1 - g(x))</math> for <math>g'</math>====
From the above, we have:
<math>g'(x) = g(x) - (g(x))^2</math>
Differentiating both sides, we obtain:
<math>g''(x) = g'(x) - 2g(x)g'(x)</math>
This simplifies to:
<math>g''(x) = g'(x)(1 - 2g(x))</math>
We can now re-use the expression for <math>g'</math> and obtain:
<math>g''(x) = g(x)(1 - g(x))(1 - 2g(x))</math>
====Using the expression <math>g(x)g(-x)</math> for <math>g'</math>====
We have:
<math>g'(x) = g(x)g(-x)</math>
Using the [[product rule for differentiation]] and the [[chain rule for differentiation]], we get:
<math>g''(x) = g'(x)g(-x) + (-g(x)g'(-x))</math>
Note from the expression that <math>g'</math> shows that <math>g'</math> is even, so we can rewrite <math>g'(-x)</math> as <math>g'(x)</math>, and we get:
<math>g''(x) = g'(x)g(-x) - g'(x)g(x) = g'(x)(g(-x) - g(x))</math>
We can re-use the expression <math>g'(x) = g(x)g(-x)</math> and obtain:
<math>g''(x) = g(x)g(-x)(g(-x) - g(x))</math>


==Functional equations==
==Functional equations==
Line 177: Line 215:
* The graph of <math>g</math> has half-turn symmetry about the point <math>(0, 1/2)</math>.
* The graph of <math>g</math> has half-turn symmetry about the point <math>(0, 1/2)</math>.
* <math>g'</math> is an even function. Note that this can also be seen from the actual expression: <math>g'(x) = g(x)g(-x)</math>. But we don't need the actual expression to deduce that it is even -- the functional equation above gives evenness.
* <math>g'</math> is an even function. Note that this can also be seen from the actual expression: <math>g'(x) = g(x)g(-x)</math>. But we don't need the actual expression to deduce that it is even -- the functional equation above gives evenness.
* <math>g''</math> is an odd function. This can be directly deduced from <math>g'</math> being even, but can also be verified from the actual expression: <math>g''(x) = g'(x)(1 - 2g(x)) = g'(x)(g(x) - g(-x))</math>.
* <math>g''</math> is an odd function. This can be directly deduced from <math>g'</math> being even, but can also be verified from the actual expression: <math>g''(x) = g'(x)(1 - 2g(x)) = g'(x)(g(-x) - g(x))</math>.


==Integration==
==Integration==

Latest revision as of 14:42, 6 July 2019

Definition

The logistic function is a function with domain R and range the open interval (0,1), defined as:

x↦11+e−x

Equivalently, it can be written as:

x↦exex+1

Yet another form that is sometimes used, because it makes some aspects of the symmetry more evident, is:

x↦ex/2ex/2+e−x/2

For this page, we will denote the function by the letter g.

We may extend the logistic function to a function [−∞,∞]→[0,1], where g(−∞)=0 and g(∞)=1.

Probabilistic interpretation

The logistic function transforms the logarithm of the odds to the actual probability. Explicitly, given a probability p (strictly between 0 and 1) of an event occurring, the odds in favor of p are given as:

p1−p

This could take any value in (0,∞)

The logarithm of odds is the expression:

ln(p1−p)

If x equals the above expression, then the function describing p in terms of x is the logistic function.

Key data

Item Value
default domain all of R, i.e., all reals
range the open interval (0,1), i.e., the set {x∣0≤x≤1}
derivative the derivative is e−x(1+e−x)2.
If we denote the logistic function by the letter g, then we can also write the derivative as g′(x)=g(x)g(−x)=g(x)(1−g(x))
second derivative If we denote the logistic function by the letter g, then we can also write the derivative as g″(x)=g′(x)(1−2g(x))=g(x)(1−g(x))(1−2g(x))=g(x)g(−x)(1−2g(x))=g(x)g(−x)(g(−x)−g(x))
logarithmic derivative the logarithmic derivative is e−x1+e−x
If we denote the logistic function by g, the logarithmic derivative is g(−x)
antiderivative the function x↦ln(ex+1)+C=−ln(g(−x))+C
critical points none
critical points for the derivative (correspond to points of inflection for the function) x=0; the corresponding point on the graph of the function is (0,1/2).
local maximal values and points of attainment none
local minimum values and points of attainment none
intervals of interest increasing and concave up on (−∞,0)
increasing and concave down on (0,∞)
horizontal asymptotes asymptote at y=0 corresponding to the limit for x→−∞
asymptote at y=1 corresponding to the limit for x→∞
inverse function inverse logistic function or log-odds function given by x↦ln(x1−x)

Differentiation

First derivative

Consider the expression for g(x):

g(x)=11+e−x=(1+e−x)−1

We can differentiate this using the chain rule for differentiation (the inner function being x↦1+e−x and the outer function being the reciprocal function t↦1/t. We get:

g′(x)=−(1+e−x)−2(−e−x)

Simplifying, we get:

g′(x)=e−x(1+e−x)2

We can write this in an alternate way that is sometimes more useful. We split the expression as a product:

g′(x)=(11+e−x)(e−x1+e−x)

The first factor on the right is g(x), and the second factor is 1−g(x), so this simplifies to:

g′(x)=g(x)(1−g(x))

Second derivative

Using the expression g(x)(1−g(x)) for g′

From the above, we have:

g′(x)=g(x)−(g(x))2

Differentiating both sides, we obtain:

g″(x)=g′(x)−2g(x)g′(x)

This simplifies to:

g″(x)=g′(x)(1−2g(x))

We can now re-use the expression for g′ and obtain:

g″(x)=g(x)(1−g(x))(1−2g(x))

Using the expression g(x)g(−x) for g′

We have:

g′(x)=g(x)g(−x)

Using the product rule for differentiation and the chain rule for differentiation, we get:

g″(x)=g′(x)g(−x)+(−g(x)g′(−x))

Note from the expression that g′ shows that g′ is even, so we can rewrite g′(−x) as g′(x), and we get:

g″(x)=g′(x)g(−x)−g′(x)g(x)=g′(x)(g(−x)−g(x))

We can re-use the expression g′(x)=g(x)g(−x) and obtain:

g″(x)=g(x)g(−x)(g(−x)−g(x))

Functional equations

Symmetry equation

The logistic function g has the property that its graph y=g(x) has symmetry about the point (0,1/2). Explicitly, it satisfies the functional equation:

g(x)+g(−x)=1

We can see this algebraically:

g(−x)=11+e−(−x)=11+ex

Multiply numerator and denominator by e−x, and get:

g(−x)=e−xe−x+1=1−11+e−x=1−g(x)

Differential equation

As discussed in the #First derivative section, the logistic function satisfies the condition:

g′(x)=g(x)(1−g(x))

Therefore, y=g(x) is a solution to the autonomous differential equation:

dydx=y(1−y)

The general solution to that equation is the function y=g(x+C) where C∈R. The initial condition y=1/2 at x=0 pinpoints the logistic function uniquely.

Points and intervals of interest

Critical points

The function has no critical points. To see this, note that the derivative is:

g′(x)=g(x)(1−g(x))=e−x(1+e−x)2

Note that the numerator is never zero, nor is the denominator. Therefore, the function is always defined and nonzero.

Intervals of increase and decrease

The derivative:

g′(x)=g(x)(1−g(x))=e−x(1+e−x)2

is always positive. So the function is increasing on all of R.

The asymptotic values are:

limx→∞11+e−x=11=1

and:

limx→−∞11+e−x=1→∞=0

In other words, the range of the function is the open interval (0,1), and it increases throughout its domain.

Points of inflection

The second derivative is:

g″(x)=g(x)(1−g(x))(1−2g(x))=g′(x)(1−2g(x))

We already noted that g′(x) is always defined and nonzero, so the only way for g″(x) to be zero is if 1−2g(x)=0< or g(x)=1/2. This solves to:

11+e−x=12

This solves to e−x=1, or x=0.

Thus, the second derivative is 0 at the point (0,1/2), i.e., with x=0 and g(x)=1/2.

Intervals of concave up and down

As above, we have:

g″(x)=g′(x)(1−2g(x))

We also noted that g′(x)>0 for all x. Therefore, g″(x)>0 for x<0 and g″(x)<0 for x>0. Therefore, g is:

  • concave up for x<0, i.e., x∈(−∞,0)
  • concave down for x>0, i.e., x∈(0,∞)

Symmetry

We discussed above a functional equation satisfied by g:

g(−x)=1−g(x)

From this, the following can be deduced:

  • The graph of g has half-turn symmetry about the point (0,1/2).
  • g′ is an even function. Note that this can also be seen from the actual expression: g′(x)=g(x)g(−x). But we don't need the actual expression to deduce that it is even -- the functional equation above gives evenness.
  • g″ is an odd function. This can be directly deduced from g′ being even, but can also be verified from the actual expression: g″(x)=g′(x)(1−2g(x))=g′(x)(g(−x)−g(x)).

Integration

First antiderivative

Direct computation

We have:

∫g(x)dx=∫1dx1+e−x=∫exdxex+1=ln(ex+1)+C

Computation in terms of functional equations for the logistic function

We have:

g′(x)=g(x)(1−g(x))

We also have that 1−g(x)=g(−x), so we get:

g′(x)=g(x)g(−x)

This can be rewritten as:

ddx(ln(g(x))=g(−x)

By the chain rule for differentiation, we get:

ddx(ln(g(−x))=−g(x)

Thus:

∫g(x)dx=−ln(g(−x))+C

This can be simplified and verified to be the same as the answer obtained by direct computation.