function [Yu] = kCentroid(K, Yl)
% Binary kernel centroid classifier.
%
% Input:
%   K -- kernel matrix of train and test data (train data first)
%   Yl -- known labels
% Output:
%   Yu -- predicted labels
%
% (c) 2016 Zalan Bodo

Pos = find(Yl == 1);
Neg = find(Yl == -1);

b = 0.5*(sum(sum(K(Neg, Neg)))/size(Neg, 1)^2 - sum(sum(K(Pos, Pos)))/size(Pos, 1)^2);

Yu = sum(K(Pos, size(Yl,1)+1:end), 1)/size(Pos, 1) - sum(K(Neg, size(Yl,1)+1:end), 1)/size(Neg, 1) + b;
Yu = Yu';

Yu(find(Yu < 0)) = -1;
Yu(find(Yu >= 0)) = 1;
