EconForge / Smolyak

Efficient implementations of Smolyak's algorithm for function approxmation in Python and Julia.
Other
30 stars 18 forks source link

ENH: better build B function #2

Open sglyon opened 10 years ago

cc7768 commented 10 years ago

This might be some food for thought. The recursive building of the chebyshev polynomials probably isn't our limiting factor, but the nth chebyshev polynomial of the first kind evaluated at a point x is equal to cos(n*arccos(x)).

Like I said, the recursion might not be a limiting factor but cos function is a little faster (and it might be easier to implement with the map idea from earlier today):

In [24]: %timeit np.cos(6*np.arccos(.75)) 100000 loops, best of 3: 3.97 µs per loop

In [25]: %timeit chebyshev.chebval(.75, [0, 0, 0, 0, 0, 0, 1]) 100000 loops, best of 3: 19.2 µs per loop

In [26]: %timeit math.cos(6*math.acos(.75)) 1000000 loops, best of 3: 278 ns per loop

albop commented 10 years ago

Are you saying it's faster to repeatedly compute chebychev polynomials with the direct formulas instead of using the recursive ones ? That would be very strange.

cc7768 commented 10 years ago

It depends on how we are setting up the evaluation at each point. This is a part that I understand, but probably not as thoroughly as you do since this is my first time putting some code together for this method.

One of the things we are thinking about right now is the fact that only the chebyshev polynomials of degree > 1 need to be evaluated. We are trying to create B by using the same set of indices as we used to evaluate the grid, but we add one more step and create a set of indices (poly_inds) that tell us which degree chebyshev polynomials we are evaluating.

It was just a thought and a couple of ideas are still bouncing around. Going to try to implement one tonight if I finish a satisfactory amount of my current homework.

sglyon commented 10 years ago

One thought I had that isn't totally fleshed out yet, but that I wanted to document is to define a class for the smolyak polynomial. The class would be very basic and would define __getitem__ in python and getindex in julia to return slices of the interpolation matrix that are computed on the fly.

The idea still needs some work, but there is some potential there.

cc7768 commented 10 years ago

Several things: