How to optimize the following algorithm?

조회 수: 12 (최근 30일)
C Zeng
C Zeng 2013년 6월 6일
I have a large matrix-M, and the rows have been sorted based on the value on some entry. Next I want to identify all rows that can be dominated, i.e., row #i is dominated by #j if j<i and M(j,:)<=M(i,:).
If rows #i is dominated, we can remove row i. I notice that remove row #i takes a lot of time for a large matrix so I set a index() and each time if it is dominated then index(i)=1. At last, M(index)=[]. (remove those dominated rows at last)
I run my code several times, and find out there is a bottleneck-N loops. Below I show some code:
for i=3:N
j=2; %j from i-1 to may be faster!
while j<=i-1
if all(M(j,1:N)<=M(i,1:N))
idx(i)=1;
break;
else
j=j+1;
end
end
end
M(idx)=[];
I am thinking if someone can help me to optimize the code? Can we do better here? Thanks.
  댓글 수: 2
Sean de Wolski
Sean de Wolski 2013년 6월 6일
Is idx preallocated?
idx = zeros(N,1);
C Zeng
C Zeng 2013년 6월 6일
편집: C Zeng 2013년 6월 6일
Yes, Sean, you are right. That is the index that records which row is dominated, I will delete them at last.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Surrogate Optimization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by