Skip to content

Commit 0fddd26

Browse files
committed
updated unlabeled code, now LAP and QAP work
1 parent 793f1e7 commit 0fddd26

Some content is hidden

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

79 files changed

+207
-134
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
.DS_*
12
*.m~

algorithms/lmnn/applypca.m

100644100755
File mode changed.

algorithms/lmnn/mexfunctions/SOD.mexmaci

100644100755
File mode changed.

algorithms/lmnn/mexfunctions/SODW.mexmaci

100644100755
File mode changed.

algorithms/lmnn/mexfunctions/addchv.c

100644100755
File mode changed.

algorithms/lmnn/mexfunctions/addchv.mexmaci

100644100755
File mode changed.

algorithms/lmnn/mexfunctions/addh.mexmaci

100644100755
File mode changed.

algorithms/lmnn/mexfunctions/addv.mexmaci

100644100755
File mode changed.

algorithms/lmnn/mexfunctions/cdist.mexmaci

100644100755
File mode changed.

algorithms/lmnn/mexfunctions/count.mexmaci

100644100755
File mode changed.

algorithms/lmnn/mexfunctions/findimps3Dac.mexmaci

100644100755
File mode changed.

algorithms/lmnn/mexfunctions/findlessh.mexmaci

100644100755
File mode changed.

algorithms/lmnn/mexfunctions/mink.mexmaci

100644100755
File mode changed.

algorithms/lmnn/mexfunctions/mulh.mexmaci

100644100755
File mode changed.

algorithms/lmnn/mexfunctions/sd.mexmaci

100644100755
File mode changed.

algorithms/lmnn/mexfunctions/sumiflessh2.mexmaci

100644100755
File mode changed.

algorithms/lmnn/mexfunctions/sumiflessv2.mexmaci

100644100755
File mode changed.

algorithms/lmnn/pca.m

100644100755
File mode changed.

algorithms/mLMNN/helperfunctions/knnclassify.m

100644100755
File mode changed.

algorithms/mLMNN/knnclassify.m

100644100755
File mode changed.

algorithms/mLMNN/lmnn2.m

100644100755
File mode changed.

algorithms/mLMNN/mexfunctions/SOD.mexa64

100644100755
File mode changed.

algorithms/mLMNN/mexfunctions/SOD.mexmaci

100644100755
File mode changed.

algorithms/mLMNN/mexfunctions/SOD.mexmaci64

100644100755
File mode changed.

algorithms/mLMNN/mexfunctions/SODW.mexa64

100644100755
File mode changed.

algorithms/mLMNN/mexfunctions/SODW.mexmaci

100644100755
File mode changed.

algorithms/mLMNN/mexfunctions/SODW.mexmaci64

100644100755
File mode changed.

algorithms/mLMNN/mexfunctions/cdist.mexa64

100644100755
File mode changed.

algorithms/mLMNN/mexfunctions/cdist.mexmaci

100644100755
File mode changed.

algorithms/mLMNN/mexfunctions/cdist.mexmaci64

100644100755
File mode changed.

algorithms/mLMNN/mexfunctions/count.mexa64

100644100755
File mode changed.

algorithms/mLMNN/mexfunctions/count.mexmaci

100644100755
File mode changed.

algorithms/mLMNN/mexfunctions/count.mexmaci64

100644100755
File mode changed.

algorithms/mLMNN/mexfunctions/findimps3Dac.mexa64

100644100755
File mode changed.

algorithms/mLMNN/mexfunctions/findimps3Dac.mexmaci

100644100755
File mode changed.

algorithms/mLMNN/mexfunctions/findimps3Dac.mexmaci64

100644100755
File mode changed.

algorithms/mLMNN/mexfunctions/findlessh.mexa64

100644100755
File mode changed.

algorithms/mLMNN/mexfunctions/findlessh.mexmaci

100644100755
File mode changed.

algorithms/mLMNN/mexfunctions/findlessh.mexmaci64

