How to put fitting constraints on smoothing splines

16 views (last 30 days)
Having a curve as the one shown in the image, and knowing for sure that the peak of this curve is the blue point, we would like to reconstruct it such that it has its peak at the blue point, so
I did some fitting for it using smoothing splines through the curve fiiting toolbox, and with significantly increasing the weight of the two end points and the peak point in blue I got the following
But this has two issues:
  1. The peak point of the spline is not exactly at the peak point that we want, it tries to approach it as much as possible but never be exactly at it.
  2. Increasing the weight of this point made the fiited curve leave the original track of the curve. trying to solve this, again, we visualy choose some knot point and increased the weight for them and got the following, (each plot shows the results for choosing different knot point).
But again, incresing the weight of some point would make the fitted curve lose its track for other points.
So what is a better way to choose the knot points other than just incresing the weight of some of them such that the fitted curve would pass through as much points as possible from the original curve without affecting its smoothness? and how can we set its maximum point to be exactly at the point that we want. Or would there be a better technique to use in our case rather than smoothing splines?
Attached is the data I am using for the plots.
  2 Comments
Bruno Luong
Bruno Luong on 29 Mar 2023
If you know the model has peak at the dark blue point, then clearly your data is incorrect.
Any fitting would not be accurate. This is NOT question of using spline or some other model.
Malak
Malak on 29 Mar 2023
the peak part of the green data is incorrect that is true. and we have the correct data (the blue point) which we are trying to use as a knot point to reconstruct the curve correctly. We are trying to look for a method that would force the spline to have its peak at the point that we want.

Sign in to comment.

Accepted Answer

Mathieu NOE
Mathieu NOE on 29 Mar 2023
hello
this is the poor's man suggestion, (no Curve Fitting toolbox, no spline smoothing)
try it and let me know
load data.mat
[myb,ib] = max(yb);
mxb = xb(ib);
xa = xb;
ya = yb;
xa(ib) = [];
ya(ib) = [];
% spline smoothing or simply with smoothdata ?
xs = xa;
ys = smoothdata(ya,'lowess',9);
% non linear y shift ?
% trying to create a y shift based on x distance from peak point (exp
% distribution)
dx = abs(xs-mxb);
dy = abs(myb-max(ys));
y_shift = dy*exp(-dx.^2/2000);
yss = ys + y_shift;
figure(1);
plot(ya,xa,'og');
hold on
plot(myb,mxb,'*b','Markersize',15);
plot(ys, xs);
plot(yss, xs,'g');
legend('raw data','peak point','smoothed raw data','streched smoothed data')
  6 Comments
Malak
Malak on 11 Apr 2023
Yes. Thank you for your efforts, I really appreciate it.

Sign in to comment.

More Answers (1)

Bruno Luong
Bruno Luong on 29 Mar 2023
Moved: Bruno Luong on 29 Mar 2023
GIGO, using my FEX submission BSFK
load('data.mat')
[yp,imax] = max(yb);
xp = xb(imax);
xb(imax) = [];
yb(imax) = [];
% force fit pass through (xp,yp) with horizontal ta,gential (peak)
pntcon = struct('p',{0 1},'x',{xp xp},'v',{yp 0});
options = struct('pntcon', pntcon);
% https://www.mathworks.com/matlabcentral/fileexchange/25872-free-knot-spline-approximation
pp = BSFK(xb,yb,4,20,[],options);
close all
xi = linspace(min(xb),max(xb),600);
yi = ppval(pp,xi);
plot(xi,yi,'r',xb,yb,'ob',xp,yp,'r+');
grid on
Zoom yo make sure that peak is at the (xp,yp) coordinates
  3 Comments
Alex Sha
Alex Sha on 29 Mar 2023
try the fitting function below:
Sum Squared Error (SSE): 1.1865504761041E23
Root of Mean Square Error (RMSE): 62890128427.9206
Correlation Coef. (R): 0.97834912925758
R-Square: 0.957167018719065
Parameter Best Estimate
--------- -------------
y0 372158039488.346
a 591488381059.073
xc 339.045269108107
w -41.8638567923805
p1 -462109113.796853

Sign in to comment.

Products


Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!