[SciPy-User] weighted griddata

Pauli Virtanen pav@iki...
Fri Sep 17 04:19:06 CDT 2010

Thu, 16 Sep 2010 21:41:28 -0700, Adam Ryan wrote:
> > You may need to fiddle with the smoothing parameter `s=...` for
> > SmoothBivariateSpline.
> I was using interpolate.SmoothBivariateSpline previously and had good
> results when it worked, but I struggled with the smoothing parameter
> for so long I had to put it down.  I could not figure out how to
> consistently calculate/estimate/predict a smoothing factor (from the
> data) that was not too low (and never return) or too high (and give
> blocky results).
> Is there a way to calculate an optimal smoothing factor from a data set?

If there is, it's probably explained in P. Dierckx's book
http://books.google.fi/books?id=-RIQ3SR0sZMC about FITPACK.

>> No, I tell a lie, the Clough-Tocher 2D spline could easily be used for
>> weighed data smoothing. The only change needed would be to adjust the
>> gradient estimation routine ...
> Yea, that's what I was thinking, ha ha, I just don't know how. 
> Pointers?

You'd have to change the approach in the _estimate_gradients_2d_global 
function to also minimize some norm over the data points:


The optimization problem solved iteratively at each vertex should be 
changed to also optimize the function value, and a quadratic penalty term 
should be added to the error functional. (Quadratic, since we want the 
optimization problem to remain linear.)

The main problem here is choosing the weights of the error term for each 
vertex in a way that makes sense. I suppose some good recipe for this can 
be found in the literature.

Actually, I think I'll take a look at this during the weekend, it sounds 
interesting (some of us have weird tastes in fun...). I won't promise 
anything, though :)

>> I think the rbf routines might be appropriate.
> I've used the rbf routines to ortho-rectify our barrel-distorted images
> (where the data comes from), but here the positional data is not based
> around a center point.  Or maybe I don't understand the rbf stuff fully.
> How would I use weights with the rbf stuff?

You'd probably need to add the weights to the distance function, and 
somehow balance it against the smooth parameter.

The distance function you pass to Rbf() has the data points always along 
the last axis, so weights can in principle be added.

Anyway, I guess some inverse distance weighting scheme (i.e. the same 
thing as simple kriging) would be more efficient than RBF. The RBF in 
Scipy always looks at all points, whereas IDW's typically look only at N 
nearest neighbours, which is probably more efficient and more stable.

> For clarification, all the points of a line have the same t value, but
> each point has a weight of 0 to 1.  Would LSQBivariateSpline be any
> better than SmoothBivariateSpline?  Again, the smoothing factor drove me
> nuts.

LSQBivariateSpline might be better. I somehow suppose part of the 
problems with FITPACK come from the knot selection, at least Chuck's 
comment points to that direction...

Now, I really wonder: is the spline fitting problem inherently difficult, 
or is there just some simple bug in FITPACK making it work like this?

Pauli Virtanen

More information about the SciPy-User mailing list