100644100755
File mode changed.

algorithms/mLMNN/mexfunctions/mink.mexa64

100644100755
File mode changed.

algorithms/mLMNN/mexfunctions/mink.mexmaci

100644100755
File mode changed.

algorithms/mLMNN/mexfunctions/mink.mexmaci64

100644100755
File mode changed.

algorithms/mLMNN/mexfunctions/sd.mexa64

100644100755
File mode changed.

algorithms/mLMNN/mexfunctions/sd.mexmaci

100644100755
File mode changed.

algorithms/mLMNN/mexfunctions/sd.mexmaci64

100644100755
File mode changed.

algorithms/mLMNN/mexfunctions/sumiflessh2.mexa64

100644100755
File mode changed.

algorithms/mLMNN/mexfunctions/sumiflessh2.mexmaci

100644100755
File mode changed.

algorithms/mLMNN/mexfunctions/sumiflessh2.mexmaci64

100644100755
File mode changed.

algorithms/mLMNN/mexfunctions/sumiflessv2.mexa64

100644100755
File mode changed.

algorithms/mLMNN/mexfunctions/sumiflessv2.mexmaci

100644100755
File mode changed.

algorithms/mLMNN/mexfunctions/sumiflessv2.mexmaci64

100644100755
File mode changed.

algorithms/mLMNN/mtrees/buildmtreec.mexa64

100644100755
File mode changed.

algorithms/mLMNN/mtrees/buildmtreec.mexmaci

100644100755
File mode changed.

algorithms/mLMNN/mtrees/buildmtreec.mexmaci64

100644100755
File mode changed.

algorithms/mLMNN/mtrees/findNimtree.mexa64

100644100755
File mode changed.

algorithms/mLMNN/mtrees/findNimtree.mexmaci

100644100755
File mode changed.

algorithms/mLMNN/mtrees/findNimtree.mexmaci64

100644100755
File mode changed.

algorithms/mLMNN/mtrees/findknnmtree.mexa64

100644100755
File mode changed.

algorithms/mLMNN/mtrees/findknnmtree.mexmaci

100644100755
File mode changed.

algorithms/mLMNN/mtrees/findknnmtree.mexmaci64

100644100755
File mode changed.

algorithms/sepca/FlipRate010_Set01.mat

100644100755
File mode changed.

algorithms/sepca/demo.m

100644100755
File mode changed.

algorithms/sepca/g_BernExp.m

100644100755
File mode changed.

algorithms/sepca/g_deriv2_BernExp.m

100644100755
File mode changed.

algorithms/sepca/g_deriv_BernExp.m

100644100755
File mode changed.

algorithms/sepca/mixsepcatrain.m

100644100755
File mode changed.

algorithms/unlabeled/classify_unlabeled_graphs.m

Lines changed: 82 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,105 @@
1-
function [Lhats inds num_iters] = classify_unlabeled_graphs(adjacency_matrices,class_labels,alg,params)
2-
1+
function [LAP QAP] = classify_unlabeled_graphs(adjacency_matrices,class_labels,alg,params)
2+
%%
33
constants = get_constants(adjacency_matrices,class_labels); % get constants to ease classification code
44

5-
ytrn = [0 1];
6-
75
P = params;
86
P.lnE0 = log(P.E0);
97
P.ln1E0 = log(1-P.E0);
108
P.lnE1 = log(P.E1);
119
P.ln1E1 = log(1-P.E1);
1210

13-
yhat = zeros(constants.s/2,1);
14-
correct = zeros(constants.s/2,1);
11+
trn0= randperm(constants.s0);
12+
trn1= randperm(constants.s1)+constants.s0;
13+
tst = randperm(constants.s);
14+
I = eye(constants.n);
15+
16+
if strcmp(alg.names(1),'LAP'),
17+
LAP.do = true;
18+
LAP.yhat = zeros(constants.s/2,1);
19+
LAP.correct = zeros(constants.s/2,1);
20+
LAP.work0 = zeros(constants.s/2,1);
21+
LAP.work1 = zeros(constants.s/2,1);
22+
else LAP.do = false;
23+
end
1524

