bundles / scipy latest / scipy / interpolate / _ndbspline / _make_lsq_ndbspl
function
scipy.interpolate._ndbspline:_make_lsq_ndbspl
source: build-install/usr/lib/python3.14/site-packages/scipy/interpolate/_ndbspline.py:449
Signature
def _make_lsq_ndbspl(x, y, t, k = 3, *, w = None, solver = <function lsqr at 0x0000>, **solver_args)Summary
Construct a least-squares NdBSpline from scattered data.
Parameters
x: array_like, shape (npts, ndim)Data point coordinates. Each row gives one point in
ndimdimensions.y: array_like, shape (npts, ...)Data values at
x. Any trailing dimensions are treated as batch dimensions and fitted with the same design matrix.t: tuple of array_like, shape (ndim,)Full knot vectors for each dimension. Boundary knots must already be included.
k: int or array_like, shape (ndim,), optionalSpline degree for each dimension. A scalar value is applied to all dimensions. Default is cubic,
k=3.w: array_like, shape (npts,), optionalNon-negative weights for weighted least squares.
solver: callable, optionalSparse least-squares solver. Default is scipy.sparse.linalg.lsqr. The solver is called as
solver(A, b, **solver_args), whereAis the sparse design matrix with shape(npts, ncoeffs)andbis a 1D right-hand side with shape(npts,). It must return the same result format as scipy.sparse.linalg.lsqr and scipy.sparse.linalg.lsmr: the fitted coefficients are read fromresult[0]and the convergence status fromresult[1]. Status values0,1, and2are treated as successful termination, following the conventions of lsqr and lsmr.**solver_argsAdditional keyword arguments passed to
solver.
Returns
spl: NdBSplineTensor-product spline with coefficients fitted by least squares.
Notes
This solves the sparse least-squares problem
min_c || W @ (A @ c - y) ||_2,
where A is the sparse tensor-product B-spline design matrix built by NdBSpline.design_matrix and W is a diagonal matrix of weights.
The default solver is scipy.sparse.linalg.lsqr. The related scipy.sparse.linalg.lsmr solver has the same basic interface and can be useful as a comparison when convergence depends on the conditioning of the least-squares problem or on the selected tolerances. Solver tolerances are not modified by this helper; pass them explicitly through solver_args if the solver defaults are not appropriate.
Other least-squares estimators can be used through a small wrapper, as long as the wrapper accepts a sparse matrix A and a one-dimensional right-hand side b and returns coefficients in result[0] and a status in result[1]. Status values other than 0, 1, or 2 are treated as solver failures.
Aliases
scipy.interpolate._ndbspline._make_lsq_ndbspl