@@ -19,7 +19,7 @@ Params:
1919 x = fixed X values of the spline
2020 l = lower bounds for spline(X) values
2121 u = upper bounds for spline(X) values
22- lambda = coefficient for the integral of the square of the second derivative
22+ lambda = coefficient for the normalized integral of the square of the second derivative
2323 configuration = spline configuration (optional)
2424Returns: $(FitSplineResult)
2525+/
@@ -76,7 +76,7 @@ FitSplineResult!T fitSpline(alias d = "a - b", T)(
7676 }
7777 assert (integral >= 0 );
7878 }
79- y[$ - 1 ] = sqrt(integral * lambda / 3 );
79+ y[$ - 1 ] = sqrt(integral * lambda * points.length / ( 3 * x.length) );
8080 };
8181
8282 ret.leastSquaresResult = optimize! (f)(settings, points.length + ! lambda, y[].sliced, l[].sliced, u[].sliced);
@@ -120,20 +120,20 @@ unittest
120120 foreach (i; 0 .. x.length)
121121 result.spline(x[i]).shouldApprox == y[i];
122122
123- result = settings.fitSpline(points, x, l, u, 1 );
123+ result = settings.fitSpline(points, x, l, u, 1e-3 );
124124
125125 // this case sensetive for numeric noise
126126 y = [
127- 0.1971683531479794 ,
128- 5.936895050720581 ,
129- 7.451651002121712 ,
130- 5.122509287945581 ,
131- 11.908292461047825 ,
132- 13.701350302891292 ,
133- 16.97948422229589 ,
134- 7.868130112291985 ,
135- 16.20637990062554 ,
136- 19.58302823176968 ,
127+ 15.898984945597563 ,
128+ 0.44978154774119194 ,
129+ 15.579636654078188 ,
130+ 4.028312405287987 ,
131+ 9.945895290402778 ,
132+ 15.07778815727665 ,
133+ 18.877926155854535 ,
134+ 5.348699237978274 ,
135+ 16.898507797404278 ,
136+ 22.024920998359942 ,
137137 ];
138138
139139 foreach (i; 0 .. x.length)
0 commit comments