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

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.

Danny







I have a crude implementa

On Jan 7, 11:17 am, "Ondrej Certik" <ond...@certik.cz> wrote:
> On Mon, Jan 5, 2009 at 11:08 AM, Danny <dannytar...@gmail.com> wrote:
>
> > Hi Ondrej,
>
> > Thanks for the functions idea.  Having to do the x substitution is a
> > little annoying, but the suggestion helps enough to get me past that
> > block, so I'm happy.
>
> Do you know how to do it more easily? If so, let's implement it.
>
>
>
> > I can't promise anything quickly, but I should have enough now to make
> > some headway on my original request.
>
> Feel free to ask if you have any questions.
>
> Thanks,
> Ondrej
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to sympy@googlegroups.com
To unsubscribe from this group, send email to sympy+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sympy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to