function []=gp_test(x,y,group)

close all;

x = x';
y = y';
n = length(x);

meanfunc = {@meanSum, {@meanLinear, @meanConst}}; hyp.mean = [0.5; 1];
covfunc = {@covMaterniso, 3}; ell = 1/4; sf = 1; hyp.cov = log([ell; sf]);
likfunc = @likGauss; sn = 0.1; hyp.lik = log(sn);

z = linspace(-5, 15, 101)';

% --------------------------------------------------
nlml = gp(hyp, @infExact, meanfunc, covfunc, likfunc, x, y)
[m s2] = gp(hyp, @infExact, meanfunc, covfunc, likfunc, x, y, z);

draw(m,s2,z,x,y,group);

% --------------------------------------------------

covfunc = @covSEiso; hyp2.cov = [0; 0]; hyp2.lik = log(0.1);
hyp2 = minimize(hyp2, @gp, -100, @infExact, [], covfunc, likfunc, x, y);

exp(hyp2.lik)
nlml2 = gp(hyp2, @infExact, [], covfunc, likfunc, x, y)
[m s2] = gp(hyp2, @infExact, [], covfunc, likfunc, x, y, z);

draw(m,s2,z,x,y,group);

% --------------------------------------------------

hyp.cov = [0; 0]; hyp.mean = [0; 0]; hyp.lik = log(0.1);
hyp = minimize(hyp, @gp, -100, @infExact, meanfunc, covfunc, likfunc, x, y);
[m s2] = gp(hyp, @infExact, meanfunc, covfunc, likfunc, x, y, z);

draw(m,s2,z,x,y,group);

% --------------------------------------------------

nu = fix(n/2); u = linspace(0,5,nu)';
covfuncF = {@covFITC, {covfunc}, u};
[mF s2F] = gp(hyp, @infFITC, meanfunc, covfuncF, likfunc, x, y, z);

draw(mF,s2F,z,x,y,group);

% --------------------------------------------------
% --------------------------------------------------

function draw(m,s2,z,x,y,group)

figure;
set(gca, 'FontSize', 12), grid on, hold all;
xlabel('input, x'), ylabel('output, y');

f = [m+2*sqrt(s2); flipdim(m-2*sqrt(s2),1)];
fill([z; flipdim(z,1)], f, [7 7 7]/8)
plot(z, m, 'LineWidth', 2); 
plot(x, y, '+', 'MarkerSize', 12);

for i=1:length(group)
    plot(group(i).time_normalized,group(i).y);
end