我试图通过定义 b 样条的顺序、基函数的数量、结和评估范围来生成基样条函数。请向我推荐一个可以帮助我的 Python 中合适的函数。
我当前的实现是使用 johntfoster/bspline 方法。它不允许我定义基函数的数量,并且结果与 MATLAB 的结果不相似。 https://github.com/johntfoster/bspline
scipy.interpolate.BSpline.basis_element 函数不允许我定义样条线的顺序、基函数的数量、节点
Matlab 实现:
nbreaks = 20;
nbasis = nbreaks + norder - 2;
breaks = linspace(0,taufmax,nbreaks)';
%Create a smooth function that passes through the break point / knots
wtaubasis = create_bspline_basis([0,max(breaks)], nbasis, norder, breaks);
% Create a matrix of basis functions at each break points for the entire Tau
basisValueMat_f = full(eval_basis(wtaubasis, tauf));
Python实现(johntfoster/bspline方法)
import numpy as np
import bspline
import bspline.splinelab as splinelab
norder = 4
nbreaks = 20
#This defines the number of basis function
nbasis = nbreaks + norder - 2
#For the spline, it has to pass thorough the corresponding break points
breaks = np.linspace(0,tauf_max,nbreaks)
k = splinelab.augknt(breaks, norder)
# create spline basis of order p on knots k
B = bspline.Bspline(k, norder)
A0 = B.collmat(np.squeeze(tau_f), deriv_order=0)
我想要在指定点评估 B 样条基函数。 与 MATLAB 类似的结果将非常令人鼓舞。
最佳答案
有evaluate_all_bspl
,
https://github.com/scipy/scipy/blob/v1.3.0/scipy/interpolate/_bspl.pyx#L163
它计算给定评估点处给定节点的所有非零 B 样条曲线。但它不是一个公共(public)函数,因此如果您最终使用它,就得靠您自己了。
关于python - 有没有办法在 Python 中生成 B 样条函数而不知道系数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56177231/