[1] | 1 | %GENBALLD Generate ball distance matrix
|
---|
| 2 | %
|
---|
| 3 | % D = GENBALLD(N,K,E)
|
---|
| 4 | %
|
---|
| 5 | % N 1xC vector with number of objects per class
|
---|
| 6 | % K Dimensionality
|
---|
| 7 | % E 1xC with ball sizes, default: class number/100
|
---|
| 8 | %
|
---|
| 9 | % This routine generates C classes of balls in a K-dimensional hypercube
|
---|
| 10 | % with edges of length 1. The radii for class n is given in E(n). Balls do
|
---|
| 11 | % not intersect. The distances between the ball surfaces are returned in D.
|
---|
| 12 |
|
---|
| 13 | function d = genballd(n,k,e)
|
---|
| 14 |
|
---|
| 15 | c = length(n); % number of classes
|
---|
| 16 | if nargin < 2, k = 1; end
|
---|
| 17 | if nargin < 3, e = [1:c]/100; end
|
---|
| 18 | m = sum(n);
|
---|
| 19 |
|
---|
| 20 | x = 100*rand(m,k); % to avoid numerical inaccurcies
|
---|
| 21 | r = [];
|
---|
| 22 | for j=1:c
|
---|
| 23 | r = [r; e(j).*ones(n(j),1)];
|
---|
| 24 | end
|
---|
| 25 | %r = r*100;
|
---|
| 26 |
|
---|
| 27 | d = sqrt(distm(x)) - repmat(r,1,m) - repmat(r',m,1);
|
---|
| 28 | d = d - diag(diag(d));
|
---|
| 29 | attempts = 0;
|
---|
| 30 | while(any(d(:)<0))
|
---|
| 31 | for j=2:m
|
---|
| 32 | while any(d(j,:) < 0)
|
---|
| 33 | attempts = attempts + 1;
|
---|
| 34 | if attempts > 50*m
|
---|
| 35 | error('No solution found, shrink ball sizes or number of balls, or enlarge dimensionality')
|
---|
| 36 | end
|
---|
| 37 | x(j,:) = 100*rand(1,k);
|
---|
| 38 | d(j,:) = sqrt(distm(x(j,:),x)) - repmat(r(j),1,m) - repmat(r',1,1);
|
---|
| 39 | d(:,j) = d(j,:)';
|
---|
| 40 | d(j,j) = 0;
|
---|
| 41 | end
|
---|
| 42 | end
|
---|
| 43 |
|
---|
| 44 | end
|
---|
| 45 |
|
---|
| 46 | labs = genlab(n);
|
---|
| 47 | d = dataset(d,labs);
|
---|
| 48 | d = setfeatlab(d,labs);
|
---|
| 49 | d = setprior(d,0);
|
---|
| 50 | desc = ['This dataset has been generated by the DisTools command GENBALLD(['...
|
---|
| 51 | num2str(classsizes(d)) '], ' int2str(k) ', [' num2str(e) ']) which generates the' ...
|
---|
| 52 | ' given numbers of ' int2str(k) '-D balls with sizes [' num2str(e) '] in a' ...
|
---|
| 53 | int2str(k) '-D hypercube. Balls do not overlap. Dissimilarities are computed as the' ...
|
---|
| 54 | ' shortest distance between two points on the surface of two balls.' ...
|
---|
| 55 | ' The intention is to study strong examples in which non-Euclidean dissimilarities are informative.'];
|
---|
| 56 | ref = {['E. Pekalska, A. Harol, R.P.W. Duin, D. Spillman, and H. Bunke, Non-Euclidean'...
|
---|
| 57 | ' or non-metric measures can be informative, in: D.-Y. Yeung et al., Proc. SSSPR2006'...
|
---|
| 58 | ' Lecture Notes in Comp. Sc., vol. 4109, Springer, Berlin, 2006, 871-880.'], ...
|
---|
| 59 | ['R.P.W. Duin, E. Pekalska, A. Harol, W.J. Lee, and H. Bunke, On Euclidean'...
|
---|
| 60 | ' corrections for non-Euclidean dissimilarities, in: N. da Vitoria Lobo et al.,'...
|
---|
| 61 | ' Proc. SSSPR2008, Lecture Notes in Comp.Sc., vol. 5342, Springer, Berlin, 2008, 551-561.'], ...
|
---|
| 62 | ['J. Laub, V. Roth, J.M. Buhmann, K.R. Mueller, On the information'...
|
---|
| 63 | ' and representation of non-euclidean pairwise data, Pattern Recognition, vol. 39, 2006, 1815-1826.']};
|
---|
| 64 | link = {'The PRTools version of the data:','http://prtools.org/files/CoilYork.zip'; ...
|
---|
| 65 | 'The DisTools package which contains the routine','http://prtools.org/files/DisTools.zip'};
|
---|
| 66 | d = setname(d,'Ball Dissimilarities');
|
---|
| 67 | d = setuser(d,desc,'desc');
|
---|
| 68 | d = setuser(d,ref,'ref');
|
---|
| 69 | d = setuser(d,link,'link');
|
---|