diff options
| author | ziejd2 | 2017-09-28 15:04:40 -0500 |
|---|---|---|
| committer | ziejd2 | 2017-09-28 15:04:40 -0500 |
| commit | 8070dc963753142bb86c4ed698d91fd623ed28e7 (patch) | |
| tree | d0f6dd8fc46a49b819aa55c1a90faa14d8448883 /sourcecodes/bnt-master/KPMtools/bipartiteMatchingIntProg.m | |
| parent | 7cc31810d53176e805532b2789955f4eedbce6bb (diff) | |
| download | BNW-8070dc963753142bb86c4ed698d91fd623ed28e7.tar.gz | |
BNW using Octave instead of Matlab.
This version of BNW should perform the same as the original version. The only difference is that it uses Octave instead of Matlab when running BayesNet Toolbox during parameter learning. I am calling this BNW_1.02. It can be accessed at: compbio.uthsc.edu/BNW_1.02
Diffstat (limited to 'sourcecodes/bnt-master/KPMtools/bipartiteMatchingIntProg.m')
| -rw-r--r-- | sourcecodes/bnt-master/KPMtools/bipartiteMatchingIntProg.m | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/sourcecodes/bnt-master/KPMtools/bipartiteMatchingIntProg.m b/sourcecodes/bnt-master/KPMtools/bipartiteMatchingIntProg.m new file mode 100644 index 00000000..26efaba8 --- /dev/null +++ b/sourcecodes/bnt-master/KPMtools/bipartiteMatchingIntProg.m @@ -0,0 +1,69 @@ +function [a,ass] = bipartiteMatchingIntProg(dst, nmatches) +% BIPARTITEMATCHINGINTPROG Use binary integer programming (linear objective) to solve for optimal linear assignment +% function a = bipartiteMatchingIntProg(dst) +% a(i) = best matching column for row i +% +% This gives the same result as bipartiteMatchingHungarian. +% +% function a = bibpartiteMatchingIntProg(dst, nmatches) +% only matches the specified number (must be <= min(size(dst))). +% This can be used to allow outliers in both source and target. +% +% For details, see Marciel & Costeira, "A global solution to sparse correspondence +% problems", PAMI 25(2), 2003 + +if nargin < 2, nmatches = []; end + +[p1 p2] = size(dst); +p1orig = p1; p2orig = p2; +dstorig = dst; + +if isempty(nmatches) % no outliers allowed (modulo size difference) + % ensure matrix is square + m = max(dst(:)); + if p1<p2 + dst = [dst; m*ones(p2-p1, p2)]; + elseif p1>p2 + dst = [dst m*ones(p1, p1-p2)]; + end +end +[p1 p2] = size(dst); + + +c = dst(:); % vectorize cost matrix + +% row-sum: ensure each column sums to 1 +A2 = kron(eye(p2), ones(1,p1)); +b2 = ones(p2,1); + +% col-sum: ensure each row sums to 1 +A3 = kron(ones(1,p2), eye(p1)); +b3 = ones(p1,1); + +if isempty(nmatches) + % enforce doubly stochastic + A = [A2; A3]; + b = [b2; b3]; + Aineq = zeros(1, p1*p2); + bineq = 0; +else + nmatches = min([nmatches, p1, p2]); + Aineq = [A2; A3]; + bineq = [b2; b3]; % row and col sums <= 1 + A = ones(1,p1*p2); + b = nmatches; % total num matches = b (otherwise get degenerate soln) +end + + +ass = bintprog(c, Aineq, bineq, A, b); +ass = reshape(ass, p1, p2); + +a = zeros(1, p1orig); +for i=1:p1orig + ndx = find(ass(i,:)==1); + if ~isempty(ndx) & (ndx <= p2orig) + a(i) = ndx; + end +end + + |
