@@ -26,28 +26,57 @@ def smoothing_spline_with_tolerance(
2626 tolerance : float ,
2727 config : SplineConfig ,
2828) -> tuple [CubicSmoothingSpline , float , float , int ]:
29- """
30- Find a cubic smoothing spline with a maximum approximation error smaller than
29+ """Find a cubic smoothing spline with a maximum approximation error smaller than
3130 a given tolerance using binary search on the μ parameter.
3231
3332 This implements the algorithm for "Smoothing spline with prescribed tolerance".
3433
35- Args:
36- t_points: Time points [t₀, t₁, t₂, ..., tₙ]
37- q_points: Position points [q₀, q₁, q₂, ..., qₙ]
38- tolerance: Maximum allowed approximation error δ between original and smoothed points
39- config: Configuration object with optional parameters:
40- - weights: Individual point weights [w₀, w₁, ..., wₙ] (None = equal weights)
41- - v0: Initial velocity constraint at t₀
42- - vn: Final velocity constraint at tₙ
43- - max_iterations: Maximum number of iterations for the binary search
44- - debug: Whether to print debug information
45-
46- Returns:
47- spline: The final CubicSmoothingSpline object
48- mu: The found value of μ parameter
49- e_max: The maximum approximation error achieved
50- iterations: Number of iterations performed
34+ Parameters
35+ ----------
36+ t_points : np.ndarray
37+ Time points [t₀, t₁, t₂, ..., tₙ]
38+ q_points : np.ndarray
39+ Position points [q₀, q₁, q₂, ..., qₙ]
40+ tolerance : float
41+ Maximum allowed approximation error δ between original and smoothed points
42+ config : SplineConfig
43+ Configuration object with optional parameters:
44+ - weights: Individual point weights [w₀, w₁, ..., wₙ] (None = equal weights)
45+ - v0: Initial velocity constraint at t₀
46+ - vn: Final velocity constraint at tₙ
47+ - max_iterations: Maximum number of iterations for the binary search
48+ - debug: Whether to print debug information
49+
50+ Returns
51+ -------
52+ spline : CubicSmoothingSpline
53+ The final CubicSmoothingSpline object
54+ mu : float
55+ The found value of μ parameter
56+ e_max : float
57+ The maximum approximation error achieved
58+ iterations : int
59+ Number of iterations performed
60+
61+ Examples
62+ --------
63+ >>> import numpy as np
64+ >>> from interpolatepy.c_s_smoothing import CubicSmoothingSpline
65+ >>> # Create sample data
66+ >>> t = np.linspace(0, 10, 100)
67+ >>> q = np.sin(t) + 0.1 * np.random.randn(100)
68+ >>> config = SplineConfig(max_iterations=20)
69+ >>> # Find spline with tolerance of 0.05
70+ >>> spline, mu, error, iterations = smoothing_spline_with_tolerance(t, q, 0.05, config)
71+ >>> print(f"Found spline with μ={mu:.6f}, error={error:.6f} in {iterations} iterations")
72+
73+ Notes
74+ -----
75+ The algorithm uses binary search to find the optimal μ parameter value that
76+ produces a smoothing spline with maximum error below the specified tolerance.
77+ The parameter μ controls the trade-off between smoothness and accuracy, with
78+ values closer to 0 producing smoother curves and values closer to 1 producing
79+ more accurate but less smooth curves.
5180 """
5281
5382 # Initialize the search range for μ
0 commit comments