source: distools/distools/genballd.m @ 5

Last change on this file since 5 was 1, checked in by dtax, 15 years ago

Dissimilarity toolbox, start!

File size: 2.8 KB
RevLine 
[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
13function d = genballd(n,k,e)
14
15c = length(n); % number of classes
16if nargin < 2, k = 1; end
17if nargin < 3, e = [1:c]/100; end
18m = sum(n);
19
20x = 100*rand(m,k); % to avoid numerical inaccurcies
21r = [];
22for j=1:c
23    r = [r; e(j).*ones(n(j),1)];
24end
25%r = r*100;
26
27d = sqrt(distm(x)) - repmat(r,1,m) - repmat(r',m,1);
28d = d - diag(diag(d));
29attempts = 0;
30while(any(d(:)<0))
31for 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
42end
43
44end         
45
46labs = genlab(n);
47d = dataset(d,labs);
48d = setfeatlab(d,labs);
49d = setprior(d,0);
50desc = ['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.'];
56ref = {['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.']};
64link = {'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'};
66d = setname(d,'Ball Dissimilarities');
67d = setuser(d,desc,'desc');
68d = setuser(d,ref,'ref');
69d = setuser(d,link,'link');
Note: See TracBrowser for help on using the repository browser.