有没有办法在 Python 中生成 B 样条函数,而系数未知?

Is there a way to generate B spline functions in Python without the coefficients known?

我试图通过定义 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 的结果将非常令人鼓舞。

scipy.interplolate has the function make_interp_spline which fits and returns a Bspline 到由两个向量 xy 表示的二维数据集。此函数有参数 kt 用于控制样条和节点的程度。

evaluate_all_bspl, https://github.com/scipy/scipy/blob/v1.3.0/scipy/interpolate/_bspl.pyx#L163 它计算给定评估点的所有 non-zero b-splines 给定结。不过,它不是 public 函数,因此如果您最终使用它,那就只能靠自己了。