Daniel@0: function D = setDistanceDiagMKL(X, W, Ifrom, Ito) Daniel@0: % Daniel@0: % D = setDistanceDiagMKL(X, W, Ifrom, Ito) Daniel@0: % Daniel@0: % X = d-by-n data matrix Daniel@0: % W = d-by-1 PSD matrix Daniel@0: % Ifrom = k-by-1 vector of source points Daniel@0: % Ito = j-by-1 vector of destination points Daniel@0: % Daniel@0: % D = n-by-n matrix of squared euclidean distances from Ifrom to Ito Daniel@0: % D is sparse, and only the rows corresponding to Ifrom and Daniel@0: % columns corresponding to Ito are populated. Daniel@0: Daniel@0: [d,n,m] = size(X); Daniel@0: L = W.^0.5; Daniel@0: Daniel@0: D = 0; Daniel@0: for i = 1:m Daniel@0: Vfrom = bsxfun(@times, L(:,i), X(:,Ifrom,i)); Daniel@0: Daniel@0: if nargin == 4 Daniel@0: Vto = bsxfun(@times, L(:,i), X(:,Ito,i)); Daniel@0: else Daniel@0: Vto = bsxfun(@times, L(:,i), X(:,:,i)); Daniel@0: Ito = 1:n; Daniel@0: end Daniel@0: Daniel@0: D = D + distToFrom(n, Vto, Vfrom, Ito, Ifrom); Daniel@0: end Daniel@0: end