MATLAB Answers

matchpairs function input parameter costUnmatched

6 views (last 30 days)
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?


Show 7 older comments
Michal Kvasnicka
Michal Kvasnicka on 14 Feb 2020
@Adam this is the main reason why I wrote the comment: "@Adam ... I rephrase my question to be more clear and simple." mostly as a apology.
If you are not comfortable with your comment in a new context ... you can delete it.
Adam on 14 Feb 2020
It's more a case of having wasted my time writing it in the first place if everything it refers to is subsequently deleted. It's not a big issue, but it discourages people from spending their time in the future.

Sign in to comment.

Accepted Answer

Michal Kvasnicka
Michal Kvasnicka on 14 Feb 2020
Edited: Michal Kvasnicka on 14 Feb 2020
I propose the following costUnmatched input parameter estimation for given Cost matrix:
costUnmatched = max(size(Cost)) * max(Cost,[],'all')
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');


Show 2 older comments
Michal Kvasnicka
Michal Kvasnicka on 14 Feb 2020
So, what do you propose in the case of matchpairs function accuracy loss? I think user should be, at least, warned that something is wrong.
Steven Lord
Steven Lord on 14 Feb 2020
If I'm right about what's going on in this situation, should the second line in the following example warn as well? After all, users might think that "something is wrong" when y turns out to be equal to x.
x = 1e20;
y = x + 1;
If this should issue a warning, every single call to plus would need to check if it needs to issue a warning. How much of a slowdown would you be okay with imposing on every user of the plus function or + operator for that check? It might only be a tiny slowdown, but how many times does the MATLAB code you run use the plus function or + operator? A tiny slowdown occurring thousands or millions of times over the course of running your program can add up to a substantial delay.
>> minutes(1e6*seconds(0.001))
ans =
Lest you think this is a hypothetical concern ... there used to be a function called intwarning. [It started issuing a warning about its removal in release R2010a and started throwing an error in release R2010b.] Looking at its documentation from one of the releases where it existed (I chose release R2009b):
"Caution Enabling the MATLAB:intMathOverflow warning slows down integer arithmetic. It is recommended that you enable this particular warning only when you need to diagnose unusual behavior in your code, and disable it during normal program operation. The other integer warnings listed here do not affect program performance."
Warning can impact performance.
Michal Kvasnicka
Michal Kvasnicka on 14 Feb 2020
@Steven Lord My motivattion how and why I propose to modify the matchpairs function is based only on the fact, that in a case of
TotalCost - CostUnassigned == 0
the resulting matches M are incorrect. So, from my point view, should be good idea to warn user that (in this specific case, only!!!) is something wrong. That is all.

Sign in to comment.

More Answers (0)




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by