annotate Problems/private/dictdist.m @ 43:984c3c175be2

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