annotate util/ksvd utils/dictdist.m @ 104:e2ce05e21a55

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