Borrar filtros
Borrar filtros

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

3 visualizaciones (últimos 30 días)
FsC
FsC el 30 de Mayo de 2024
Comentada: Star Strider el 2 de Jun. de 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');

Respuesta aceptada

Star Strider
Star Strider el 30 de Mayo de 2024
Editada: Star Strider el 30 de Mayo de 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.
.

Más respuestas (0)

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by