%  constructs gaussian processes w/o training 
%

clear
clc
clf

%k = @(x,y) 1*x'*y;
k= @(x,y) exp(-((x-y)'*(x-y))/(2.*0.1*0.1));

rand(2);

% sample points
x= (0:.001:1);
n = length(x);

% construct covariance matrix
C = zeros(n,n);
for i=1:n
    for j=1:n
        C(i,j)= k(x(i),x(j));
    end
end

% sample from GP at these points
u = randn(n,1);

[A, S, ~]= svd(C);
z = A*sqrt(S)*u;  % z = A S^0.5

figure(2); hold on;
plot(x,z,'.-')
axis([0, 1, -3, 3])

for i=2:5
    u = randn(n,1);
    z = A*sqrt(S)*u;  % z = A S^0.5 u
    plot(x,z,'.-')
end

