Mercurial > hg > camir-aes2014
annotate toolboxes/distance_learning/mlr/distance/setDistanceDODMKL.m @ 0:e9a9cd732c1e tip
first hg version after svn
author | wolffd |
---|---|
date | Tue, 10 Feb 2015 15:05:51 +0000 |
parents | |
children |
rev | line source |
---|---|
wolffd@0 | 1 function D = setDistanceDODMKL(X, W, Ifrom, Ito) |
wolffd@0 | 2 % |
wolffd@0 | 3 % D = setDistanceDODMKL(X, W, Ifrom, Ito) |
wolffd@0 | 4 % |
wolffd@0 | 5 % X = d-by-n data matrix |
wolffd@0 | 6 % W = m-by-m-by-n PSD matrix |
wolffd@0 | 7 % Ifrom = k-by-1 vector of source points |
wolffd@0 | 8 % Ito = j-by-1 vector of destination points |
wolffd@0 | 9 % |
wolffd@0 | 10 % D = n-by-n matrix of squared euclidean distances from Ifrom to Ito |
wolffd@0 | 11 % D is sparse, and only the rows corresponding to Ifrom and |
wolffd@0 | 12 % columns corresponding to Ito are populated. |
wolffd@0 | 13 |
wolffd@0 | 14 [d,n,m] = size(X); |
wolffd@0 | 15 L = W.^0.5; |
wolffd@0 | 16 |
wolffd@0 | 17 D = 0; |
wolffd@0 | 18 for i = 1:m |
wolffd@0 | 19 for j = i:m |
wolffd@0 | 20 Vfrom = bsxfun(@times, squeeze(L(i,j)), X(:,Ifrom,i) + X(:,Ifrom,j)); |
wolffd@0 | 21 |
wolffd@0 | 22 if nargin == 4 |
wolffd@0 | 23 Vto = bsxfun(@times, squeeze(L(i,j)), X(:,Ito,i) + X(:,Ito,j)); |
wolffd@0 | 24 else |
wolffd@0 | 25 Vto = bsxfun(@times, squeeze(L(i,j)), X(:,:,i) + X(:,:,j)); |
wolffd@0 | 26 Ito = 1:n; |
wolffd@0 | 27 end |
wolffd@0 | 28 |
wolffd@0 | 29 if i == j |
wolffd@0 | 30 s = 0.5; |
wolffd@0 | 31 else |
wolffd@0 | 32 s = 1; |
wolffd@0 | 33 end |
wolffd@0 | 34 |
wolffd@0 | 35 D = D + s * distToFrom(n, Vto, Vfrom, Ito, Ifrom); |
wolffd@0 | 36 end |
wolffd@0 | 37 end |
wolffd@0 | 38 |
wolffd@0 | 39 end |