During the course of writing a textbook, I discovered many problems with the Stats module. I've attached an ipynb file showing the problems. Here they are in brief.
1. This gives the correct answer, but not in the best form. I can't
figure out how to use Sympy to simplify the condition from $e^{-y} \le 1$
to $y>0$.
u, x, y = symbols('u x y', positive=True, real=True)
U = Uniform("u",0,1)
Y = -log(U)
simplify(density(Y)(y))
... Piecewise((exp(-y), exp(-y) <= 1), (0, True))
2. Conditional probabilities with the Uniform distribution don't work.
These give NaNs when the answers are simple.
P(U<0.3, U<0.5), P(U<S(1)/3, U<S(1)/2)
... NaN, NaN
3. These answers are wrong. The condition should be $y \le 0.5$, not $y \le
1$, and same for $u$.
Y = given(U, U<1/2)
density(Y)(y), density(U,U<1/2)(u)
... (2.0*Piecewise((1, y <= 1), (0, True)), 2.0*Piecewise((1, u <= 1), (0,
True)))
4. These are also wrong. Both should be 0.25.
E(U, U<1/2), E(given(U,U<1/2))
... NaN, NaN
5. This gives a Python error. The correct answer is easy to calculate.
density(1/U)(u)
---------------------------------------------------------------------------
TypeError Traceback (most recent call
last)<ipython-input-11-f8cdc2170015> in <module>()----> 1 density(1/U)(u)
/Users/boncelet/anaconda/lib/python3.6/site-packages/sympy/stats/rv.py in
density(expr, condition, evaluate, numsamples, **kwargs) 717
**kwargs) 718 --> 719 return Density(expr,
condition).doit(evaluate=evaluate, **kwargs) 720 721
/Users/boncelet/anaconda/lib/python3.6/site-packages/sympy/stats/rv.py in
doit(self, evaluate, **kwargs) 667 isinstance(pspace(expr),
SinglePSpace)): 668 return expr.pspace.distribution--> 669
result = pspace(expr).compute_density(expr, **kwargs) 670 671
if evaluate and hasattr(result, 'doit'):
/Users/boncelet/anaconda/lib/python3.6/site-packages/sympy/stats/crv.py in
compute_density(self, expr, **kwargs) 400 raise ValueError("Can
not solve %s for %s"%(expr, self.value)) 401 fx =
self.compute_density(self.value)--> 402 fy = sum(fx(g) * abs(g.diff(y))
for g in gs) 403 return Lambda(y, fy) 404
TypeError: 'Complement' object is not iterable
6. This gives the same Python error (error message deleted):
X = Exponential("x",1)
density(1/X)(x)
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit
https://groups.google.com/d/msgid/sympy/de3ca0be-e51a-4528-b67c-d78a909bf8e7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
SympyStatsProblems.ipynb
Description: Binary data
