Daniel@0: function D = setDistanceDODMKL(X, W, Ifrom, Ito) Daniel@0: % Daniel@0: % D = setDistanceDODMKL(X, W, Ifrom, Ito) Daniel@0: % Daniel@0: % X = d-by-n data matrix Daniel@0: % W = m-by-m-by-n 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: for j = i:m Daniel@0: Vfrom = bsxfun(@times, squeeze(L(i,j)), X(:,Ifrom,i) + X(:,Ifrom,j)); Daniel@0: Daniel@0: if nargin == 4 Daniel@0: Vto = bsxfun(@times, squeeze(L(i,j)), X(:,Ito,i) + X(:,Ito,j)); Daniel@0: else Daniel@0: Vto = bsxfun(@times, squeeze(L(i,j)), X(:,:,i) + X(:,:,j)); Daniel@0: Ito = 1:n; Daniel@0: end Daniel@0: Daniel@0: if i == j Daniel@0: s = 0.5; Daniel@0: else Daniel@0: s = 1; Daniel@0: end Daniel@0: Daniel@0: D = D + s * distToFrom(n, Vto, Vfrom, Ito, Ifrom); Daniel@0: end Daniel@0: end Daniel@0: Daniel@0: end