Skip to content

Commit 793f1e7

Browse files
author
JoVo
committed
LAP works for unlabeled graph classification
1 parent 405b0c0 commit 793f1e7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+323
-44
lines changed

.DS_Store

-6 KB
Binary file not shown.

MRI/.DS_Store

-6 KB
Binary file not shown.

algorithms/.DS_Store

-6 KB
Binary file not shown.

algorithms/lmnn/.DS_Store

-6 KB
Binary file not shown.

algorithms/lmnn/applypca.m

100755100644
File mode changed.

algorithms/lmnn/mexfunctions/SOD.mexmaci

100755100644
File mode changed.

algorithms/lmnn/mexfunctions/SODW.mexmaci

100755100644
File mode changed.

algorithms/lmnn/mexfunctions/addchv.c

100755100644
File mode changed.

algorithms/lmnn/mexfunctions/addchv.mexmaci

100755100644
File mode changed.

algorithms/lmnn/mexfunctions/addh.mexmaci

100755100644
File mode changed.

algorithms/lmnn/mexfunctions/addv.mexmaci

100755100644
File mode changed.

algorithms/lmnn/mexfunctions/cdist.mexmaci

100755100644
File mode changed.

algorithms/lmnn/mexfunctions/count.mexmaci

100755100644
File mode changed.

algorithms/lmnn/mexfunctions/findimps3Dac.mexmaci

100755100644
File mode changed.

algorithms/lmnn/mexfunctions/findlessh.mexmaci

100755100644
File mode changed.

algorithms/lmnn/mexfunctions/mink.mexmaci

100755100644
File mode changed.

algorithms/lmnn/mexfunctions/mulh.mexmaci

100755100644
File mode changed.

algorithms/lmnn/mexfunctions/sd.mexmaci

100755100644
File mode changed.

algorithms/lmnn/mexfunctions/sumiflessh2.mexmaci

100755100644
File mode changed.

algorithms/lmnn/mexfunctions/sumiflessv2.mexmaci

100755100644
File mode changed.

algorithms/lmnn/pca.m

100755100644
File mode changed.

algorithms/mLMNN/.DS_Store

-6 KB
Binary file not shown.

algorithms/mLMNN/data/.DS_Store

-6 KB
Binary file not shown.

algorithms/mLMNN/helperfunctions/knnclassify.m

100755100644
File mode changed.

algorithms/mLMNN/knnclassify.m

100755100644
File mode changed.

algorithms/mLMNN/lmnn2.m

100755100644
File mode changed.

algorithms/mLMNN/mexfunctions/SOD.mexa64

100755100644
File mode changed.

algorithms/mLMNN/mexfunctions/SOD.mexmaci

100755100644
File mode changed.

algorithms/mLMNN/mexfunctions/SOD.mexmaci64

100755100644
File mode changed.

algorithms/mLMNN/mexfunctions/SODW.mexa64

100755100644
File mode changed.

algorithms/mLMNN/mexfunctions/SODW.mexmaci

100755100644
File mode changed.

algorithms/mLMNN/mexfunctions/SODW.mexmaci64

100755100644
File mode changed.

algorithms/mLMNN/mexfunctions/cdist.mexa64

100755100644
File mode changed.

algorithms/mLMNN/mexfunctions/cdist.mexmaci

100755100644
File mode changed.

algorithms/mLMNN/mexfunctions/cdist.mexmaci64

100755100644
File mode changed.

algorithms/mLMNN/mexfunctions/count.mexa64

100755100644
File mode changed.

algorithms/mLMNN/mexfunctions/count.mexmaci

100755100644
File mode changed.

algorithms/mLMNN/mexfunctions/count.mexmaci64

100755100644
File mode changed.

algorithms/mLMNN/mexfunctions/findimps3Dac.mexa64

100755100644
File mode changed.

algorithms/mLMNN/mexfunctions/findimps3Dac.mexmaci

100755100644
File mode changed.

algorithms/mLMNN/mexfunctions/findimps3Dac.mexmaci64

100755100644
File mode changed.

algorithms/mLMNN/mexfunctions/findlessh.mexa64

100755100644
File mode changed.

algorithms/mLMNN/mexfunctions/findlessh.mexmaci

