function []=gp_test3(x,y,group,obs_group)

% close all;

x = x';
y = y';
n = length(x);
z = linspace(0, 5, 101)';

meanfunc = {@meanSum, {@meanLinear, @meanConst}}; 
likfunc = @likGauss; 

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

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

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

%plot prediction
%%%%%%%%%%%%%%%%%%%%%%%%%
%plot prediction
%plot traj
obs_number = 100;
obs_z = linspace(0, obs_group.time_normalized(obs_number), 101)';
[m s2] = gp(hyp, @infExact, [], covfunc, likfunc, x, y, obs_z);
figure;
set(gca, 'FontSize', 12), grid on, hold all;
xlabel('time (s)'), ylabel('position (mm)');

%plot GP 2sigma
f = [m+2*sqrt(s2); flipdim(m-2*sqrt(s2),1)];
h = fill([obs_z; flipdim(obs_z,1)], f, [7 7 7]/8)
set(h,'FaceAlpha',0.3);

%plot GP mean
plot(obs_z, m, 'k', 'LineWidth', 5);
axis tight;

%plot observed trajectory
plot(obs_group.time_normalized(1:obs_number),...
     obs_group.y(1:obs_number),...
     '--','LineWidth', 2);
% --------------------------------------------------

% hyp.cov = [0; 0]; 
% hyp.mean = [0; 0]; 
% hyp.lik = log(0.1);
% hyp = minimize(hyp, @gp, -10, @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)

%%%%%%%%%%%%%%%%%%%%%%%%%
%plot cluster only
figure;
set(gca, 'FontSize', 12), grid on, hold all;
xlabel('time (s)'), ylabel('position (mm)');
%plot trajectories cluster
for i=1:length(group)
    plot(group(i).time_normalized,group(i).y,...
        '--','LineWidth', 2);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%
%plot cluster with GP
figure;
set(gca, 'FontSize', 12), grid on, hold all;
xlabel('time (s)'), ylabel('position (mm)');

%plot GP 2 sigma
f = [m+2*sqrt(s2); flipdim(m-2*sqrt(s2),1)];
fill([z; flipdim(z,1)], f, [7 7 7]/8)

%plot trajectories cluster
for i=1:length(group)
    plot(group(i).time_normalized,group(i).y,...
        '--','LineWidth', 2);
end

%plot GP mean
plot(z, m, 'k', 'LineWidth', 5); 
%%%%%%%%%%%%%%%%%%%%%%%%%




