Effacer les filtres
Effacer les filtres

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

3 vues (au cours des 30 derniers jours)
FsC
FsC le 30 Mai 2024
Commenté : Star Strider le 2 Juin 2024
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');

Réponse acceptée

Star Strider
Star Strider le 30 Mai 2024
Modifié(e) : Star Strider le 30 Mai 2024
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 commentaires
FsC
FsC le 2 Juin 2024
thank you!
Star Strider
Star Strider le 2 Juin 2024
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by