source: distools/discheck.m @ 13

Last change on this file since 13 was 10, checked in by bduin, 14 years ago
File size: 1.9 KB
Line 
1%DISCHECK Dissimilarity Matrix Check
2%
3%   N = DISCHECK(D)
4%         OR
5%   N = DISCHECK(D,LABLIST,FLAG)
6%
7% INPUT
8%   D       NxN dissimilarity matrix or dataset
9%   LABLIST List of labels
10%   FLAG    0 - check square dissimilarity matrix
11%           1 - check square similarity matrix
12%
13% OUTPUT
14%   N      1/0 if D is/isnot a proper dissimilarity matrix
15%
16% DESCRIPTION
17% Returns error if
18%       - D is not a square dissimilarity matrix with feature labels
19%               equal to object labels or feature labels of D are not in LABLIST.
20%       - FLAG==0 & there are non-zero elements on the diagonal of D
21%       - FLAG==0 & there are negative values in D
22%
23
24% Copyright: R.P.W. Duin, r.duin@ieee.org
25% and Elzbieta Pekalska, ela.pekalska@googlemail.com
26% Faculty EWI, Delft University of Technology and
27% School of Computer Science, University of Manchester
28
29function out = discheck(D,lablist,flag)
30
31if nargin < 3, flag = 0; end
32if nargin < 2 | isempty(lablist)
33  [m,k,c]  = getsize(D);
34  lablist  = getlablist(D);
35  featlist = getfeatlab(D);
36  if m ~= k
37    if nargout == 0
38      error('Square (dis)similarity matrix D is expected.')
39    else
40      out = 0;
41      return
42    end
43  end
44else
45  featlist = getfeat(D);
46  c = size(lablist,1);
47end
48[nn,nf,fl] = renumlab(lablist,featlist);
49if max(nf) > c
50  if nargout == 0
51    error('Feature labels do not match the class labels.')
52  else
53    out = 0;
54    return
55  end
56end
57
58if any(+D < 0) & ~flag,
59  if nargout == 0
60    error('Dissimilarities should be nonnegative.')
61  else
62    out = 0;
63    return
64  end
65end
66
67dd = diag(+D);
68if any(dd ~= 0) & ~flag,
69  if max(dd) < 1e-5 & min(dd) >= 0
70     D(1:m+1:end) = 0;
71     prwarning(3,'The diagonal has small non-zero values. They are set to zero.');
72  else
73    if nargout == 0
74      error('The diagonal of D should be a zero vector.')
75    else
76      out = 0;
77      return
78    end
79  end
80end
81
82if nargout > 0
83  out = 1;
84end
85
86return;
Note: See TracBrowser for help on using the repository browser.