フィルターのクリア

How do I fit a 3rd order polynomial Basis using fitrgp?

4 ビュー (過去 30 日間)
FsC
FsC 2024 年 5 月 30 日
コメント済み: Star Strider 2024 年 6 月 2 日
Hello,
I am trying to fit a 3rd order polynomial basis using fitgrp for my signal (1x1503). From the instructions, it looks like I would pass hfcn but don't quite understand how to implement this for the 3rd order polynomial. How would I do this?
Here is code but at the moment it is only implementing a quadratic:
t_observed = (0:length(dodWavelet(:,1))-1)/10;
y_observed = dodWavelet(:,1);
gprMdl1 = fitrgp(t_observed',y_observed,'Basis',"pureQuadratic");
[ypred1] = predict(gprMdl1,t_observed');

採用された回答

Star Strider
Star Strider 2024 年 5 月 30 日
編集済み: Star Strider 2024 年 5 月 30 日
From the documentation, using a table as input:
  • Each row of Tbl corresponds to one observation, and each column corresponds to one variable.
So the data must be column-oriented.
Taking a clue from the 'pureQuadratic' function, see if this does what you want —
dodWavelet = randn(1,1503).' + sin(2*pi*(0:1502).'/500); % Create Data (Note Transposition To Column Vector)
t_observed = (0:length(dodWavelet(:,1))-1)/10;
y_observed = dodWavelet(:,1);
hfcn = @(X) [ones(size(X)) X X.^2 X.^3];
B0 = rand;
gprMdl1 = fitrgp(t_observed',y_observed,'Basis',hfcn, 'Beta',B0);
format long
Coefficients = gprMdl1.Beta
Coefficients = 4x1
-0.050399516294833 0.004117034993237 -0.000011969492060 -0.000000227385782
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
format short
[ypred1,ysd1, yint1] = predict(gprMdl1,t_observed');
figure
hp1 = plot(t_observed, y_observed, '.', 'DisplayName','Data');
hold on
hp2 = plot(t_observed, ypred1, '-r', 'DisplayName','Regression');
hp3 = plot(t_observed, yint1, '--r', 'DisplayName','95% Confidence Limits');
hold off
grid
legend([hp1 hp2 hp3(1)], 'Location','best')
It seems to work and produce a reasonable result.
EDIT — (30 May 2024 at 22:03)
Added ‘Coefficients’ assignment to display them.
.
  2 件のコメント
FsC
FsC 2024 年 6 月 2 日
thank you!
Star Strider
Star Strider 2024 年 6 月 2 日
As always, my pleasure!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGaussian Process Regression についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by