% GPML code (and book) is available from http://www.gaussianprocess.org/gpml/


load info.txt
y = info(:,2);

load dp_VBM


K    = Phi;
[u,s]=svd(K);
x    = u*sqrtm(s);


N    = size(x,1);
r    = randperm(N);
h    = 16; % K-fold cross-validation
p    = NaN(N,1);

for i=1:h,
    fprintf('-- %g --\n', i);
    ind      = r((floor((i-1)/h*N+1):(floor(i/h*N))));  % Indices for testing
    msk      = true(N,1);
    msk(ind) = false;
    hyp.lik   = 0;
    hyp.mean  = 0;
    hyp.cov   = -log(norm(x));
    hyp       = minimize(hyp, @gp, -50, @infExact, @meanConst, @covLINone, @likGauss, x(msk,:), y(msk));
    [a b c d] = gp(hyp, @infExact, @meanConst, @covLINone, @likGauss, x(msk,:), y(msk),x(~msk,:));
    p(~msk,1) = a; % Results for test data
end

plot(y,p,'.'); axis image xy
corrcoef(y,p)


