sinc function approximated on [-10,10]. First
we define the global structures holding
the GP and the various constants used for data generation and inference:
global net gpopt ep nType = 'GAUSS'; % type of the noise sig02 = 3; % variance allBV = 10:10:60; % BV set sizes totExp = 1; % experiment # for EACH BV set size nTest = 201; % test data size nTrain = 25; % training data size
[xTest,yTest] = sincdata(nType,nTest,0,[],1);
indBV = 0;
for maxB = allBV;
indBV = indBV + 1;
for bInd= 1:totExp; % iteration for different datasets
% training data
[xTrain, yTrain] = sincdata(nType,nTrain,sig02,[],0);
ogp(1,1, ... % input/output dimension
'sqexp', ... % kernel type
log([1/5 100 1])); % kernel parameters
ogpinit(@c_reg_gauss,...
0.1, ... % noise variance
@em_gauss); % to adjust the likelihood variance
5. The second parameter is the
amplitude of the Gaussian process (100) and the
last one would be the order, it is not used in the case of the
squared-exponential kernel.net.thresh is a small value which is the
BV addition threshold; this controls the "degree of
singularity" allowed in the OGP structure, essentially the level at
which two Basis Vectors are considered identical. net.thresh = 1e-5; % the admission threshold for new BVs
net.maxBV = maxB; % the maximal size of BV set
ogphypcovpar(1e-2);
gpopt. Its fields have to be initialised
prior the learning stage. A set of default options are put inot
gpopt by using the function defoptions.
ogphypcovpar initialises the hyperpriors to
the Gaussian process hyperparameters -- used to make the algorithm
more stable.
isep says that the iterative extension to
the online algorithm will be used, itn specifies the
number of sweeps through the data, isem is an other
indicator saying that an EM algorithm is used to infer likelihood
parameter, which is the noise variance. Finally the function address
specifies the function that is used for hyper-parameter update
(em_gauss).
gpopt = defoptions; % setting defaults
gpopt.postopt.isep = 1; % USING the TAP/EP algorithm
gpopt.postopt.itn = 2; % number of EP iteration with CHANGING BVs
gpopt.postopt.fixitn= 1; % FIXING the BV set.
maxHyp = 4;
for iHyp = 1:maxHyp;
ogptrain(xTrain,yTrain);
ogpreset;
ogppost(xTrain,yTrain)
end;
ogptrain and
ogppost. The first function is used to train the
Gaussian process, i.e. to obtain optimal set of hyperparameters and
the last one obtains a posterior with a fixed set of hyperparameters.
ogpfwd then plotted together with the
true function and the locations of the Basis Vectors.
[meanT, varT] = ogpfwd(xTest);
stdT = sqrt(varT);
meanBV = ogpfwd(net.BV);
figure; clf; hold on; box on;
plot(xTest,yTest);
plot(xTest,meanT,'k--');
plot(xTest,meanT + stdT,'r-.');
plot(xTest,meanT - stdT,'r-.');
plot(net.BV,meanBV,'k*');
plot(xTrain,yTrain,'r.');
end; end;
ogpfwd(net,inputs) - which returns the mean and variance
of the posterior process at the input locations.
ogpsample(net,inputs) and
gives a random sample from the Gaussian posterior (see image in the Glossary about the posterior samples).
Questions, comments, suggestions: contact Lehel Csató.