Skip to content

Added scipy RBF interpolation#21

Open
alexknyshu wants to merge 1 commit into
paulknysh:masterfrom
alexknyshu:master
Open

Added scipy RBF interpolation#21
alexknyshu wants to merge 1 commit into
paulknysh:masterfrom
alexknyshu:master

Conversation

@alexknyshu

Copy link
Copy Markdown

The rbf() function is now called from standard scipy library.

Added scipy RBF interpolation
Comment thread blackbox.py
return points


def rbf(points):

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Old rbf() function is completely removed.

Comment thread blackbox.py
import multiprocessing as mp
import numpy as np
import scipy.optimize as op
from scipy.interpolate import Rbf as rbf

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import Rbf() function from scipy as rbf().

Comment thread blackbox.py

# sampling next batch of points
fit = rbf(points)
fit = rbf(*np.transpose(points), function='cubic')

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New rbf() function requires another input format. The input list is transposed and then unpacked with *.

Old: [ [ x1, x2, ... , xd, val ] , [ ... ] , ... ]
New: [ x1, ... ] , [ x2, ... ] , ... , [ xd, ... ] , [ val, ... ]

Original function included cubic basis function, so now it's called manually in arguments.

@paulknysh

Copy link
Copy Markdown
Owner

Thanks! I'm actually getting different answers with new and old RBF. Any idea why?

points = np.array([[0., 0., 1.], [0., 1., 1.], [1., 0., 1.], [1., 1., 1.], [0.5, 0.5, 0.]])

test_point = [0.3, 0.3]

old_fit = rbf_old(points)
print(old_fit(test_point))

new_fit = rbf(*np.transpose(points), function='cubic')
print(new_fit(*test_point))

@alexknyshu

Copy link
Copy Markdown
Author

It looks like you have an additional polynomial bt x + a in the interpolation function

https://arxiv.org/pdf/1605.00998.pdf (equation 4)

while scipy uses only the first "sum-lambda-phi" term by default:

https://github.com/scipy/scipy/blob/adc4f4f7bab120ccfab9383aba272954a0a12fb0/scipy/interpolate/rbf.py#L290

self._function(r) here is your basis function phi(r) and self.nodes are weights lambda, so they simply calculate their dot product and that is it. As far as I see there are no options to extend your interpolation function with any kind of polynomial in scipy.

I'm pretty sure it's true, cause I coded my own rbf without extra terms and get exactly the same results as I get in the standard library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants