On Mon, Jan 12, 2009 at 2:12 PM, Danny <[email protected]> wrote:
>
> Hi,
>
> This isn't 100% fleshed out, but what do you think about something
> that works along these lines:
>
> xs, ys = ([], [])
>
> for i in range(1000):
> xs.append(random.randn())
> ys.append(random.randn())
>
> s = Sum('(x(i) * y(i) - mu)**2', 1000)
>
> For simplicity, we'd assume that any term indexed by i only occurs in
> the i^{th} term of the summation, so differentiating with respect to
> it would only require looking at that little piece of the sum (but I'm
> not tied to this specific syntax).
I don't much like to specify expressions using strings syntax. Why not
to just specify everything as Python expressions?
>
> E.g., s.diff((x, 1)) would yield the derivative with respect to x(1):
> mu**2 + 2*x(1) * y(1)**2 - 2*y(1)*mu
>
> s.subs_arrays({'x' : xs, 'y' : ys}) would compute the sum efficiently,
> plugging in xs[i] and ys[i] for x and y in each summation and grouping
> the terms together as we go so that the end result looked something
> like:
> 1000 * mu**2 - 321.2 * mu + 1204
>
> In a smarter implementation, we could do the computation completely
> outside of sympy by grouping according to coefficients of symbolic
> variables (in this case (mu**2, mu, 1).
>
> I've experimented with several naive and slightly trickier variants of
> this that explicitly represent y_1, ..., y_999, x_1, ..., x_999 as
> symbols in sympy, but the number of subs calls that I have to make
> render it too inefficient for my needs both in terms of time and
> memory. In reality, I'd like to be able to handle sums with i ranging
> from 0 to 10k-20k.
>
> Thanks in advance for your thoughts.
Thanks for playing with it. Looks interesting, I would like sympy to
be able to handle the problem.
I think the way forward is not to rewrite the sum using y_1, ...,
y_999, x_1, ..., x_999, but keep it compact in Sum() and just handle
that.
Ondrej
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sympy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/sympy?hl=en
-~----------~----~----~----~------~----~------~--~---