yuki-koyama / mathtoolbox

Mathematical tools (interpolation, dimensionality reduction, optimization, etc.) written in C++11 with Eigen
https://yuki-koyama.github.io/mathtoolbox/
MIT License
257 stars 35 forks source link

question: rbf-interpolation out of range #75

Closed shekh closed 3 years ago

shekh commented 3 years ago

I don't fully understand the math, just want to use it. RbfInterpolator has undesirable effect to me that values computed outside of sample points do not approximate any points, e.g. with linear kernel they grow to infinity, with gaussian kernel they fade to 0. Is this expected outcome or I'm doing something wrong? I'd be happy if value computed 'outside' matched nearest sample or close to that, is it possible to achieve in straightforward way?

yuki-koyama commented 3 years ago

Hi,

with linear kernel they grow to infinity, with gaussian kernel they fade to 0

This is true, and this is known as a limitation of RBF interpolation (and many other interpolation techniques) --- interpolation techniques are simply not good at extrapolation.

I'd be happy if value computed 'outside' matched nearest sample or close to that

In one-dimensional cases, it is easy to achieve this by inserting some if statements before calling RBF interpolation. E.g., if x is larger than x_max (in data) or smaller than x_min (in data), then return f(x_max) or f(x_min).

If the dimensionality is 2 or more, then it is not very trivial. However, there are some mathematical techniques that can be used here (e.g., [*]). This is not yet implemented in this library, unfortunately.

[*]: Section 3.1: Radial basis function with polynomial term https://dl.acm.org/doi/10.1145/2614028.2615425

shekh commented 3 years ago

Thanks for replying, well at least I got a confirmation that it is not simple (need multiple dimensions).

yuki-koyama commented 3 years ago

Note that the latest version provides an option (enabled by default) about using "polynomial term", and it provides better extrapolation behavior.

polynomial