-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_maximal_rows.m
56 lines (52 loc) · 1.76 KB
/
get_maximal_rows.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
function maximals = get_maximal_rows(unknowns)
% GET_MAXIMAL_ROWS returns a matrix with pointwise maximal rows
%
% Synopsis:
% maximals = get_maximal_rows(unknowns)
%
% Input:
% unknowns = a matrix with rows of unknown relative pointwise
% dominance status
%
% Output:
% maximals = a matrix with the unique pointwise maximal rows of the
% input matrix unknowns; relative order is not preserved
%
% Background & Method:
% A vector x pointwise dominates another vector y if every component of
% their difference x-y is nonpositive. This function uses a simple
% scanning algorithm inspired by, but not equal to, the 'Best' algorithm
% as presented in
%
% Godfrey, P., Shipley, R., & Gryz, J. (2007). “Algorithms and
% analyses for maximal vector computation.” The VLDB Journal, 16(1),
% 5-28. doi:10.1007/s00778-006-0029-7
% preallocate
maximals = [];
while ~isempty(unknowns)
candidate = unknowns(1,:);
% assume the candidate is maximal and compare it with all other rows
maximals = [maximals; candidate];
unknowns(1,:) = [];
dominated = [];
for k = 1:size(unknowns, 1)
comparandum = unknowns(k,:);
criterion = candidate - comparandum;
% detect rows dominated by the candidate
if all(criterion >= 0)
dominated = [dominated; k];
% detect if candidate is nonmaximal
elseif all(criterion <= 0)
maximals(end,:) = [];
% "promote the winner"-heuristic: move dominating vector to the
% front, to become the next candidate
unknowns(k,:) = [];
unknowns = [comparandum; unknowns];
dominated = dominated + 1;
break;
end
end
% remove dominated from unknowns
unknowns(dominated,:) = [];
end
end