Skip to content

Commit 219e193

Browse files
committed
initial commit
0 parents  commit 219e193

29 files changed

+9257
-0
lines changed

Makefile

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Makefile to generate fig23.pdf, fig4.pdf
2+
# Michael Tschannen, 2016
3+
4+
5+
all: fig23.pdf fig4.pdf
6+
7+
fig23.pdf: ceskm-distobslen.dat ceskm-distsigman.dat ceskm-obslenp.dat ceskm-obslensigman.dat ceskmfp-distobslen.dat ceskmfp-distsigman.dat ceskmfp-obslenp.dat ceskmfp-obslensigman.dat cesnnpc-distobslen.dat cesnnpc-distsigman.dat cesnnpc-obslenp.dat cesnnpc-obslensigman.dat
8+
pdflatex -halt-on-error -interaction=batchmode fig23.tex
9+
10+
ceskm-distobslen.dat:
11+
matlab -nojvm -r "synthPhaseDiag; exit(0);"
12+
13+
ceskm-distsigman.dat:
14+
15+
16+
ceskm-obslenp.dat:
17+
18+
19+
ceskm-obslensigman.dat:
20+
21+
22+
ceskmfp-distobslen.dat:
23+
24+
25+
ceskmfp-distsigman.dat:
26+
27+
28+
ceskmfp-obslenp.dat:
29+
30+
31+
ceskmfp-obslensigman.dat:
32+
33+
34+
cesnnpc-distobslen.dat:
35+
36+
37+
cesnnpc-distsigman.dat:
38+
39+
40+
cesnnpc-obslenp.dat:
41+
42+
43+
cesnnpc-obslensigman.dat:
44+
45+
46+
47+
fig4.pdf: cesnnpc.dat ceskm.dat
48+
pdflatex -halt-on-error -interaction=batchmode fig4.tex
49+
50+
cesnnpc.dat:
51+
matlab -nojvm -r "testeeg; exit(0);"
52+
53+
ceskm.dat:
54+
55+
56+
clean:
57+
rm *.dat *.log *.gz *.aux
58+
cleanall:
59+
rm *.dat *.log *.pdf *.gz *.aux
60+

NNPCDist.m

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
% NNPC for precomputed dissimilarity matrix
2+
% D: Dissimilarity matrix
3+
% q: Number of nearest neighbors
4+
% L: Number of clusters
5+
% labels: Labels assigned to the data points
6+
7+
8+
function labels = NNPCDist(D,q,L)
9+
N = size(D,1);
10+
11+
Z = zeros(N,N);
12+
13+
% Compute nearest neighbor graph
14+
for i=1:N
15+
di = D(:,i);
16+
di(i) = inf; % avoid that the ith point is selected
17+
[dio,order] = sort(di, 'ascend');
18+
Z(i, order(1:q) ) = exp(-2*dio(1:q));
19+
end
20+
21+
Z = Z + Z';
22+
23+
% Normalized spectral clustering
24+
Dsum = diag(1./sqrt(sum(Z)+eps));
25+
LN = eye(N) - Dsum*Z*Dsum;
26+
[~,S,V] = svd(LN);
27+
28+
if nargin < 3
29+
singvals = diag(S);
30+
[~,minidx] = min(diff(singvals(1:(end-1))));
31+
L = N - minidx;
32+
end
33+
34+
VL = V(:,N-L+1:N);
35+
VL = normr(VL);
36+
[labels,~] = kmeans(VL,L,'maxiter',1000,'replicates',200,'EmptyAction','singleton');
37+
end
38+
39+

README.md

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
### Instructions for reproducing the numerical results in "Robust nonparametric nearest neighbor random process clustering", 2016, by Michael Tschannen and Helmut Bölcskei
2+
3+
Requirements: matlab, make, pdflatex
4+
5+
6+
#### Comparison of NNPC and TSC (see Section 4 in the paper)
7+
8+
Run "synthDataNNPCvsTSC(0.2)" in Matlab (the argument indicates the noise variance). This will produce a figure showing the clustering error as a function of the observation length M for NNPC and TSC clustering observations stemming from three different generative models. The generative model PSDs will be shown in a separate figure.
9+
10+
11+
### Figures 2 and 3:
12+
13+
In terminal, cd to the folder "supp_material_rpc_ext" and type "make fig23.pdf".
14+
15+
16+
### Table 1:
17+
18+
1. Download the file "amc_to_matrix.m" from "http://mocap.cs.cmu.edu/tools.php" and move it to "robust_rpc".
19+
2. Download the motion capture files listed below from "http://mocap.cs.cmu.edu" and move them to the corresponding folders in "robust_rpc".
20+
3. Run "testMOCAP(1)" and "testMOCAP(2)" in Matlab to reproduce the first and second row of Table 1, respectively.
21+
22+
23+
File list "MOCAP_S16":
24+
25+
16_08.amc
26+
16_11.amc
27+
16_12.amc
28+
16_13.amc
29+
16_14.amc
30+
16_15.amc
31+
16_16.amc
32+
16_17.amc
33+
16_18.amc
34+
16_19.amc
35+
16_20.amc
36+
16_21.amc
37+
16_22.amc
38+
16_23.amc
39+
16_24.amc
40+
16_25.amc
41+
16_26.amc
42+
16_27.amc
43+
16_28.amc
44+
16_29.amc
45+
16_30.amc
46+
16_31.amc
47+
16_32.amc
48+
16_33.amc
49+
16_34.amc
50+
16_35.amc
51+
16_36.amc
52+
16_37.amc
53+
16_38.amc
54+
16_39.amc
55+
16_40.amc
56+
16_41.amc
57+
16_42.amc
58+
16_43.amc
59+
16_44.amc
60+
16_45.amc
61+
16_46.amc
62+
16_47.amc
63+
16_48.amc
64+
16_49.amc
65+
16_50.amc
66+
16_51.amc
67+
16_52.amc
68+
16_53.amc
69+
16_54.amc
70+
16_55.amc
71+
16_56.amc
72+
16_57.amc
73+
16_58.amc
74+
75+
76+
File list "MOCAP_S35":
77+
78+
35_01.amc
79+
35_02.amc
80+
35_03.amc
81+
35_04.amc
82+
35_05.amc
83+
35_06.amc
84+
35_07.amc
85+
35_08.amc
86+
35_09.amc
87+
35_10.amc
88+
35_11.amc
89+
35_12.amc
90+
35_13.amc
91+
35_14.amc
92+
35_15.amc
93+
35_16.amc
94+
35_17.amc
95+
35_18.amc
96+
35_19.amc
97+
35_20.amc
98+
35_21.amc
99+
35_22.amc
100+
35_23.amc
101+
35_24.amc
102+
35_25.amc
103+
35_26.amc
104+
35_28.amc
105+
35_29.amc
106+
35_30.amc
107+
35_31.amc
108+
35_32.amc
109+
35_33.amc
110+
35_34.amc
111+
112+
113+
114+
#### Table 2 and Figure 4:
115+
116+
1. Download Set A ("Z.zip") and Set E ("S.zip") from http://ntsa.upf.edu/downloads/andrzejak-rg-et-al-2001-indications-nonlinear-deterministic-and-finite-dimensional and unpack the zip files in the folder "robust_rpc".
117+
2. In terminal, cd to the folder "robust_rpc" and type "make fig4.pdf".
118+
119+

