**TI 30Xa Algorithm: ****The Sigmoid Function and its Integral**

**The
Sigmoid Function**

The sigmoid function is defined as:

S = 1 / (1 + e^(-x))

If we multiply the last equation by e^(x) / e^(x), we get:

S = e^(x) / (e^(x) + 1) = e^(x) / (1 + e^(x))

The sigmoid function takes functions from the real numbers and maps them to the interval (0,1). If x → -∞, S → 0. If x → +∞, S → 1.

The inverse of the sigmoid function is the logit function, from which we can derive:

S = 1 / (1 + e^(-x))

1 / S = 1 + e^(-x)

1 / S – 1 = e^(-x)

ln( 1 / S – 1 ) = -x

ln( (1 – S) / S ) = -x (Note: 1 / S – 1 = 1 / S – S / S = (1 – S) / S )

-ln( (1 – S) / S ) = x

ln( S / (1 – S)) = x (Note: For any x, -ln(x) = ln(x^(-1)) = ln(1 / x))

The rest of the blog will focus on the sigmoid function.

**The
Integral of the Sigmoid Function**

Funding the area of the curve under the sigmoid function is pretty straight forward.

∫ 1 / (1 + e^(-x)) dx

= ∫ e^(x) / (e^(x) + 1) dx

Let u = e^(x) + 1. The du = e^(x) dx and:

∫ du / u

= ln | u | + C

= ln (e^(x) +1) + C (since e^(x) + 1 > 0 for all real x)

The definite integral (area) can be calculated as:

x = b

∫ e^(x) / (e^(x) + 1) dx

x = a

= ln (1 + e^b) – ln (1 + e^a)

What if we are given the area, A (capital A), from negative infinity to a value x? Here we are finding the lower tail area.

t = x

∫ e^(t) / (e^(t) + 1) dx = A

t = -∞

ln(1 + e^(x)) – ln(1 + e^(-∞)) = A

Note that e^(-∞) → 0 as t → -∞

We can estimate that:

ln(1 + e^(x)) – ln( 1 ) = A

ln(1 + e^(x)) – 0 = A

1 + e^(x) = e^(A)

e^(x) = e^(A) – 1

x = ln(e^(A) – 1)

**TI-30Xa
Algorithms**

Sigmoid function:

S = 1 / (1 + e^(-x)) = e^(x) / (e^(x) + 1)

Algorithm:

[ (
] x [ +/- ] [ 2^{nd} ] [ LN ] {e^x} [ + ] 1 [ ) ] [ 1/x ] [
= ]

Example:

S(1.5):

[ (
] 1.5 [ +/- ] [ 2^{nd} ] [ LN ] {e^x} [ + ] 1 [ ) ] [ 1/x ]
[ = ]

Result: 0.817574476

Integral of the sigmoid function:

x = b

∫ e^(x) / (e^(x) + 1) dx

x = a

Algorithm:

[ (
] b [ 2^{nd} ] [ LN ] {e^x} [ + ] 1 [ ) ] [ LN ]

[ -
] [ ( ] a [ 2^{nd} ] [ LN ] {e^x} [ + ] 1 [ ) ] [ LN ] [ = ]

Example:

x = 3

∫ e^(x) / (e^(x) + 1) dx

x = 0

(a = 0, b = 3)

[ (
] 3 [ 2^{nd} ] [ LN ] {e^x} [ + ] 1 [ ) ] [ LN ]

[ -
] [ ( ] 0 [ 2^{nd} ] [ LN ] {e^x} [ + ] 1 [ ) ] [ LN ] [ = ]

Result: 2.355440171

Find x given lower tail area:

x = ln(e^(A) – 1)

Algorithm:

[ (
] A [ 2^{nd} ] [ LN ] {e^x} [ - ] 1 [ ) ] [ LN ] [ = ]

Example:

Area: A = 0.5

[ (
] 0.5 [ 2^{nd} ] [ LN ] {e^x} [ - ] 1 [ ) ] [ LN ] [ = ]

Result: -0.4327521296

Until next time,

Eddie

All original content copyright, © 2011-2024. Edward Shore. Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited. This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.