function XK = kesler_construction(X, labels) % KESLER_CONSTRUCTION - Given a data set returns the Kesler constructed data set for training a multiclass perceptron with % % Written by: % -- % John L. Weatherwax 2005-08-04 % % email: wax@alum.mit.edu % % Please send comments and especially bug reports to the % above email address. % %----- [N,p] = size(X); uLabels = unique(labels); M = length(uLabels); % This ensures that that the class labels are given 1:M i.e. sequentially. % if they are not this code will create one based labels % oneIndexedLabels = zeros(1,N); for mi=1:M inds = find( labels == uLabels(mi) ); oneIndexedLabels(inds) = mi; end X_Kesler = zeros(N*(M-1),p*M); xk_spot = 1; for xii=1:N, x = X(xii,:); % get this sample xl = oneIndexedLabels(xii); % get this samples label for jj=1:M, if( jj==xl ) continue; end xk_sample = zeros(1,p*M); % one Kesler sample xk_sample(1, (p*(xl-1)+1) : (p*xl) ) = +x; xk_sample(1, (p*(jj-1)+1) : (p*jj)) = -x; X_Kesler(xk_spot,:) = xk_sample; xk_spot = xk_spot + 1; end end XK = X_Kesler;