-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCrowdingDistance.m
36 lines (32 loc) · 966 Bytes
/
CrowdingDistance.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
function Rep=CrowdingDistance(Rep)
% Sort Repository
tmp=[Rep.Cost];
[~,ind]=sort(tmp(1,:));
Rep=Rep(ind);
% Rep(1).CD=100;
% Rep(end).CD=100;
costs=[Rep.Cost]';
[~,I,~] = unique(costs, 'rows', 'first');
Rep=Rep(I);
if numel(Rep)>=2
% d1=abs((Rep(2).Cost(1)-Rep(1).Cost(1)));
% d2=abs((Rep(2).Cost(2)-Rep(1).Cost(2)));
% d=d1+d2;
Rep(1).CD=100;
% d1=abs((Rep(end).Cost(1)-Rep(end-1).Cost(1)));
% d2=abs((Rep(end).Cost(2)-Rep(end-1).Cost(2)));
% d=d1+d2;
Rep(end).CD=100;
elseif numel(Rep)==1
Rep(1).CD=100;
end
cost=[Rep.Cost];
fmin=min(cost,[],2);
fmax=max(cost,[],2);
for i=2:numel(Rep)-1
d1=abs((Rep(i-1).Cost(1)-Rep(i+1).Cost(1)))/(fmax(1)-fmin(1));
d2=abs((Rep(i-1).Cost(2)-Rep(i+1).Cost(2)))/(fmax(2)-fmin(2));
d=d1+d2;
Rep(i).CD=d;
end
end