
% Template code illustrating use of GP classification toolbox

% x_train and x_test are NxD matrices, where N is the number of training 
% examples and D is the dimensionality of the feature space.
load('intensity_features.mat');
% load('hog_features.mat');

% Usage hints for the Laplace approximation inference function:
%[p, mu, s2, nlZ] = binaryLaplaceGP(loghyper, covfunc, lik, x, y, xstar);
%  loghyper is a (column) vector of log hyper-parameters
%  covfunc  is the name of the covariance function: 'covSEiso' or 'covLINone'.
%  lik      is the name of the likelihood function: 'logistic'
%  x        is a N by D matrix of N training examples of length D
%  y        is a N by 1 vector of binary +1/-1 targets 
%  xstar    is a M by D matrix of M test examples of length D
%  p        is a M by 1 vector of predictive probabilities
%  mu       is a M by 1 vector of predictive latent means
%  s2       is a M by 1 vector of predictive latent variances
%  nlZ      is the returned value of the negative log marginal likelihood

% Call the minimize function to estimate (locally) optimal hyperparameters.
% Ensure that you cast x_train to double as shown (necessary for intensity features). 
init_guess = [10; 3];
[newloghyper logmarglik] = minimize(init_guess, 'binaryLaplaceGP', ...
  -25, 'covSEiso', 'logistic', double(x_train), y_train);
% -25 indicates that minimize should evaluate 'binaryLaplaceGP' 25 times

% Call GPC to classify x_test. Convert both x_train and x_test to double.
[p, ~, ~, ~] = binaryLaplaceGP(newloghyper, 'covSEiso', 'logistic', double(x_train), y_train, double(x_test));

