Mercurial > hg > mauch-mirex-2010
annotate _FullBNT/KPMtools/sqdist.m @ 9:4ea6619cb3f5 tip
removed log files
author | matthiasm |
---|---|
date | Fri, 11 Apr 2014 15:55:11 +0100 |
parents | b5b38998ef3b |
children |
rev | line source |
---|---|
matthiasm@8 | 1 function m = sqdist(p, q, A) |
matthiasm@8 | 2 % SQDIST Squared Euclidean or Mahalanobis distance. |
matthiasm@8 | 3 % SQDIST(p,q) returns m(i,j) = (p(:,i) - q(:,j))'*(p(:,i) - q(:,j)). |
matthiasm@8 | 4 % SQDIST(p,q,A) returns m(i,j) = (p(:,i) - q(:,j))'*A*(p(:,i) - q(:,j)). |
matthiasm@8 | 5 |
matthiasm@8 | 6 % From Tom Minka's lightspeed toolbox |
matthiasm@8 | 7 |
matthiasm@8 | 8 [d, pn] = size(p); |
matthiasm@8 | 9 [d, qn] = size(q); |
matthiasm@8 | 10 |
matthiasm@8 | 11 if nargin == 2 |
matthiasm@8 | 12 |
matthiasm@8 | 13 pmag = sum(p .* p, 1); |
matthiasm@8 | 14 qmag = sum(q .* q, 1); |
matthiasm@8 | 15 m = repmat(qmag, pn, 1) + repmat(pmag', 1, qn) - 2*p'*q; |
matthiasm@8 | 16 %m = ones(pn,1)*qmag + pmag'*ones(1,qn) - 2*p'*q; |
matthiasm@8 | 17 |
matthiasm@8 | 18 else |
matthiasm@8 | 19 |
matthiasm@8 | 20 if isempty(A) | isempty(p) |
matthiasm@8 | 21 error('sqdist: empty matrices'); |
matthiasm@8 | 22 end |
matthiasm@8 | 23 Ap = A*p; |
matthiasm@8 | 24 Aq = A*q; |
matthiasm@8 | 25 pmag = sum(p .* Ap, 1); |
matthiasm@8 | 26 qmag = sum(q .* Aq, 1); |
matthiasm@8 | 27 m = repmat(qmag, pn, 1) + repmat(pmag', 1, qn) - 2*p'*Aq; |
matthiasm@8 | 28 |
matthiasm@8 | 29 end |