フィルターのクリア

Weighted cubic spline (csaps) -- varying weighting factor

7 ビュー (過去 30 日間)
2one
2one 2014 年 9 月 2 日
コメント済み: 2one 2014 年 9 月 3 日
%weighted cubic spline
x=0:0.1:10; %input data
y=5*sin(1.5*x);
x2=x;
y2=0.5+(0.5*sin(1.5*x));
pp = csaps(x,y,1,x) %weighted cubic spline
plot(x,y); hold all; plot(x2,y2); hold all; plot(x,pp,'*'); legend('input data','input weighting data','weighted cubic spline') %
I need to modify the above code to use the current y2 value to recursively (for each value of y) update the c-spline weighting factor for each value of y.
i.e. instead of:
pp = csaps(x,y,1,x)
i will have something like:
pp = csaps(x,y,[current_y2_value],x)
so the output spline will have different weights for each value of y.
please can you help

採用された回答

rmc256
rmc256 2014 年 9 月 2 日
編集済み: rmc256 2014 年 9 月 2 日
Have a close look at the csaps documentation. There are two kinds of weighting factor you can see in the equation under "this smoothing spline f minimizes:", the first, w, operates directly on the squared error, the other, (1-p)*lambda operates on the 2nd derivative of f.
If you are just looking to weight the data with error bars (if y2 are your 1-sigma error bars), for example, you should just input:
pp = csaps(x,y,1,x,1./y2.^2);
If instead you really do want y2 to weight the smoothness of different areas (i.e set p not equal to 1), then you need to create a vector with a p value as the first element, and the 2:end elements as the lambda weighting factor for each knot of x, for example:
pp = csaps(x,y,[0.99,y2(2:end)]);
Again, look closely at the documentation, it makes sense when you sit down and read it all the way through.
  1 件のコメント
2one
2one 2014 年 9 月 3 日
thanks! this is very helpful.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSplines についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by