필터 지우기
필터 지우기

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

조회 수: 3 (최근 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.
.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Gaussian Process Regression에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by