annotate examples/private/dictdist.m @ 5:f44689e95ea4

(none)
author idamnjanovic
date Mon, 22 Mar 2010 10:43:01 +0000
parents 7750624e0c73
children
rev   line source
idamnjanovic@1 1 function [dist,ratio] = dictdist(approxD,D,epsilon)
idamnjanovic@1 2 %DICTDIST Distance between dictionaries.
idamnjanovic@1 3 % [DIST,RATIO] = DICTDIST(APPROXD,D) computes the distance between the
idamnjanovic@1 4 % approximate dictionary APPROXD and the true dictionary D, where APPROXD
idamnjanovic@1 5 % is NxK and D is NxM.
idamnjanovic@1 6 %
idamnjanovic@1 7 % The distance between the dictionary APPROXD and a single atom A of D is
idamnjanovic@1 8 % defined as:
idamnjanovic@1 9 %
idamnjanovic@1 10 % DIST(APPROXD,A) = min { 1-abs(APPROXD(:,i)' * A) }
idamnjanovic@1 11 % i
idamnjanovic@1 12 %
idamnjanovic@1 13 % The distance between the dictionaries APPROXD and D is defined as:
idamnjanovic@1 14 %
idamnjanovic@1 15 % DIST(APPROXD,D) = sum { dist(APPROXD, D(:,k)) } / M
idamnjanovic@1 16 % k
idamnjanovic@1 17 %
idamnjanovic@1 18 % Note that 0 <= DIST(APPROXD,D) <= 1, where 0 implies that all atoms in D
idamnjanovic@1 19 % appear in APPROXD, and 1 implies that the atoms of D are orthogonal to
idamnjanovic@1 20 % APPROXD.
idamnjanovic@1 21 %
idamnjanovic@1 22 % The similarity ratio between APPROXD and D is defined as:
idamnjanovic@1 23 %
idamnjanovic@1 24 % RATIO(APPROXD,D) = #(atoms in D that appear in APPROXD) / M
idamnjanovic@1 25 %
idamnjanovic@1 26 % where two atoms are considered identical when DIST(A1,A2) < EPSILON with
idamnjanovic@1 27 % EPSILON=0.01 by default. Note that 0 <= RATIO(APPROXD,D) <= 1, where 0
idamnjanovic@1 28 % means APPROXD and D have no identical atoms, and 1 means that all atoms
idamnjanovic@1 29 % of D appear in APPROXD.
idamnjanovic@1 30 %
idamnjanovic@1 31 % [DIST,RATIO] = DICTDIST(DICT1,DICT2,EPSILON) specifies a different value
idamnjanovic@1 32 % for EPSILON.
idamnjanovic@1 33
idamnjanovic@1 34 % Ron Rubinstein
idamnjanovic@1 35 % Computer Science Department
idamnjanovic@1 36 % Technion, Haifa 32000 Israel
idamnjanovic@1 37 % ronrubin@cs
idamnjanovic@1 38 %
idamnjanovic@1 39 % October 2007
idamnjanovic@1 40
idamnjanovic@1 41
idamnjanovic@1 42 if (nargin < 3), epsilon = 0.01; end
idamnjanovic@1 43
idamnjanovic@1 44 [n,m] = size(D);
idamnjanovic@1 45
idamnjanovic@1 46 approxD = normcols(approxD*spdiag(sign(approxD(1,:))));
idamnjanovic@1 47 D = normcols(D*spdiag(sign(D(1,:))));
idamnjanovic@1 48
idamnjanovic@1 49 identical_atoms = 0;
idamnjanovic@1 50 dist = 0;
idamnjanovic@1 51
idamnjanovic@1 52 for i = 1:m
idamnjanovic@1 53 atom = D(:,i);
idamnjanovic@1 54 distances = 1-abs(atom'*approxD);
idamnjanovic@1 55 mindist = min(distances);
idamnjanovic@1 56 dist = dist + mindist;
idamnjanovic@1 57 identical_atoms = identical_atoms + (mindist < epsilon);
idamnjanovic@1 58 end
idamnjanovic@1 59
idamnjanovic@1 60 dist = dist / m;
idamnjanovic@1 61 ratio = identical_atoms / m;