100755100644
File mode changed.

algorithms/mLMNN/mexfunctions/findlessh.mexmaci64

100755100644
File mode changed.

algorithms/mLMNN/mexfunctions/mink.mexa64

100755100644
File mode changed.

algorithms/mLMNN/mexfunctions/mink.mexmaci

100755100644
File mode changed.

algorithms/mLMNN/mexfunctions/mink.mexmaci64

100755100644
File mode changed.

algorithms/mLMNN/mexfunctions/sd.mexa64

100755100644
File mode changed.

algorithms/mLMNN/mexfunctions/sd.mexmaci

100755100644
File mode changed.

algorithms/mLMNN/mexfunctions/sd.mexmaci64

100755100644
File mode changed.

algorithms/mLMNN/mexfunctions/sumiflessh2.mexa64

100755100644
File mode changed.

algorithms/mLMNN/mexfunctions/sumiflessh2.mexmaci

100755100644
File mode changed.

algorithms/mLMNN/mexfunctions/sumiflessh2.mexmaci64

100755100644
File mode changed.

algorithms/mLMNN/mexfunctions/sumiflessv2.mexa64

100755100644
File mode changed.

algorithms/mLMNN/mexfunctions/sumiflessv2.mexmaci

100755100644
File mode changed.

algorithms/mLMNN/mexfunctions/sumiflessv2.mexmaci64

100755100644
File mode changed.

algorithms/mLMNN/mtrees/.DS_Store

-6 KB
Binary file not shown.

algorithms/mLMNN/mtrees/buildmtreec.mexa64

100755100644
File mode changed.

algorithms/mLMNN/mtrees/buildmtreec.mexmaci

100755100644
File mode changed.

algorithms/mLMNN/mtrees/buildmtreec.mexmaci64

100755100644
File mode changed.

algorithms/mLMNN/mtrees/findNimtree.mexa64

100755100644
File mode changed.

algorithms/mLMNN/mtrees/findNimtree.mexmaci

100755100644
File mode changed.

algorithms/mLMNN/mtrees/findNimtree.mexmaci64

100755100644
File mode changed.

algorithms/mLMNN/mtrees/findknnmtree.mexa64

100755100644
File mode changed.

algorithms/mLMNN/mtrees/findknnmtree.mexmaci

100755100644
File mode changed.

algorithms/mLMNN/mtrees/findknnmtree.mexmaci64

100755100644
File mode changed.

algorithms/sepca/FlipRate010_Set01.mat

100755100644
File mode changed.

algorithms/sepca/demo.m

100755100644
File mode changed.

algorithms/sepca/g_BernExp.m

100755100644
File mode changed.

algorithms/sepca/g_deriv2_BernExp.m

100755100644
File mode changed.

algorithms/sepca/g_deriv_BernExp.m

100755100644
File mode changed.

algorithms/sepca/mixsepcatrain.m

100755100644
File mode changed.

algorithms/spectral/.DS_Store

-6 KB
Binary file not shown.

algorithms/unlabeled/classify_unlabeled_graphs.m

Lines changed: 59 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,55 @@
22

33
constants = get_constants(adjacency_matrices,class_labels); % get constants to ease classification code
44

5-
% get indices for test data
6-
tst_ind = [2:constants.s0, constants.s0+2:constants.s];
7-
85
ytrn = [0 1];
9-
ytst = class_labels(tst_ind);
106

11-
Atrn(:,:,1) = adjacency_matrices(:,:,1);
12-
Atrn(:,:,2) = adjacency_matrices(:,:,constants.s0+1);
13-
Atst = zeros(constants.n,constants.n,constants.s-2); % pre-allocate memory for Atst
7+
P = params;
8+
P.lnE0 = log(P.E0);
9+
P.ln1E0 = log(1-P.E0);
10+
P.lnE1 = log(P.E1);
11+
P.ln1E1 = log(1-P.E1);
1412

13+
yhat = zeros(constants.s/2,1);
14+
correct = zeros(constants.s/2,1);
1515

1616
%% do LAP
1717

