Find the minimum sum of errors for every permutation

3 views (last 30 days)
I have an (m x n) matrix that is filled with error percentages.
Example:
error = [ 2.1 2.3 1.9 2.0;
1.8 1.9 2.3 2.1;
2.0 1.9 1.8 2.3];
Each row/column can only contain 1 final error percentage.
I need the best permutation that minimizes the sum of all of the chosen errors.
The actual matrix is on the scale of about 100x100 so writing nested for loops and if statements just doesn't seem viable for each row/column.
Is there a more efficient way of calculating the sums of every permutation?
I don't need the whole code written out, just a general approach.
Thanks!
  4 Comments
em7
em7 on 19 Oct 2022
@James Tursa, The example was dumbed down. The gyst is that each element in the matrix will consist of an error (in decimal form). Each row represents some different objects and each column represents some objects that the row can possibly "map" to, hence an error that is calculated using mean squared.
I've been using nested for loops like this:
for i = 1:size(error, 1)
for j = 1:size(error, 2)
end
end
But I need to create several more loops to account for the permutations; far more than I care to type out if I don't have to to save space. I feel like the math is on the tip of my tongue but I can't remember any from school for the life of me.
@the cyclist, your solution would be the correect solution, but I was curious if there's a function or mathematical approach to solving that rather than brute force since I would be operating on several 10's of rows/columns.
the cyclist
the cyclist on 19 Oct 2022
Understood that you want an efficient algorithm. I was just trying to clarify the problem you are trying to solve.

Sign in to comment.

Accepted Answer

Steven Lord
Steven Lord on 19 Oct 2022
Take a look at the matchpairs function.
  3 Comments
Torsten
Torsten on 19 Oct 2022
Can't find anything similar in file exchange either.
Strange. My google search gives many, many matches:
linear assignment problem & matlab

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!