function [pred_mean, pred_labels, pred_var] = test_multiclass_gp(model, Ks, Kss) % Prediction with multi-class GP models, outputs predictive mean and variance % % function [pred_mean, pred_labels, pred_var] = test_multiclass_gp(model, Ks, Kss) % % INPUT: model -- model structure obtained from function "learn_multiclass_gp" % Ks -- n x m matrix of kernel values between n training and m test samples % Kss -- 1 x m vector of self-similarities of test samples % % OUTPUT: pred_mean -- c x m matrix of predicitive mean values for each of the m test samples and each of the c binary tasks % pred_labels -- 1 x m vector containing predicted multi-class label for each test sample % pred_var -- 1 x m vector containing predicted variance for each test sample % % NOTE: to get the maximum mean value for each test sample out of the c binary tasks, use: max_mean = max(pred_mean,[],2); % Copyright (c) by Alexander Freytag, 2013-11-13. if ( nargin < 2) Kss = []; end pred_mean = zeros( length(model.unique_labels), size(Ks,2) ); % loop over classes and thus over binary one-vs-all tasks for k=1:length(model.unique_labels) pred_mean(k,:) = Ks'*model.alpha{k}; end % obtain predicted labels using max-pooling [~, maxID] = max(pred_mean,[],1); pred_labels = model.unique_labels(maxID); % compute predictive variances if necessary if nargout > 2 v = model.L\Ks; if ( isempty(Kss) ) disp('No Kss given - break!'); return; end pred_var = (Kss - sum(v .* v)' + model.noise)'; end end