A little notebook that came out of this work, is case anyone is interested:
http://nbviewer.ipython.org/github/justinvf/algorithmshop/blob/master/20140715-mixture-models/pearson_gaussian_mixtures.ipynb
On Wednesday, July 16, 2014 1:13:42 PM UTC-7, Justin Vincent wrote:
>
> Thanks! This works great.
>
> On Tuesday, July 15, 2014 2:28:11 PM UTC-7, Matthew wrote:
>>
>> Use sympy.stats, not sympy.statistics
>>
>> In [1]: x, mu = symbols('x,mu', real=True)
>>
>> In [2]: sigma = symbols('sigma', positive=True)
>>
>> In [3]: from sympy.stats import *
>>
>> In [4]: X = Normal('X', mu, sigma)
>>
>> In [5]: moment?
>> Type: function
>> String form: <function moment at 0x7fc3fbbe2b18>
>> File: /home/mrocklin/workspace/sympy/sympy/stats/rv_interface.py
>> Definition: moment(X, n, c=0, condition=None, **kwargs)
>> Docstring:
>> Return the nth moment of a random expression about c i.e. E((X-c)**n)
>> Default value of c is 0.
>>
>> Examples
>> ========
>>
>> >>> from sympy.stats import Die, moment, E
>> >>> X = Die('X', 6)
>> >>> moment(X, 1, 6)
>> -5/2
>> >>> moment(X, 2)
>> 91/6
>> >>> moment(X, 1) == E(X)
>> True
>>
>> In [6]: moment(X, 1)
>> Out[6]: μ
>>
>> In [7]: moment(X, 2)
>> Out[7]:
>> 2 2
>> μ + σ
>>
>> In [8]: moment(X, 3)
>> Out[8]:
>> 3 2
>> μ + 3⋅μ⋅σ
>>
>> In [9]: moment(X, 4)
>> Out[9]:
>> 4 2 2 4
>> μ + 6⋅μ ⋅σ + 3⋅σ
>>
>>
>>
>> On Tue, Jul 15, 2014 at 1:40 PM, Justin Vincent <[email protected]>
>> wrote:
>>
>>> Wanted to get the moments of a Normal distribution WRT mu and sigma, a
>>> la:
>>>
>>> http://en.wikipedia.org/wiki/Normal_distribution#Moments
>>>
>>> For starters, this outputs 1 for one for one crazy domains, and then
>>> leaves the integral unevaluated on the rest of the domain. But it gets one,
>>> so I'm cool with that.
>>>
>>> from sympy.statistics import Normal
>>> from sympy import symbols, integrate
>>> f = Normal(mu, sigma).pdf(x)
>>> x, mu, sigma = symbols('x mu sigma')
>>> integrate(f, (x,-oo, oo))
>>>
>>> Then when I get the first moment, it really starts to go crazy though,
>>> and leaves it all indefinite:
>>> integrate(f * x, (x, -oo, oo))
>>>
>>> What approach should I take here if I wanted to get those values cited
>>> in wikipedia? Haven't used Sympy much before. Thanks in advance.
>>>
>>> Justin
>>>
>>> --
>>> 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 http://groups.google.com/group/sympy.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/sympy/2babc41b-0ab4-443c-a75b-d5910ce16c21%40googlegroups.com
>>>
>>> <https://groups.google.com/d/msgid/sympy/2babc41b-0ab4-443c-a75b-d5910ce16c21%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
--
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 http://groups.google.com/group/sympy.
To view this discussion on the web visit
https://groups.google.com/d/msgid/sympy/8e7e3a2a-639c-4816-a892-872e94e10ac9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.