简体   繁体   English

如何设置B样条曲线结果的上下限以获得合理的插值

[英]How to set upper and lower bound on B-Spline result to get a reasonable interpolation

I have interpolation function: 我有插值功能:

from scipy import interpolate
def f(x):
  x_points = [38508,38510,38512]
  y_points = [0.249267578125,0.181396484375,0.1912841796875]

  tck = interpolate.splrep(x_points, y_points,k=2,xb=38508,xe=38512)
  return interpolate.splev(x, tck)

when i evaluate f(38503) output is 0.75 which is nothing like y_points. 当我评估f(38503)输出为0.75 ,与y_points完全不同。

Any suggestion on how to decrease this error using this or other interpolation methods? 关于如何使用此插值方法或其他插值方法减少此错误的任何建议?

As RishiG pointed out in the comments, what you want to do is extrapolation. 正如RishiG在评论中指出的那样,您要做的是推断。

The object oriented approach has an extra parameter for this: ext . 面向对象的方法为此有一个额外的参数: ext

from scipy import interpolate

def f(x):
    x_points = [38508, 38510, 38512]
    y_points = [0.249267578125, 0.181396484375, 0.1912841796875]

    tck = interpolate.splrep(x_points, y_points,k=2,xb=38508,xe=38512)
    return interpolate.splev(x, tck)

def g(x):
    x_points = [38508, 38510, 38512]
    y_points = [0.249267578125, 0.181396484375, 0.1912841796875]

    spl = interpolate.UnivariateSpline(x_points, y_points, k=2, ext=3)

    return spl(x)

if __name__=='__main__':

    print(f(38503))
    print(g(38503))

Output: 输出:

0.7591400146484374
0.249267578125

Edit: 编辑:

This similar question might also be interesting. 这个类似的问题可能也很有趣。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM