得到由Scipy创建的一个插值函数的公式 [英] Get the formula of a interpolation function created by scipy

查看:31
本文介绍了得到由Scipy创建的一个插值函数的公式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Python中做过一些工作,但我是scipy的新手。我正在尝试使用interpolate库中的方法来设计一个近似一组数据的函数。

我已经查找了一些开始使用的示例,并且可以使以下示例代码在Python(x,y)中工作:

import numpy as np
from scipy.interpolate import interp1d, Rbf
import pylab as P

# show the plot (empty for now)
P.clf()
P.show()

# generate random input data
original_data = np.linspace(0, 1, 10)

# random noise to be added to the data
noise = (np.random.random(10)*2 - 1) * 1e-1

# calculate f(x)=sin(2*PI*x)+noise
f_original_data = np.sin(2 * np.pi * original_data) + noise

# create interpolator
rbf_interp = Rbf(original_data, f_original_data, function='gaussian')

# Create new sample data (for input), calculate f(x) 
#using different interpolation methods
new_sample_data = np.linspace(0, 1, 50)
rbf_new_sample_data    = rbf_interp(new_sample_data)

# draw all results to compare
P.plot(original_data, f_original_data, 'o', ms=6, label='f_original_data')
P.plot(new_sample_data, rbf_new_sample_data, label='Rbf interp')
P.legend()

曲线图显示如下:

现在,有没有办法得到表示Rbf(即创建为rbf_interp的方法)创建的插值函数的多项式表达式?

或者,如果Rbf无法做到这一点,也欢迎使用不同的插值法、其他库甚至不同的工具提供任何建议。

推荐答案

rbf使用您要求的任何函数,它当然是一个全局模型,所以有一个函数结果,但当然您可能不会喜欢它,因为它是许多高斯型函数的总和。您有:

 rbf.nodes   # the factors for each of the RBF (probably gaussians)
 rbf.xi      # the centers.
 rbf.epsilon # the width of the gaussian, but remember that the Norm plays a role too
有了这些东西,您就可以计算距离(使用rbf.xi,然后将rbf.nodesrbf.epsilon中的因子插入到高斯(或您要求它使用的任何函数)中)。(您可以查看__call___call_norm的python代码)

所以您会得到类似sum(rbf.nodes[i] * gaussian(rbf.epsilon, sqrt((rbf.xi - center)**2)) for i, center in enumerate(rbf.nodes))的代码/公式,RBFS函数是在文档中编写的,但您也可以查看python代码。

这篇关于得到由Scipy创建的一个插值函数的公式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