Problem with function handle for Basis function in fitrgp

I like to use a custom Basis function for fitrgp.
beta0 = [1.5,2.0];
hfcn = @(X) (beta0(1).*(X).^beta0(2));
This should be a powerMean-function.
If I call:
gprMdl1 = fitrgp(x,y,'BasisFunction',hfcn,'Beta',beta0)
with dummy-data from:
load(fullfile(matlabroot,'examples','stats','gprdata2.mat'))
I get
gprMdl1.Beta = 0.0019
Why is gprMdl1.Beta not 1x2 like beta0? Is it posible to optimize custom parameters in Basis function (like beta0)?

2 Kommentare

"Why is gprMdl1.Beta not 1x2 like beta0?"
That basis function will return as many values as provided in the input X. X is multiplied by 1 value (beta0(1)) and added to one value (beta0(2)). So if X is only 1 value, the output should only be one value. If x is 1x5, the output will be 1x5; if x is 3x4, so is the output.
>gprMdl1.Beta is not 3x1, there is still only one beta. Could you help me check this?
Check this out.....
% Your function
beta0 = [1;2;3];
hfcn = @(X) ([ones(size(X,1),1),X,X.^2]*beta0);
% Test some inputs-outputs
hfcn(1)
ans = 6
hfcn([1;2;3])
ans = 3×1
6 17 34

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Ridwan Alam
Ridwan Alam am 28 Jan. 2020
Bearbeitet: Ridwan Alam am 28 Jan. 2020
load(fullfile(matlabroot,'examples','stats','gprdata2.mat'))
In this case, your x is n x 1;
hfcn returns H, which has size n x 1; i.e. p = 1;
So if you want to provide 'Beta' to fitrgp(), it should be of size p x 1, i.e 1 x 1.
fitrgp() is only using your beta0(1) as Adam mentioned in the comment.

4 Kommentare

So, the number of coefficents/parameter within the Basic function is restricted to the number of dimensions of the input-vector? In other words powerMean is not available as a custom Basic function for a single dimension vector or univariate regression. Is that correct?
Ridwan Alam
Ridwan Alam am 28 Jan. 2020
Bearbeitet: Ridwan Alam am 28 Jan. 2020
Well ... you are still achieving power mean from the hfcn, except the fact that for a 1-d vector, you are taking the mean of only one element per instance, right? So your H is still returning 1.5*x^2. The 'Beta' you provide to fitrgp() has no relation to the way your hfcn is defined, except working as an initial value for finding the optimal beta of H*beta. Hope it makes sense.
Okay, now I get it. Beta can be interpreted as a weight on the Basis function H. I would like fitrgp to find the optimal values for beta0 within hfcn. For the KernelFunction it is posible see Example: Fit GPR Model Using Custom Kernel Function:
kfcn = @(XN,XM,theta) (exp(theta(2))^2)*exp(-(pdist2(XN,XM).^2)/(2*exp(theta(1))^2));
Here fitrgp optimizes the theta-values (see KernelInformation). I suppose it is not posible for Basis function.
Thanks a lot!
Sure. Glad to help.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by