Looping for finding dominating points.

9 views (last 30 days)
Hi,
I have a matrix with 'n' rows and two columns, say,
f(1,1) f(1,2)
f(2,1) f(2,2)
f(3,1) f(3,2)
f(4,1) f(4,2)
............
f(n,1) f(n,2)
I would like to remove dominating row or rows, and record non-dominating rows as a data file. It would be much appreciated if any one can help me with coding to do that.
Thanks in advance.
Rizvi
  2 Comments
Yu Jiang
Yu Jiang on 30 Aug 2014
How do you define a 'dominating row'?
Mohammed Rizvi
Mohammed Rizvi on 31 Aug 2014
Hi Yu,
Thanks for your reply. Let's say, rows are [f(1,1) f(1,2)] and [f(2,1) f(2,2)].
If f(1,1)>f(2,1) and f(1,2)>f(2,2) then [f(1,1) f(1,2)] dominates [f(2,1) f(2,2)], so discard [f(1,1) f(1,2)].
I have a mathematical logic for n=4 which is as follows;
Step 1
If f(1,1) > f(2,1) & f(1,2)> f(2,2)
‘Go to Step-2’
elseif f(1,1) > f(3,1) & f(1,2)> f(3,2)
‘Go to Step-2’
elseif f(1,1) > f(4,1) & f(1,2)> f(4,2)
‘Go to Step-2’
else print(f(1,1), f(1,2))
Step 2
If f(2,1) > f(3,1) & f(2,2)> f(3,2)
Go to Step-3
elseif f(2,1) > f(4,1) & f(2,2)> f(4,2)
Go to Step-3
else print(f(2,1), f(2,2))
Step 3
If f(3,1) > f(4,1) & f(3,2)> f(4,2)
print(f(4,1), f(4,2))
else print (f(3,1), f(3,2)) & (f(4,1), f(4,2))
Many thanks in advance.
Rizvi

Sign in to comment.

Accepted Answer

Roger Stafford
Roger Stafford on 30 Aug 2014
Mohammed Rizvi, in a forum of this nature you really ought to carefully define a concept such as "dominating points" so as to avoid causing an excess of guessing at what you mean.
I will guess that you mean by a "dominating point", a point in a given 2D set for which a straight line can be drawn that separates that point from all other points in the set. If that is what you mean, you could call on 'convhull'. Call your n x 2 matrix f.
K = convhull(f(:,1),f(:,2),'simplify',true);
f(K,:) = [];
This should strip away all "dominating points" of f.
You used the term "looping" in your subject title. I would warn that removing dominating points one at a time can result, if not done properly, in removing too many points, as remaining points that weren't previously dominating points suddenly become dominating ones. It is much better to use a function like 'convhull' which does the job simultaneously (so to speak.)
  1 Comment
Mohammed Rizvi
Mohammed Rizvi on 31 Aug 2014
Hi Roger,
Many thanks for your reply. As per your advice I have run the following code
f = dlmread('ipopt_r.dat'); [Here data file includes info about rows]
K = convhull(f(:,1),f(:,2),'simplify',true)
f(K,:) =[]
However, it is not functioning. Could you please see my replies to other commenters. Thanks again for your help.
Cheers, Rizvi

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 30 Aug 2014
Try this:
% Define rows to remove:
% However they're determined....I don't know, presumably you do.
% For this demo, let's assume you've identified the rows
% and the row numbers are entered into an array.
dominatingRows = [2,3,42,69,123]; % For example...
% Now, remove the dominating rows:
f(dominatingRows, :) = [];
  2 Comments
Mohammed Rizvi
Mohammed Rizvi on 31 Aug 2014
Hi
Thanks for your reply. Let's say, rows are [f(1,1) f(1,2)] and [f(2,1) f(2,2)].
If f(1,1)>f(2,1) and f(1,2)>f(2,2) then [f(1,1) f(1,2)] dominates [f(2,1) f(2,2)], so discard [f(1,1) f(1,2)].
I have a data file f(n, m) where ‘n’ probably 100 or more and ‘m’ may be 2 or 3. I would like to remove dominating row or rows (definition given above) comparing with other rows. Every time I run the code and get a new data file f, and thus I need to remove dominating rows or points. I have a mathematical logic to do that for n=4 (please see in the Yu's reply), however, I could not write any code in MATLAB to implement it.
Any help would be greatly appreciated.
Cheers,
Rizvi
Image Analyst
Image Analyst on 31 Aug 2014
Now it's clear - would have been great to have given that definition in your original post. Try this:
rows = 30; % Whatever you want.
columns = 3; % Whatever you want.
f = rand(rows, columns) % Create sample data.
df = diff(f) % Calc diff between each row and one below it.
% Find where all 3 differences are positive.
dominatingRows = sum(df>0, 2) == size(df, 2)
% Extract only the non-dominating rows.
out = f(~dominatingRows,:)

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!