TSC.m

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
% TSC algorithm
2+
% X: Data matrix containing data points as columns
3+
% q: Number of nearest neighbors
4+
% L: Number of clusters
5+
% labels: Labels assigned to the data points
6+
7+
8+
function labels = TSC(X,q,L)
9+
N = size(X,2);
10+
11+
Z = zeros(N,N);
12+
13+
D = abs(X'*X);
14+
Xnorm = normc(X);
15+
Dnorm = abs(Xnorm'*Xnorm);
16+
17+
% Compute nearest neighbor graph
18+
for i=1:N
19+
di = D(:,i);
20+
di(i) = -inf; % avoid that the ith point is selected
21+
[~,order] = sort(di, 'descend');
22+
dion = Dnorm(order,i);
23+
Z(i, order(1:q) ) = exp(-2*acos(dion(1:q)));
24+
end
25+
26+
Z = Z + Z';
27+
28+
% Normalized spectral clustering
29+
Dsum = diag(1./sqrt(sum(Z)+eps));
30+
LN = eye(N) - Dsum*Z*Dsum;
31+
[~,S,V] = svd(LN);
32+
33+
if nargin < 3
34+
singvals = diag(S);
35+
[~,minidx] = min(diff(singvals(1:(end-1))));
36+
L = N - minidx;
37+
end
38+
39+
VL = V(:,N-L+1:N);
40+
VL = normr(VL);
41+
[labels,~] = kmeans(VL,L,'maxiter',1000,'replicates',200,'EmptyAction','singleton');
42+
end
43+
44+

clusconfent2.m

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
% Compute the entropy of the 2x2 clustering confustion matrix corresponding
2+
% to labels 'labels' and the ground truth 'gt' (column or row vectors)
3+
4+
function S = clusconfent2(labels,gt)
5+
% Swap label indices if needed
6+
if sum(labels ~= gt) > 0.5
7+
labels = labels - 1;
8+
labels(labels == 0) = 2;
9+
end
10+
11+
% Compute clustering confusion matrix
12+
M = zeros(2,2);
13+
14+
M(1,1) = sum(labels(gt == 1) == 1);
15+
M(1,2) = sum(labels(gt == 2) == 1);
16+
M(2,1) = sum(labels(gt == 1) == 2);
17+
M(2,2) = sum(labels(gt == 2) == 2);
18+
19+
% Compute entropy
20+
S = 0;
21+
for i = 1:2
22+
for j = 1:2
23+
if M(i,j) ~= 0
24+
S = S + M(i,j)*log(sum(M(i,:))/M(i,j));
25+
end
26+
end
27+
end
28+
S = S/sum(M(:));
29+
end

computece.m

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
% Compute minimum clustering error w.r.t. all label permutations (brute
2+
% force)
3+
% labels: Vector containing label assignments (values in 1:L)
4+
% gt: Vector containing ground truth labels (values in 1:L)
5+
6+
function cemin = computece(labels,gt)
7+
% Transpose if needed
8+
if size(labels,2) < size(labels,1); labels = labels'; end
9+
if size(gt,2) > size(gt,1); gt = gt'; end
10+
11+
L = max(gt);
12+
N = length(gt);
13+
cemin = 1;
14+
% L! label permutations
15+
per = perms(1:L)';
16+
17+
indmatrix = (per(:,1)*ones(1,N) == ones(L,1)*labels);
18+
for i = 1:size(per,2)
19+
% Map labels and compute clustering error
20+
mapmatrix = repmat(per(:,i),1,N);
21+
ce = sum(mapmatrix(indmatrix) ~= gt)/N;
22+
if ce < cemin
23+
cemin = ce;
24+
end
25+
end
26+
end

0 commit comments

Comments
 (0)