# [SciPy-User] scipy.interpolate.rbf: how is "smooth" defined?

denis denis-bz-gg@t-online...
Tue Aug 31 10:20:50 CDT 2010

```On Aug 30, 1:10 pm, Mischa Schirmer <mis...@astro.uni-bonn.de> wrote:
> Hello,
>
> I'm doing a 2D fit using scipy.interpolate.rbf.
> I have no problem with the fit itself, it works fine.
>
> Data points are randomly scattered in a x-y plane,
> and have a z-value each. The data is fairly well
> behaved, in the sense that variations across-x-y
> plane are slow. The data is somewhat noisy, and
> thus I want to smooth it.
>
> rbf has a 'smooth' parameter which is working well,
> but it is exteremly poorly documented. Basically,
> for smooth=0 no smoothing takes place, and for
> smooth>0 some smoothing takes place.

Mischa,
are you seeing smoothing with smooth > 0 ? measured how ?

For varying epsilon aka r0 in exp( - (r / r0)^2 ),

r0 = side * sqrt( 2 / N )

looks to be of the right scale:
on a checkerboard of N points in a side^2 square,
a circle of that radius will enclose its 8 neighbours.
Well, the points are scattered, but.
Can you try epsilon = this r0, *2, *3
keeping smooth=0 ?

Of course any interpolation depends heavily on what you're fitting.

(Opinion:
You really want smaller Gaussian hills / smaller r0
where points are clustered, bigger where sparse.
RBF is not at all adaptive -- all hills are of size r0.
griddata (Delaunay triangulation + Natural Neighbour) is adaptive,
Invdisttree (kd tree + inverse-distance weighting) is adaptive.
)

cheers
-- denis

r0 = side * np.sqrt( 2 / N )
for smooth in ( 0, -1e-6 ):
print "smooth %.2g" % smooth
for c in range( 1, 5+1 ):
rbf = Rbf( x,y,z, function=func, epsilon=c*r0, smooth=smooth )
zi = rbf( xm.flatten(), ym.flatten() ) .reshape((ngrid,ngrid))
```