Vous êtes un professionnel et vous avez besoin d'une formation ?
Programmation Python
Les compléments
Voir le programme détaillé
Module « scipy.interpolate »
Signature de la fonction make_splprep
def make_splprep(x, *, w=None, u=None, ub=None, ue=None, k=3, s=0, t=None, nest=None)
Description
help(scipy.interpolate.make_splprep)
Find a smoothed B-spline representation of a parametric N-D curve.
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 (m, ndim)
Sampled data points representing the curve in ``ndim`` dimensions.
The typical use is a list of 1D arrays, each of length ``m``.
w : array_like, shape(m,), optional
Strictly positive 1D array of weights.
The weights are used in computing the weighted least-squares spline
fit. If the errors in the `x` values have standard deviation given by
the vector d, then `w` should be 1/d. Default is ``np.ones(m)``.
u : array_like, optional
An 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, optional
The end-points of the parameters interval. Default to ``u[0]`` and ``u[-1]``.
k : int, optional
Degree of the spline. Cubic splines, ``k=3``, are recommended.
Even values of `k` should be avoided especially with a small ``s`` value.
Default is ``k=3``
s : float, optional
A 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 to ``x``. The user can
use `s` to control the trade-off between closeness and smoothness
of fit. Larger ``s`` means more smoothing while smaller values of ``s``
indicate less smoothing.
Recommended values of ``s`` depend on the weights, ``w``. If the weights
represent the inverse of the standard deviation of ``x``, then a good
``s`` value should be found in the range ``(m - sqrt(2*m), m + sqrt(2*m))``,
where ``m`` is the number of data points in ``x`` and ``w``.
t : array_like, optional
The spline knots. If None (default), the knots will be constructed
automatically.
There must be at least ``2*k + 2`` and at most ``m + k + 1`` knots.
nest : int, optional
The target length of the knot vector. Should be between ``2*(k + 1)``
(the minimum number of knots for a degree-``k`` spline), and
``m + k + 1`` (the number of knots of the interpolating spline).
The actual number of knots returned by this routine may be slightly
larger than `nest`.
Default is None (no limit, add up to ``m + k + 1`` knots).
Returns
-------
spl : a `BSpline` instance
For `s=0`, ``spl(u) == x``.
For non-zero values of ``s``, `spl` represents the smoothed approximation
to ``x``, generally with fewer knots.
u : ndarray
The values of the parameters
See Also
--------
generate_knots : is used under the hood for generating the knots
make_splrep : the analog of this routine 1D functions
make_interp_spline : construct an interpolating spline (``s = 0``)
make_lsq_spline : construct the least-squares spline given the knot vector
splprep : a FITPACK analog of this routine
Notes
-----
Given a set of :math:`m` data points in :math:`D` dimensions, :math:`\vec{x}_j`,
with :math:`j=1, ..., m` and :math:`\vec{x}_j = (x_{j; 1}, ..., x_{j; D})`,
this routine constructs the parametric spline curve :math:`g_a(u)` with
:math:`a=1, ..., D`, to minimize the sum of jumps, :math:`D_{i; a}`, of the
``k``-th derivative at the internal knots (:math:`u_b < t_i < u_e`), where
.. math::
D_{i; a} = g_a^{(k)}(t_i + 0) - g_a^{(k)}(t_i - 0)
Specifically, the routine constructs the spline function :math:`g(u)` which
minimizes
.. math::
\sum_i \sum_{a=1}^D | D_{i; a} |^2 \to \mathrm{min}
provided that
.. math::
\sum_{j=1}^m \sum_{a=1}^D (w_j \times (g_a(u_j) - x_{j; a}))^2 \leqslant s
where :math:`u_j` is the value of the parameter corresponding to the data point
:math:`(x_{j; 1}, ..., x_{j; D})`, and :math:`s > 0` 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 :math:`g(u_j)`
from the data :math:`x_j` (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.
.. versionadded:: 1.15.0
References
----------
.. [1] P. Dierckx, "Algorithms for smoothing data with periodic and
parametric splines, Computer Graphics and Image Processing",
20 (1982) 171-184.
.. [2] P. Dierckx, "Curve and surface fitting with splines", Monographs on
Numerical Analysis, Oxford University Press, 1993.
Vous êtes un professionnel et vous avez besoin d'une formation ?
Programmation Python
Les fondamentaux
Voir le programme détaillé
Améliorations / Corrections
Vous avez des améliorations (ou des corrections) à proposer pour ce document : je vous remerçie par avance de m'en faire part, cela m'aide à améliorer le site.
Emplacement :
Description des améliorations :