uqlab;
n=21;
n2=1001;
x=0:2*pi/(n-1):2*pi;
x=x';
y0=sin(2*x).*x;

x2=0:2*pi/(n2-1):2*pi;
x2=x2';
amp=0.5;
figure;
hold on;




poolobj = gcp('nocreate');
if isempty(poolobj)
    poolsize = 8;
    CoreNum = 8;                   
    parpool('local', CoreNum);
else
    poolsize = poolobj.NumWorkers;
    disp('Already initialized');    
end



MetaModel= Regression_Kriging(x,y0);
MetaModel0=MetaModel;

for i=1:8
    MetaModel(i)=MetaModel0;    
end






parfor i=1:8
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %Add noise
    noise=amp*rand(n,1);
    y=y0+noise;   
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %MetalModeling    
    MetaModel(i)= Regression_Kriging(x,y);

    
end
% 
for i=1:8
    y2=uq_evalModel(MetaModel(i),x2);
    
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %Plot results
    drawnow;
    plot(x2,y2)
end

