gpt4 book ai didi

python - 3D 中的径向基函数(面向奇点矩阵)

转载 作者:太空宇宙 更新时间:2023-11-04 06:32:06 24 4
gpt4 key购买 nike

我正在为 2D RBF 插值编写代码但面临奇点问题:

`raise LinAlgError('Matrix is singular.')

LinAlgError: Matrix is singular.`

我有一个二维码分解的想法来解决这个问题,但我不知道应该在代码的哪个位置编写二维码分解的代码?我也删除了重复的点!

import numpy as np
from scipy import interpolate
import pandas as pd
import xlsxwriter
#Read the Dataset from Excel File
dataset=pd.read_excel(r'C:\Users\Windows 10\.spyder-py3\Messwerte_FIBRE.xlsx')
dataset=dataset.drop([0])
dataset=dataset.drop_duplicates(subset=['T Heizstation','T GWK','P Presse','Bauteilverzug'])
index1=[1]
index2=[4]
index3=[5]
index4=[9]
x1=dataset.iloc[:, index1]
x2=dataset.iloc[:, index2]
x3=dataset.iloc[:, index3]
y=dataset.iloc[:, index4]
#converting string into array
x1np=np.array(x1,dtype=float)
x2np=np.array(x2,dtype=float)
x3np=np.array(x3,dtype=float)
ynp=np.array(y,dtype=float)
newfunc = interpolate.Rbf(x1np,x2np,x3np,ynp,function='linear')
estimation= newfunc(x1np,x2np,x3np)
estimation=np.array(estimation)
# Write the estimation output in Another Excel file
workbook = xlsxwriter.Workbook(r'C:\Users\Windows 10\.spyder-py3\RBF_Reg.xlsx')
worksheet = workbook.add_worksheet('est_output')
row=2
for outputverzug in enumerate(estimation):
worksheet.write(row,0,outputverzug[1])
row+=1
#for next column
row=2
for outputverzug in enumerate(ynp):
worksheet.write_column(row,1,outputverzug[1])
row+=1
worksheet.write(0,0,"Predicted Angle Values")
worksheet.write(1,0,"°")
worksheet.write(0,1,"Original Angle Values")
worksheet.write(1,1,"°")
worksheet.conditional_format('A2:A202', {'type': '3_color_scale',
'min_color': "#FF0000",
'max_color': "#00FF00"})
worksheet.conditional_format('B2:B202', {'type':'3_color_scale',
'min_color': "#00FF00",
'max_color': "#FF0000"})
workbook.close()

最佳答案

对于具有重复(或其他形式的冗余)的经验数据,使用平滑(而不是强制对所有点进行插值)是合适的。

没有平滑,比重复更糟糕的是“不兼容的近重复”(在 X、Y 平面上接近但在 Z 上明显不同)。 “几乎奇异”的点会破坏附近的结果。

Rbf 有一个smooth关键字参数,float:

Values greater than zero increase the smoothness of the approximation. 0 is for interpolation (default), the function will always go through the nodal points in this case.

我设计了一个近奇异点的例子。尝试使用不同的 smooth 参数值。

import numpy as np
from scipy.interpolate import Rbf
import matplotlib.pyplot as plt
np.random.seed(99)

x, y = np.random.rand(2, 100)
x[0] = 0.
for i in range(1,len(x)): # Generate clumpy distribution.
x[i] = x[i-1] + np.exp(-6.*x[i])
y += 2.*np.sin(x)

fig, ax = plt.subplots(figsize=(15,4))
ax.plot(x ,y ,'ko')
xi = np.linspace(x[0], x[-1], 1000)
for smooth in [.01, 1, 100]:
rbfi = Rbf(x, y, smooth=smooth)
yi = rbfi(xi)
ax.plot(xi,yi,'k-')
fig.show()

关于python - 3D 中的径向基函数(面向奇点矩阵),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50435630/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com