bundles / scipy latest / scipy / interpolate / _fitpack_repro / make_splprep
function
scipy.interpolate._fitpack_repro:make_splprep
Signature
def make_splprep ( x , * , w = None , u = None , ub = None , ue = None , k = 3 , s = 0 , t = None , nest = None , bc_type = None ) Summary
Create a smoothing parametric B-spline curve with bounded error, minimizing derivative jumps.
Extended Summary
Given a list of N 1D arrays, x, which represent a curve in N-dimensional space parametrized by u, find a smooth approximating spline curve g(u).
Parameters
x: array_like, shape (ndim, m)Sampled data points representing the curve in
ndimdimensions. The typical use is a list of 1D arrays, each of lengthm.w: array_like, shape(m,), optionalStrictly positive 1D array of weights. The weights are used in computing the weighted least-squares spline fit. If the errors in the
xvalues have standard deviation given by the vector d, thenwshould be 1/d. Default isnp.ones(m).u: array_like, optionalAn array of parameter values for the curve in the parametric form. If not given, these values are calculated automatically, according to
v[0] = 0 v[i] = v[i-1] + distance(x[i], x[i-1]) u[i] = v[i] / v[-1]
ub, ue: float, optionalThe end-points of the parameters interval. Default to
u[0]andu[-1].k: int, optionalDegree of the spline. Cubic splines,
k=3, are recommended. Even values ofkshould be avoided especially with a smallsvalue. Default isk=3s: float, optionalA smoothing condition. The amount of smoothness is determined by satisfying the conditions
sum((w * (g(u) - x))**2) <= s,where
g(u)is the smoothed approximation tox. The user can usesto control the trade-off between closeness and smoothness of fit. Largersmeans more smoothing while smaller values ofsindicate less smoothing. Recommended values ofsdepend on the weights,w. If the weights represent the inverse of the standard deviation ofx, then a goodsvalue should be found in the range(m - sqrt(2*m), m + sqrt(2*m)), wheremis the number of data points inxandw.t: array_like, optionalThe spline knots. If None (default), the knots will be constructed automatically. There must be at least
2*k + 2and at mostm + k + 1knots.nest: int, optionalThe target length of the knot vector. Should be between
2*(k + 1)(the minimum number of knots for a degree-kspline), andm + k + 1(the number of knots of the interpolating spline). The actual number of knots returned by this routine may be slightly larger thannest. Default is None (no limit, add up tom + k + 1knots).bc_type: str, optionalBoundary conditions. Default is
"not-a-knot". The following boundary conditions are recognized:"not-a-knot"(default): The first and second segments are the same polynomial. This is equivalent to havingbc_type=None."periodic": The values and the firstk-1derivatives at the ends are equivalent.
Returns
spl: a `BSpline` instanceFor
s=0,spl(u) == x. For non-zero values ofs, spl represents the smoothed approximation tox, generally with fewer knots.u: ndarrayThe values of the parameters
Notes
Given a set of data points in dimensions, , with and , this routine constructs the parametric spline curve with , to minimize the sum of jumps, , of the k-th derivative at the internal knots (), where
Specifically, the routine constructs the spline function which minimizes
provided that
where is the value of the parameter corresponding to the data point , and is the input parameter.
In other words, we balance maximizing the smoothness (measured as the jumps of the derivative, the first criterion), and the deviation of from the data (the second criterion).
Note that the summation in the second criterion is over all data points, and in the first criterion it is over the internal spline knots (i.e. those with ub < t[i] < ue). The spline knots are in general a subset of data, see generate_knots for details.
Array API Standard Support
make_splprep has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable SCIPY_ARRAY_API=1 and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.
==================== ==================== ==================== Library CPU GPU ==================== ==================== ==================== NumPy ✅ n/a CuPy n/a ⛔ PyTorch ✅ ⛔ JAX ⚠️ no JIT ⛔ Dask ⚠️ computes graph n/a ==================== ==================== ====================
See
dev-arrayapifor more information.
See also
- generate_knots
is used under the hood for generating the knots
- make_interp_spline
construct an interpolating spline (
s = 0)- make_lsq_spline
construct the least-squares spline given the knot vector
- make_splrep
the analog of this routine 1D functions
- splprep
a FITPACK analog of this routine
Aliases
-
scipy.interpolate.make_splprep