Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added scipy RBF interpolation #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

alexknyshu
Copy link

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

Added scipy RBF interpolation
@@ -168,53 +169,3 @@ def rseq(n, d):
points = np.array([(0.5 + alpha*(i+1)) % 1 for i in range(n)])

return points


def rbf(points):
Copy link
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.

@@ -2,6 +2,7 @@
import multiprocessing as mp
import numpy as np
import scipy.optimize as op
from scipy.interpolate import Rbf as rbf
Copy link
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().

@@ -116,7 +117,7 @@ def cubetobox(x):
str(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")) + ' ...')

# sampling next batch of points
fit = rbf(points)
fit = rbf(*np.transpose(points), function='cubic')
Copy link
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
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
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