MATLAB: Matchpairs function input parameter costUnmatched

graph theorymatchpairsMATLAB

How to choose proper value of parameter costUnmatched (matchpairs function) to get requested number of matches.
Especially in a case, when I need maximum number of possible matches min(M,N), where [M,N] = size(Cost), Cost is (M x N) matrix.
Is there at least some clue for a suitable choice of costUnmatched for given cost matrix?

Best Answer

I propose the following costUnmatched input parameter estimation for given Cost matrix:
costUnmatched = max(size(Cost)) * max(Cost,[],'all')
then
M = matchpairs(Cost,costUnmatched)
and the following accuracy check:
CostAssigned = sum(Cost(sub2ind(size(Cost), M(:,1), M(:,2))));
CostUnassigned = costUnmatched*(sum(size(Cost))-2*size(M,1));
TotalCost = CostAssigned + CostUnassigned;
if TotalCost - CostUnassigned == 0
error('matchpairs: Input parameter costUnmatched is very high ... possible loss of accuracy');
end