1818
if strcmp(alg.names(1),'LAP')
19-
k=0;
20-
for j=tst_ind
21-
k=k+1;
22-
if j < constants.s0,
23-
B=Atrn(:,:,1);
24-
else
25-
B=Atrn(:,:,2);
26-
end
27-
A=adjacency_matrices(:,:,j);
28-
[myp,f]=munkres(-B*A'); %Note that sum(sum(-A(myp,:).*B))==f
29-
Atst(:,:,k)=A(myp,:);
30-
end
3119

32-
Gtrn = get_constants(Atrn,ytrn);
33-
Gtst = get_constants(Atst,ytst);
20+
trn0=randperm(constants.s0);
21+
trn1=randperm(constants.s1)+constants.s0;
22+
tst =randperm(constants.s);
3423

35-
LLAP = graph_classify_ind_edge(Atrn,Gtrn,alg,Atst,Gtst,params);
36-
37-
Lhats.LAP = LLAP.nb;
24+
for j=1:constants.s/2
25+
26+
Atrn(:,:,1)=adjacency_matrices(:,:,trn0(j));
27+
Atrn(:,:,2)=adjacency_matrices(:,:,trn1(j));
28+
Atst=adjacency_matrices(:,:,tst(j));
29+
ytst=class_labels(tst(j));
30+
31+
B=Atst;
32+
[myp0,f]=munkres(-Atrn(:,:,1)*B'); %Note that sum(sum(-A(myp,:).*B))==f
33+
% Atst1=B(myp1,:);
34+
35+
worked0(j)=norm(Atrn(:,:,1)-B(myp0,:)) < norm(Atrn(:,:,1)-B);
36+
37+
B=Atst;
38+
[myp1,f]=munkres(-Atrn(:,:,2)*B'); %Note that sum(sum(-A(myp,:).*B))==f
39+
% Atst2=B(myp2,:);
40+
41+
worked1(1)=norm(Atrn(:,:,2)-B(myp1,:)) < norm(Atrn(:,:,2)-B);
42+
43+
lik0=sum(sum(Atst(myp0,:).*P.lnE0+(1-Atst(myp0,:)).*P.ln1E0));
44+
lik1=sum(sum(Atst(myp1,:).*P.lnE1+(1-Atst(myp1,:)).*P.ln1E1));
45+
46+
[~, bar] = sort([lik0, lik1]);
47+
yhat(j)=bar(2)-1;
48+
correct(j)=(yhat(j)==class_labels(tst(j)));
49+
50+
end
51+
52+
Lhats.LAP = 1-mean(correct);
53+
3854
end
3955

4056
%% do QAP
@@ -46,30 +62,32 @@
4662

4763
inds{alg.QAP_max_iters} = [];
4864

49-
for ii=1:alg.QAP_max_iters
50-
51-
k=0;
52-
for j=tst_ind
53-
k=k+1;
54-
if j < constants.s0,
55-
B=Atrn(:,:,1);
56-
else
57-
B=Atrn(:,:,2);
58-
end
59-
A=adjacency_matrices(:,:,j);
60-
%FW approximate solution of QAP
61-
[f,myp,x,iter]=sfw(A,-B,ii); % Note that sum(sum(-A.*B(myp,myp)))==f
62-
Atst(myp,myp,k)=A;
63-
num_iters(ii,j)=iter;
64-
% myp=1:constants.n;
65-
end
65+
66+
k=0;
67+
for j=tst_ind
68+
k=k+1;
69+
if j < constants.s0,
70+
B=Atrn(:,:,1);
71+
else
72+
B=Atrn(:,:,2);
73+
end
74+
A=adjacency_matrices(:,:,j);
75+
%FW approximate solution of QAP
76+
[f,myp,x,iter,fs,myps]=sfw(A,-B,alg.QAP_max_iters,A)
77+
% [f,myp,x,iter]=sfw(A,-B,ii); % Note that sum(sum(-A.*B(myp,myp)))==f
78+
Atst(myp,myp,k)=A;
79+
num_iters(ii,j)=iter;
80+
% myp=1:constants.n;
6681

6782
Gtrn = get_constants(Atrn,ytrn);
6883
Gtst = get_constants(Atst,ytst);
6984

7085
LQAP = graph_classify_ind_edge(Atrn,Gtrn,alg,Atst,Gtst,params);
7186

7287
Lhats.QAP(ii) = LQAP.nb;
88+
89+
7390
end
7491

92+
7593
if alg.save, save([alg.datadir alg.fname '_results'],'Lhats','inds'); end

assignment/.DS_Store

-6 KB
Binary file not shown.

assignment/assign.m

100755100644
File mode changed.

assignment/dsproj.m

100755100644
File mode changed.

assignment/fun.m

100755100644
File mode changed.

assignment/fungrad.m

100755100644
File mode changed.

assignment/lines.m

100755100644
File mode changed.

assignment/perm2mat.m

100755100644
File mode changed.

assignment/sfw.m

100755100644
File mode changed.

assignment/stack.m

100755100644
File mode changed.

assignment/unstack.m

100755100644
File mode changed.

misc/.DS_Store

-6 KB
Binary file not shown.

misc/choose.m

100755100644
File mode changed.

misc/get_constants.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
n = siz(1); % # vertices
99
constants.s0 = length(constants.y0); % # of class 0 examples
1010
constants.s1 = length(constants.y1); % # of class 1 examples
11-
constants.s = siz(3); % # training samples
11+
if numel(siz)==2, constants.s=1;
12+
else constants.s = siz(3); % # training samples
13+
end
1214

1315
dummy=ones(n);
1416
if nargin==4,

plots/plot_models.m

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
2+
3+
4+
clear; clc
5+
6+
alg.datadir = '~/Research/data/graph_sims/unlabeled/';
7+
alg.figdir = '~/Research/figs/graph_sims/unlabeled/';
8+
alg.fname = 'models';
9+
alg.save = 1;
10+
11+
n = 10; % # of vertices
12+
p = 0.5; % prob of connection for kidney
13+
q0 = 0.25; % prob of connection for egg
14+
q1 = 0.75; % prob of connection for egg
15+
egg = 1:3; % vertices in egg
16+
17+
E0=p*ones(n); % params in class 0
18+
E0(egg,egg)=q0; % egg params in class 0
19+
20+
E1=p*ones(n); % params in class 1
21+
E1(egg,egg)=q1; % egg params in class 1
22+
23+
params1.E0=E0; params1.E1=E1;
24+
25+
26+
n = 10; % # of vertices
27+
28+
E0=rand(n); % params in class 0
29+
E1=rand(n); % params in class 1
30+
31+
32+
params2.E0=E0; params2.E1=E1;
33+
34+
35+
%% plot params
36+
37+
figure(1), clf
38+
fs=6;
39+
w=0.3;
40+
h=0.3;
41+
s=(1-3*w)/15;
42+
43+
44+
emax=max(max([params1.E0(:) params1.E1(:) abs(params1.E0(:)-params1.E1(:))]));
45+
46+
% subplot('Position',[s .1 w h])
47+
subplot(231)
48+
image(60*params1.E0/emax)
49+
colormap('gray')
50+
title('class 0 mean','fontsize',fs)
51+
% xlabel('vertices','fontsize',fs)
52+
% ylabel('vertices','fontsize',fs)
53+
set(gca,'fontsize',fs,'DataAspectRatio',[1 1 1])
54+
55+
% subplot('Position',[2*s+w .1 w h])
56+
subplot(232)
57+
image(60*params1.E1/emax)
58+
title('class 1 mean','fontsize',fs)
59+
set(gca,'fontsize',fs)
60+
set(gca,'fontsize',fs,'DataAspectRatio',[1 1 1])
61+
62+
% subplot('Position',[4*s+2*w .1 w h])
63+
subplot(233)
64+
image(60*abs(params1.E0-params1.E1)/emax)
65+
colormap('gray')
66+
title('difference','fontsize',fs)
67+
set(gca,'fontsize',fs)
68+
set(gca,'fontsize',fs,'DataAspectRatio',[1 1 1])
69+
70+
Position=get(gca,'Position');
71+
pos(1)=Position(1)+Position(3)+0.01;
72+
pos(2)=Position(2)+.05;
73+
pos(3)=0.01;
74+
pos(4)=Position(4)*.75;
75+
colorbar('Position',pos,'YTick',[0 15 30 45 60],'YTickLabel',[0 25 50 75 100],'fontsize',fs)
76+
77+
% subplot('Position',[s .1 w h])
78+
subplot(234)
79+
image(60*params2.E0/emax)
80+
colormap('gray')
81+
title('class 0 mean','fontsize',fs)
82+
xlabel('vertices','fontsize',fs)
83+
ylabel('vertices','fontsize',fs)
84+
set(gca,'fontsize',fs,'DataAspectRatio',[1 1 1])
85+
86+
% subplot('Position',[2*s+w .1 w h])
87+
subplot(235)
88+
image(60*params2.E1/emax)
89+
title('class 1 mean','fontsize',fs)
90+
set(gca,'fontsize',fs)
91+
set(gca,'fontsize',fs,'DataAspectRatio',[1 1 1])
92+
93+
% subplot('Position',[4*s+2*w .1 w h])
94+
subplot(236)
95+
image(60*abs(params2.E0-params2.E1)/emax)
96+
colormap('gray')
97+
title('difference','fontsize',fs)
98+
set(gca,'fontsize',fs)
99+
set(gca,'fontsize',fs,'DataAspectRatio',[1 1 1])
100+
101+
Position=get(gca,'Position');
102+
pos(1)=Position(1)+Position(3)+0.01;
103+
pos(2)=Position(2)*1.5;
104+
pos(3)=0.01;
105+
pos(4)=Position(4)*.75;
106+
colorbar('Position',pos,'YTick',[0 15 30 45 60],'YTickLabel',[0 25 50 75 100],'fontsize',fs)
107+
108+
if alg.save
109+
wh=[3 2]; %width and height
110+
set(gcf,'PaperSize',wh,'PaperPosition',[0 0 wh],'Color','w');
111+
figname=[alg.figdir alg.fname '_params'];
112+
print('-dpdf',figname)
113+
print('-deps',figname)
114+
saveas(gcf,figname)
115+
end
116+

plots/sim_plot_models..m

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
clear; clc
2+
3+
alg.datadir = '~/Research/data/graph_sims/unlabeled/';
4+
alg.figdir = '~/Research/figs/graph_sims/unlabeled/';
5+
alg.fname = 'models';
6+
alg.save = 1;
7+
8+
n = 10; % # of vertices
9+
p = 0.5; % prob of connection for kidney
10+
q0 = 0.25; % prob of connection for egg
11+
q1 = 0.75; % prob of connection for egg
12+
egg = 1:3; % vertices in egg
13+
14+
E0=p*ones(n); % params in class 0
15+
E0(egg,egg)=q0; % egg params in class 0
16+
17+
E1=p*ones(n); % params in class 1
18+
E1(egg,egg)=q1; % egg params in class 1
19+
20+
params1.E0=E0; params1.E1=E1;
21+
22+
23+
n = 10; % # of vertices
24+
25+
E0=rand(n); % params in class 0
26+
E1=rand(n); % params in class 1
27+
28+
29+
params2.E0=E0; params2.E1=E1;
30+
31+
32+
plot_models(params1,params2,alg)

runs/.DS_Store

-6 KB
Binary file not shown.

runs/demo_unlabeled2.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
q0 = 0.25; % prob of connection for egg
1212
q1 = 0.75; % prob of connection for egg
1313
egg = 1:3; % vertices in egg
14-
S = 102; % # of samples
14+
S = 20000; % # of samples
1515

1616
E0=p*ones(n); % params in class 0
1717
E0(egg,egg)=q0; % egg params in class 0
@@ -37,7 +37,7 @@
3737
alg.names = [{'LAP'}; {'QAP'}];
3838
% alg.names = [{'LAP'}];
3939

40-
alg.QAP_max_iters = 10;
40+
alg.QAP_max_iters = 15;
4141

4242
% provide indices to classifiers
4343
alg.nb_ind = 1:n^2; % use all edges
@@ -92,6 +92,8 @@
9292
Lhats.LAP = Lhat.LAP;
9393
Lhats.QAP = Lhat.QAP;
9494

95+
save([alg.datadir alg.fname],'adjacency_matrices','class_labels','params','alg','Lhat','num_iters')
96+
9597
%% make plots
9698

9799

0 commit comments

Comments
 (0)