'Entry-wise domination of vectors
I have several list of reals in [0,1] of identical size. For instance:
[0.33, 0.0, 0.0, 0.33, 0.33, 0.33, 0.0]
[0.0, 0.33, 0.0, 0.33, 0.33, 0.33, 0.0]
[0.0, 0.33, 0.0, 0.33, 0.0, 0.33, 0.0]
I suspect that some lists are strictly dominated by others; for instance the third list is dominated by the second; in the sense that l3[i] <= l2[i] for all i; and l3[j] < l2[j] for at least one j. I want to get rid of those; so I wrote these two functions:
# R correspond to the original list of lists.
# Rp is the list where the striclty dominated lists have been removed.
def minor_solution(r, R):
"""determines if there exists r2 in R such that r <= r2 for all value and r<r2 for at least one value"""
for r2 in R:
if strict_domination(r, r2):
return True
return False
def strict_domination(r1,r2):
"""return true iff r1 is stricly dominated by r2."""
strict = False
dom = True
for i in range(len(r1)):
strict = strict or (r1[i] < r2[i])
dom = dom and (r1[i] <= r2[i])
return dom and strict
Rp = []
for ri in R:
if minor_solution(ri, R) == False:
Rp.append(ri)
My problem is that this does not work. Some list are eventually removed; but some which should be removed remains. For instance; the third list in the example I gave was not removed. Any idea?
Solution 1:[1]
for such comparisons you don't need to loop over all your elements, it will be enough to check elements like this :
l1 = [0,2,5]
l2 = [0,2,5]
l1==l2
True
or
l1 = [0,2,5]
l2 = [0,2,10]
l1<l2
True
and python will do the element-wise work for you. Here come's my question, do you need a "survival of the fittest", the most predominant list of all or something else, because from the description you gave,it is not clear what the relation to the rest of list-elements should be. Maybe a bit more exhaustive example of what you'd like to receive will be helpful.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | baskettaz |