comparison Problems/private/dictdist.m @ 10:207a6ae9a76f version1.0

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