It seems there was a flurry of development over the winter holidays.
Tom’s Meijer-G integration code was merged into master giving SymPy an incredibly powerful definite integration engine. This encouraged me to finish up the pull request for random variables.
Earlier this morning we finally merged it in and sympy.stats is now in master. If you’re interested please play with it and generate feedback. At the very least it should be able to solve many of your introductory stats homework problems :)
Actually, I tried using it for a non-trivial example last month and generated an integral which killed the integration engine (mostly this was due to a combination of trigonometric and delta functions). However, I still really wanted the result. The standard solution to analytically intractable statistics problems is to sample. This pushed me to build a monte carlo engine into sympy stats.
The family of stats functions P, E, Var, Density, Given, now have a new member, Sample. You can generate a random sample of any random expression as follows
>>> from sympy.stats import * >>> X, Y = Die(6), Die(6) >>> roll = X+Y >>> Sample(roll) 10 >>> Sample(roll) 5 >>> Sample(X, roll>10) # Sample X given that X+Y>10 6
Sampling is of course more fail-proof than solving integrals and so expressions can be made arbitrarily complex without issue. This sampling mechanism is also built into the probability and expectation functions using the keyword “numsamples”
>>> from sympy.stats import * >>> X, Y = Normal(0, 1), Normal(0, 1) >>> P(X>Y) 1/2 >>> P(X>Y, numsamples = 1000) 499 ──── 1000 >>> E(X+Y) 0 >>> E(X+Y, numsamples = 1000) -0.0334982435603208
GSoC 2012 was announced a couple days ago. I’m excited to see what projects are proposed.