summaryrefslogtreecommitdiffstats
path: root/SD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib
diff options
context:
space:
mode:
Diffstat (limited to 'SD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib')
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib/v5/optim/assignprob/Contents.m26
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib/v5/optim/assignprob/allcosts.m17
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib/v5/optim/assignprob/allperm.m17
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib/v5/optim/assignprob/condass.m54
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib/v5/optim/assignprob/demo.m38
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib/v5/optim/assignprob/hungarian.m464
-rwxr-xr-xSD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib/v5/optim/assignprob/test.m87
7 files changed, 703 insertions, 0 deletions
diff --git a/SD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib/v5/optim/assignprob/Contents.m b/SD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib/v5/optim/assignprob/Contents.m
new file mode 100755
index 0000000..3ddb232
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib/v5/optim/assignprob/Contents.m
@@ -0,0 +1,26 @@
1%Functions related to the assignment problem.
2%Version 1.0, 25-May-1999.
3%
4%Copyright (c) 1995-1999 Niclas Borlin, Dept. of Computing Science,
5% Umea University, SE-901 87 UMEA, Sweden.
6% Niclas.Borlin@cs.umu.se.
7% www.cs.umu.se/~niclas.
8%
9%All standard disclaimers apply.
10%
11%You are free to use this code as you wish. If you use it for a
12%publication or in a commercial package, please include an
13%acknowledgement and/or at least send me an email. (Looks good in my CV :-).
14%
15%Main functions:
16% hungarian - calculate a solution of the square assignment
17% problem. See HELP for a reference.
18% condass - calculate a condition number of the solution to the
19% assignment problem. See HELP for a reference.
20% allcosts - calculate the costs of all possible assignments.
21% allperms - calculate all possible permutations/assignments of a
22% given problem size.
23%
24%Test/demo functions.
25% demo - short demonstration of the main functions.
26% test - test/verification of the main functions.
diff --git a/SD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib/v5/optim/assignprob/allcosts.m b/SD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib/v5/optim/assignprob/allcosts.m
new file mode 100755
index 0000000..ffdb8b9
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib/v5/optim/assignprob/allcosts.m
@@ -0,0 +1,17 @@
1function [c,p]=allcosts(C)
2%ALLCOSTS Calculate all costs for an assignment problem.
3%
4%[c,p]=allcosts(C)
5%c returns the costs, p the corresponding permutations.
6
7% v1.0 95-07-18. Niclas Borlin, niclas@cs.umu.se.
8
9p=allperm(size(C,1));
10
11c=zeros(size(p,1),1);
12
13I=eye(size(C,1));
14
15for i=1:size(p,1)
16 c(i)=sum(C(logical(sparse(p(i,:),1:size(C,1),1))));
17end
diff --git a/SD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib/v5/optim/assignprob/allperm.m b/SD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib/v5/optim/assignprob/allperm.m
new file mode 100755
index 0000000..b8d419e
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib/v5/optim/assignprob/allperm.m
@@ -0,0 +1,17 @@
1function p=allperm(n)
2%ALLPERM All permutation matrix.
3%
4%p=allperm(n)
5%Returns a matrix with all permutations of 1:n stored row-wise.
6
7% v1.0 95-07-18. Niclas Borlin, niclas@cs.umu.se.
8
9if (n<=1)
10 p=1;
11else
12 q=allperm(n-1);
13 p=[];
14 for i=1:n
15 p=[p;i*ones(size(q,1),1) q+(q>=i)];
16 end
17end
diff --git a/SD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib/v5/optim/assignprob/condass.m b/SD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib/v5/optim/assignprob/condass.m
new file mode 100755
index 0000000..82552e7
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib/v5/optim/assignprob/condass.m
@@ -0,0 +1,54 @@
1function [k,C1,T1,C2,T2]=condass(A)
2%CONDASS Calculate condition number of the assigment problem.
3%
4%[k,C1,T1,C2,T2]=condass(A)
5%A - A square cost matrix.
6%k - The condition number of the assigment problem.
7%C1 - The best assigment.
8%T1 - The lowest cost.
9%C2 - The second best assignment.
10%T2 - The second lowest cost.
11%
12%The condition number is calculated as the relative difference between
13%the best and second best solutions, as described in Nystrom, Soderkvist,
14%and Wedin, "A Note on some Identification Problems Arising in Roentgen
15%Stereo Photogrammetric Analysis", J of Biomechanics, 27(10):1291-1294,
16%1994.
17
18% v1.0 96-09-14. Niclas Borlin, niclas@cs.umu.se.
19
20% A substantial effort was put into this code. If you use it for a
21% publication or otherwise, please include an acknowledgement and notify
22% me by email. /Niclas
23
24% Create a large number used to block selected assignments.
25big=sum(sum(A))+1;
26
27% Get best assigment.
28[C1,T1]=hungarian(A);
29
30% Initialize second best solution.
31T2=inf;
32C2=zeros(size(C1));
33
34% Create a work matrix.
35B=A;
36for i=1:length(C1)
37 % Block assigment in column i.
38 B(C1(i),i)=big;
39 % Get best assigment with this one blocked.
40 [C,T]=hungarian(B);
41 if (T<T2)
42 % Remember it if it's the best so far.
43 T2=T;
44 C2=C;
45 end
46 % Remove blocking in column i.
47 B(C1(i),i)=A(C1(i),i);
48end
49
50% Calculate difference...
51mu=T2-T1;
52
53% ...and condition number.
54k=T1/mu;
diff --git a/SD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib/v5/optim/assignprob/demo.m b/SD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib/v5/optim/assignprob/demo.m
new file mode 100755
index 0000000..2d34e37
--- /dev/null
+++ b/SD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib/v5/optim/assignprob/demo.m
@@ -0,0 +1,38 @@
1A=magic(10);
2B=A(4:7,4:7);
3disp('Cost matrix:')
4disp(B)
5disp('Calculating best assignment...');
6[c,t]=hungarian(B);
7disp('Best assignment (as row indices):')
8disp(c)
9disp('Best assignment (as logical matrix):')
10disp(logical(full(sparse(c,1:4,1))))
11disp('Lowest cost:')
12disp(t)
13
14disp(sprintf('\nCalculating condition number for solution...'));
15[k,c1,t1,c2,t2]=condass(B);
16disp('Lowest cost (should be same as above): ')
17disp(t1)
18disp('corresponding assignment (should be same as above):')
19disp(c1)
20disp('Second lowest cost: ')
21disp(t2)
22disp('corresponding assignment:')
23disp(c2)
24disp('Condition number for solution:')
25disp(k)
26
27disp(sprintf('\nCalculating all possible costs...'));
28[c,p]=allcosts(B);
29% Sort by cost.
30[y,i]=sort(c);
31disp('The three lowest costs:')
32disp(c(i(1:3)))
33disp('Corresponding assignments:')
34disp(p(i(1:3),:))
35disp('The three highest costs:')
36disp(c(i(end+[-2:0])))
37disp('Corresponding assignments:')
38disp(p(i(end+[-2:0]),:))
diff --git a/SD-VBS/comm