16-
%% do LAP
25+
if strcmp(alg.names(2),'QAP'),
26+
QAP.do = true;
27+
QAP.yhat = NaN(constants.s/2,alg.QAP_max_iters);
28+
QAP.correct = NaN(constants.s/2,alg.QAP_max_iters);
29+
QAP.work0 = NaN(constants.s/2,alg.QAP_max_iters);
30+
QAP.work1 = NaN(constants.s/2,alg.QAP_max_iters);
31+
QAP.obj0 = NaN(constants.s/2,alg.QAP_max_iters);
32+
QAP.obj1 = NaN(constants.s/2,alg.QAP_max_iters);
33+
else QAP.do = false;
34+
end
1735

18-
if strcmp(alg.names(1),'LAP')
36+
for j=1:constants.s/2
1937

20-
trn0=randperm(constants.s0);
21-
trn1=randperm(constants.s1)+constants.s0;
22-
tst =randperm(constants.s);
38+
Atrn(:,:,1) = adjacency_matrices(:,:,trn0(j));
39+
Atrn(:,:,2) = adjacency_matrices(:,:,trn1(j));
40+
Atst = adjacency_matrices(:,:,tst(j));
2341

24-
for j=1:constants.s/2
42+
% do LAP
43+
if LAP.do
44+
LAP_ind0 = munkres(-Atrn(:,:,1)*Atst'); %Note that sum(sum(-A(LAP,:).*Atst))==f
45+
LAP.work0(j)=norm(Atrn(:,:,1)-Atst(LAP_ind0,:)) < norm(Atrn(:,:,1)-Atst); % check that LAP work
46+
47+
LAP_ind1 = munkres(-Atrn(:,:,2)*Atst'); %Note that sum(sum(-A(LAP,:).*Atst))==f
48+
LAP.work1(j)=norm(Atrn(:,:,2)-Atst(LAP_ind1,:)) < norm(Atrn(:,:,2)-Atst); % check that LAP work
49+
50+
LAP_lik0=sum(sum(Atst(LAP_ind0,:).*P.lnE0+(1-Atst(LAP_ind0,:)).*P.ln1E0));
51+
LAP_lik1=sum(sum(Atst(LAP_ind1,:).*P.lnE1+(1-Atst(LAP_ind1,:)).*P.ln1E1));
2552

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));
53+
[~, bar] = sort([LAP_lik0, LAP_lik1]);
54+
LAP.yhat(j)=bar(2)-1;
55+
LAP.correct(j)=(LAP.yhat(j)==class_labels(tst(j)));
56+
end
57+
58+
% do QAP
59+
if QAP.do
3060

31-
B=Atst;
32-
[myp0,f]=munkres(-Atrn(:,:,1)*B'); %Note that sum(sum(-A(myp,:).*B))==f
33-
% Atst1=B(myp1,:);
61+
[~,~,~,iter0,~,QAP_inds0]=sfw(Atrn(:,:,1),-Atst,alg.QAP_max_iters,I);
62+
for ii=1:iter0
63+
QAP.obj0(j,ii) = norm(Atrn(:,:,1) - Atst(QAP_inds0{ii},QAP_inds0{ii}));
64+
QAP.work0(j,ii)= QAP.obj0(j,ii) < norm(Atrn(:,:,1)-Atst); % check that QAP works
65+
end
3466

35-
worked0(j)=norm(Atrn(:,:,1)-B(myp0,:)) < norm(Atrn(:,:,1)-B);
67+
[~,~,~,iter1,~,QAP_inds1]=sfw(Atrn(:,:,2),-Atst,alg.QAP_max_iters,I);
68+
for ii=1:iter1
69+
QAP.obj1(j,ii) = norm(Atrn(:,:,2) - Atst(QAP_inds1{ii},QAP_inds1{ii}));
70+
QAP.work1(j,ii)= QAP.obj1(j,ii) < norm(Atrn(:,:,1)-Atst); % check that QAP works
71+
end
3672

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));
73+
for ii=1:min(iter0,iter1)
74+
QAP_lik0=sum(sum(Atst(QAP_inds0{ii},QAP_inds0{ii}).*P.lnE0+(1-Atst(QAP_inds0{ii},QAP_inds0{ii})).*P.ln1E0));
75+
QAP_lik1=sum(sum(Atst(QAP_inds1{ii},QAP_inds1{ii}).*P.lnE1+(1-Atst(QAP_inds1{ii},QAP_inds1{ii})).*P.ln1E1));
76+
77+
[~, bar] = sort([QAP_lik0, QAP_lik1]);
78+
QAP.yhat(j,ii)=bar(2)-1;
79+
QAP.correct(j,ii)=(QAP.yhat(j)==class_labels(tst(j)));
80+
end
4581

