I was wondering if there was an external lib or a built-in to generate unique triplets from two lists. So, I have two lists like so (the elements of the source list are PyTorch tensors - I have abstracted it out here as just numbers):
source_list=[1,2,3,4,5,6,7,8..] # size N
labels_list=[1,1,0,2,1,3,6..] # size N
and I would like triplets of form:
<anchor> <postive> <negative>
where, <anchor>
can be any element in the source_list
, postive
means that this element should come from the same label as the anchor(so, 1,2 and 1,5 could be seen as postive pairs in the triplet) and negative'
s mean that they should be from a different label (so, 1,3 and 1,4 would be considered a negative pair of the triplet). So, some examples of the correct triplet would be:
1, 2, 3
1, 2, 4
1, 2, 6
From the outset it seems like a N choose k
problem, but I am not sure how to approach this with minimal computational cost other than doing loops with each element in python.