14 views (last 30 days)

Show older comments

If I trained a GP using training data D = {X, y} with fitrgp and I obtained my gprMdl:

gprMdl = fitrgp(data.X, data.Y, 'KernelFunction', 'squaredexponential', ...

'BasisFunction', 'none', 'verbose', 1, 'FitMethod', 'exact')

[ystar, ysd, yint] = predict(gprMdl, Xstar)

How can I obtain the matrix K(Xstar, Xstar)? I can not find the subfunction of the RegressionGP that calculates the matrices K.

Thanks

Gautam Pendse
on 9 Nov 2015

Hi Umberto,

There is an undocumented way of calculating what you want. Here is an example:

rng(0,'twister');

N = 100;

x = linspace(-10,10,N)';

y = 1 + x*5e-2 + sin(x)./x + 0.2*randn(N,1);

gpr = fitrgp(x,y,'FitMethod','Exact','PredictMethod','Exact');

kfcn = gpr.Impl.Kernel.makeKernelAsFunctionOfXNXM(gpr.Impl.ThetaHat)

K = kfcn(x(1:5,:),x(1:7,:))

K(i,j) kernel function evaluated for x(i,:) and x(j,:). For example,

K(3,6)

kfcn(x(3,:),x(6,:))

I would be interested in knowing why you want to compute K.

Hope that helps,

Gautam

Sterling Baird
on 25 Jul 2021

Basim Khalid
on 1 Nov 2020

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

Start Hunting!