46-
[~, bar] = sort([lik0, lik1]);
47-
yhat(j)=bar(2)-1;
48-
correct(j)=(yhat(j)==class_labels(tst(j)));
49-
5082
end
51-
52-
Lhats.LAP = 1-mean(correct);
53-
5483
end
5584

56-
%% do QAP
57-
58-
Lhats.QAP = zeros(alg.QAP_max_iters,1);
59-
60-
Atst=zeros(constants.n,constants.n,constants.s-2);
61-
num_iters=zeros(1,alg.QAP_max_iters);
62-
63-
inds{alg.QAP_max_iters} = [];
64-
85+
if LAP.do
86+
LAP.Lhat = 1-mean(LAP.correct);
87+
LAP.Lvar = var(LAP.correct);
88+
end
6589

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);
90+
if QAP.do
91+
for ii=1:alg.QAP_max_iters
92+
corrects = QAP.correct(:,ii);
93+
keeper = ~isnan(corrects);
94+
corrects = corrects(keeper);
95+
96+
QAP.Lhat(ii)= 1-mean(corrects);
97+
QAP.Lvar(ii)= var(corrects);
98+
QAP.Lstd(ii)= std(corrects);
99+
QAP.num(ii) = length(corrects);
100+
QAP.obj0_avg(ii) = mean(QAP.obj0(keeper,ii));
101+
QAP.obj1_avg(ii) = mean(QAP.obj1(keeper,ii));
102+
QAP.obj0_var(ii) = var(QAP.obj0(keeper,ii));
103+
QAP.obj1_var(ii) = var(QAP.obj1(keeper,ii));
73104
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;
81-
82-
Gtrn = get_constants(Atrn,ytrn);
83-
Gtst = get_constants(Atst,ytst);
84-
85-
LQAP = graph_classify_ind_edge(Atrn,Gtrn,alg,Atst,Gtst,params);
86-
87-
Lhats.QAP(ii) = LQAP.nb;
88-
89-
90105
end
91-
92-
93-
if alg.save, save([alg.datadir alg.fname '_results'],'Lhats','inds'); end

assignment/assign.m

100644100755
File mode changed.

assignment/dsproj.m

100644100755
File mode changed.

assignment/fun.m

100644100755
File mode changed.

assignment/fungrad.m

100644100755
File mode changed.

assignment/lines.m

100644100755
File mode changed.

assignment/perm2mat.m

100644100755
File mode changed.

assignment/sfw.m

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
% x is the doubly stochastic matrix (interior point) computed by the FW
2929
% method
3030
% iter is the number of iterations of FW performed.
31-
% fs is ????
31+
% fs is the list of fs for each iteration
3232
% myps is the list of myps for each iteration
3333
%
3434
% Louis J. Podrazik circa 1996

assignment/stack.m

100644100755
File mode changed.

assignment/unstack.m

100644100755
File mode changed.

misc/choose.m

100644100755
File mode changed.

0 commit comments

Comments
 (0)