123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- 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 -- m x 1 vector of self-similarities of test samples
- %
- % OUTPUT: pred_mean -- m x c matrix of predicitive mean values for each of the m test samples and each of the c binary tasks
- % pred_labels -- m x 1 vector containing predicted multi-class label for each test sample
- % pred_var -- m x 1 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( size(Ks,2),length(model.unique_labels) );
- % 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,[],2);
- 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
|