diff options
Diffstat (limited to 'SD-VBS/common/toolbox/toolbox_basic/matching/pub/contrib')
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 @@ | |||
| 1 | function [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 | |||
| 9 | p=allperm(size(C,1)); | ||
| 10 | |||
| 11 | c=zeros(size(p,1),1); | ||
| 12 | |||
| 13 | I=eye(size(C,1)); | ||
| 14 | |||
| 15 | for i=1:size(p,1) | ||
| 16 | c(i)=sum(C(logical(sparse(p(i,:),1:size(C,1),1)))); | ||
| 17 | end | ||
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 @@ | |||
| 1 | function 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 | |||
| 9 | if (n<=1) | ||
| 10 | p=1; | ||
| 11 | else | ||
| 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 | ||
| 17 | end | ||
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 @@ | |||
| 1 | function [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. | ||
| 25 | big=sum(sum(A))+1; | ||
| 26 | |||
| 27 | % Get best assigment. | ||
| 28 | [C1,T1]=hungarian(A); | ||
| 29 | |||
| 30 | % Initialize second best solution. | ||
| 31 | T2=inf; | ||
| 32 | C2=zeros(size(C1)); | ||
| 33 | |||
| 34 | % Create a work matrix. | ||
| 35 | B=A; | ||
| 36 | for 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); | ||
| 48 | end | ||
| 49 | |||
| 50 | % Calculate difference... | ||
| 51 | mu=T2-T1; | ||
| 52 | |||
| 53 | % ...and condition number. | ||
| 54 | k=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 @@ | |||
| 1 | A=magic(10); | ||
| 2 | B=A(4:7,4:7); | ||
| 3 | disp('Cost matrix:') | ||
| 4 | disp(B) | ||
| 5 | disp('Calculating best assignment...'); | ||
| 6 | [c,t]=hungarian(B); | ||
| 7 | disp('Best assignment (as row indices):') | ||
| 8 | disp(c) | ||
| 9 | disp('Best assignment (as logical matrix):') | ||
| 10 | disp(logical(full(sparse(c,1:4,1)))) | ||
| 11 | disp('Lowest cost:') | ||
| 12 | disp(t) | ||
| 13 | |||
| 14 | disp(sprintf('\nCalculating condition number for solution...')); | ||
| 15 | [k,c1,t1,c2,t2]=condass(B); | ||
| 16 | disp('Lowest cost (should be same as above): ') | ||
| 17 | disp(t1) | ||
| 18 | disp('corresponding assignment (should be same as above):') | ||
| 19 | disp(c1) | ||
| 20 | disp('Second lowest cost: ') | ||
| 21 | disp(t2) | ||
| 22 | disp('corresponding assignment:') | ||
| 23 | disp(c2) | ||
| 24 | disp('Condition number for solution:') | ||
| 25 | disp(k) | ||
| 26 | |||
| 27 | disp(sprintf('\nCalculating all possible costs...')); | ||
| 28 | [c,p]=allcosts(B); | ||
| 29 | % Sort by cost. | ||
| 30 | [y,i]=sort(c); | ||
| 31 | disp('The three lowest costs:') | ||
| 32 | disp(c(i(1:3))) | ||
| 33 | disp('Corresponding assignments:') | ||
| 34 | disp(p(i(1:3),:)) | ||
| 35 | disp('The three highest costs:') | ||
| 36 | disp(c(i(end+[-2:0]))) | ||
| 37 | disp('Corresponding assignments:') | ||
| 38 | disp(p(i(end+[-2:0]),:)) | ||
diff --git a/SD-VBS/comm | |||
