source: distools/discheck.m @ 155

Last change on this file since 155 was 19, checked in by bduin, 13 years ago

allow soft object labels without feature labels in discheck

File size: 2.0 KB
RevLine 
[10]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
[19]48if isempty(featlist) & c > 0 & islabtype(D,'crisp')
[16]49        error('Features are unlabeled and objects are: no proper dissimilarity matrix')
50end
51
[10]52[nn,nf,fl] = renumlab(lablist,featlist);
53if max(nf) > c
54  if nargout == 0
55    error('Feature labels do not match the class labels.')
56  else
57    out = 0;
58    return
59  end
60end
61
62if any(+D < 0) & ~flag,
63  if nargout == 0
64    error('Dissimilarities should be nonnegative.')
65  else
66    out = 0;
67    return
68  end
69end
70
71dd = diag(+D);
72if any(dd ~= 0) & ~flag,
73  if max(dd) < 1e-5 & min(dd) >= 0
74     D(1:m+1:end) = 0;
75     prwarning(3,'The diagonal has small non-zero values. They are set to zero.');
76  else
77    if nargout == 0
78      error('The diagonal of D should be a zero vector.')
79    else
80      out = 0;
81      return
82    end
83  end
84end
85
86if nargout > 0
87  out = 1;
88end
89
90return;
Note: See TracBrowser for help on using the repository browser.