T <https://groups.google.com/forum/#!topic/sympy/gRgNYef3oyc>hanks
Matthew, Is the following snippet of use? Yes and No.
The lines 5 and 6 are a useful tip; I missed the prod method, that is nice.
And yes for two N-distributions explicit solutions are to be found in the
litt and SymPy can find them as it can for longer products and also for the
uniform distribution which is also of use to me. However, I want both the
algebraic expression and numerical results. In the past lambdify has helped
me often and here it works also.
My problem is that when I have PNs as the product of n distributions an mu
and sigma symbolic arrays of n means and stdevs then after:
MeanPns = E(PNs)
meanPNs = lambdify([mu, sigma], MeanPNs)
I cannot calculate the mean of the product of two (or more) Ns with m=[1.0,
1.0] and s= [0.05, 0.15] by calling
average = meanPNs(m, s)
This gives an error saying that meanPNs expects 4 arguments an only 2 are
given.
So you need the intermediate step
ms = m + s
and than
average = meanPNs(*ms)
whereby meanPS gets the 4 Or rather 2n) arguments it wants.
This works but I do not consider it an elegant solution so I wondered
whether there is a more elegant solution.
By the way, the purpose of it is to show in a course on uncertainty in
measurement that the Law of Propagation of Uncertainties (LPU) under
estimates the standard uncertainty and that the resulting distribution is
skewed in violation to the common assumption that the Central Limit Theorem
(CLT) would be valid. Showing this both through equations an numbers.
Thanks again for paying attention, cheers, Janwillem
On Friday, 30 August 2013 06:00:21 UTC+2, Matthew wrote:
>
> Is the following snippet of use?
>
> In [1]: from sympy.stats import *
>
> In [2]: n = 5
>
> In [3]: mus = [Symbol('mu'+str(i), bounded=True) for i in range(n)]
>
> In [4]: sigmas = [Symbol('sigma'+str(i), positive=True) for i in range(n)]
>
> In [5]: Xs = [Normal('X'+str(i), mu, sigma) for i, (mu, sigma) in
> enumerate(zip(mus, sigmas))]
>
> In [6]: E(prod(Xs))
> << Big Scary Thing >>
>
> In [7]: simplify(E(prod(Xs)))
> Out[7]: μ₀⋅μ₁⋅μ₂⋅μ₃⋅μ₄
>
> Please note that you shouldn't have to switch down to numerics for this
> problem. There is a clean analytic form.
>
>
>
> On Thu, Aug 29, 2013 at 2:01 PM, Janwillem van Dijk
> <[email protected]<javascript:>
> > wrote:
>
>> I have problems lambdifying a symbolic function that needs array
>> arguments.
>> The problem I want to solve is to find the statistics of the product of
>> Normal distributions. Attached is an example that works and even yields the
>> correct answers. However, I think that the part where the symbolic versions
>> are lambdified into Python callable functions can't win a beauty contest.
>> For example a part of the class :
>>
>> self.MeanNN = E(NN)
>>
>> self.meanNN = lambdify([mu, s], self.MeanNN)
>>
>> def meanOfNs(self, mu, s):
>>
>> mus = mu + s
>>
>> return self.meanNN(*mus)
>>
>> Than called as:
>>
>> Nn = ProductOfNormals(n)
>>
>> print('Mean: ', Nn.meanOfNs(mu, s))
>>
>> Where mu and s are lists of length n
>>
>>
>> In case the arguments are spelled out it looks nicer but I want the
>> flexibility of variable number of distributions in the product.
>>
>> e.g.:
>>
>> self.MeanNN = E(NN)
>>
>> self.meanNN = lambdify([mu1, s1, mu2, s2], self.MeanNN)
>>
>> Than:
>>
>> NN = ProductNormalNormal()
>>
>> print('Mean: ', NN.meanNN(mu0, s0, mu1, s1))
>>
>> Where all parms are scalar
>>
>>
>> Any tips on how to get a more elegant solution are welcome!!
>>
>> The complete example is attached. I am using SymPy 0.7.3 on Python 2.7.4
>> on Linux.
>>
>> Cheers, Janwillem
>>
>>
>> --
>> 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] <javascript:>.
>> To post to this group, send email to [email protected] <javascript:>
>> .
>> Visit this group at http://groups.google.com/group/sympy.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>
--
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.
For more options, visit https://groups.google.com/groups/opt_out.