Sympy integration does not give the correct answer

The standard logistic function is encoded as sigmain the following code:

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

logistic function

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

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

If you need the correct answer, you need to calculate the next limit, which gives log(2), as it should be.

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

Why SymPydoesn't sigma integrate correctly?

+4
source share
1 answer

This is similar to a bug that has been fixed in the SymPy development branch (and will be fixed in SymPy 1.0, which will be released shortly).

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

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

Source: https://habr.com/ru/post/1629962/


All Articles