Sympy integrate does not give the right answer

The standard logistic function is coded as sigma in the following code:

from sympy import *
x, sigma = symbols("x sigma")
sigma = 1/(1 + exp(-x))
plot(sigma);

logistic function

When you try calculate the area below the curve for negative x:

integrate(sigma,(x, -oo, 0))  # This gives NaN

If you need the right answer you need to calculate the following limit, that gives log(2) as it must be.

t = symbols("t")
limit(integrate(sigma, (x, -t, 0)), t, oo) # log(2)

Why SymPyis not integrating sigma properly?

Upvotes: 4

Views: 265

Answers (1)

asmeurer
asmeurer

Reputation: 91490

This looks like a bug which has been fixed in the SymPy development branch (and will be fixed in SymPy 1.0, to be released soon).

In [31]: sigma = 1/(1 + exp(-x))

In [32]: integrate(sigma,(x, -oo, 0))
Out[32]: log(2)

Upvotes: 1

Related Questions