source: distools/genrepi.m @ 147

Last change on this file since 147 was 10, checked in by bduin, 14 years ago
File size: 1.3 KB
Line 
1%GENREPI Generate indices for representation, learning and testing sets
2%
3%       [R,L,T] = GENREPI(D,K,M)
4%
5% INPUT
6%   D   NxN dissimilarity dataset
7%   K   Number of objects for the representation set R
8%   M   Number of objects for the learning set L; M >= K
9%
10% OUTPUT
11%   R  Indices for the representation set
12%   L  Indices for the learning set
13%   T  Indices for the test set
14%
15% DESCRIPTION
16% Random selection of M indices for a representation set R and N indices for
17% a learning set L. L contains R (M <= N). Indices of the remaining objects
18% are stored in T.
19%
20% DEFAULT
21% M   = N
22%
23
24% Copyright: Robert Duin, r.duin@ieee.org, and
25% Elzbieta Pekalska, ela.pekalska@googlemail.com
26% Faculty EWI, Delft University of Technology and
27% School of Computer Science, University of Manchester
28%
29
30function [R,L,T] = genrepi(D,k,m)
31if nargin < 3,
32        m = k;
33end
34
35[nr,nc,c] = getsize(D);
36if nr ~= nc,
37        error('Dissimilarity matrix should be square.');       
38end
39
40if m > nr | k > nr
41        error('K and M should not exceed the total number of objects in D.')
42end
43
44if k > m
45        error('K should not be larger than M.');
46end
47               
48R = [];
49L = [];
50T = [];
51C = classsizes(D);
52
53for j = 1:c
54        J  = findnlab(D,j);
55        LL = randperm(C(j));
56        LL = LL(1:m);
57        RR = LL(1:k);
58        R  = [R;J(RR)];
59        L  = [L;J(LL)];
60end
61T = setdiff([1:nr]',L);
62       
Note: See TracBrowser for help on using the repository browser.