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]>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].
> 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.
>

-- 
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.

Reply via email to