function [K2] = kbag(K, k, t)
% Bagged cluster kernel. 
%
% Input:
%   K -- kernel matrix
%   k -- number of clusters
%   t -- number of runs
% Output: 
%   K2 -- kernel matrix
%
% (c) 2008-2016 Zalan Bodo

N = size(K, 1);
epsilon = 10^-3; % Convergence threshold

K2 = zeros(N,N);
for i=1:t
    U = kkMeans2(K, k, epsilon);
    K2 = K2 + U'*U;
end
K2 = K2/t;
