How to put fitting constraints on smoothing splines

조회 수: 11 (최근 30일)
Malak
Malak 2023년 3월 29일
댓글: Mathieu NOE 2023년 4월 11일
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
Bruno Luong
Bruno Luong 2023년 3월 29일
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 2023년 3월 29일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Mathieu NOE
Mathieu NOE 2023년 3월 29일
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
Malak
Malak 2023년 4월 11일
Yes. Thank you for your efforts, I really appreciate it.
Mathieu NOE
Mathieu NOE 2023년 4월 11일
as always, my pleasure !

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Bruno Luong
Bruno Luong 2023년 3월 29일
이동: Bruno Luong 2023년 3월 29일
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
Bruno Luong
Bruno Luong 2023년 3월 29일
or quadratic spline
Alex Sha
Alex Sha 2023년 3월 29일
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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by