def get_triplets(self, anom_idx, x, y, normal_label=0):
    self.x = x.cpu().data.numpy()
    self.y = y.cpu().data.numpy()
    n_neighbors = self.nbrs_num
    rand_num = self.rand_num
    anom_x = self.x[anom_idx]
    anom_indices = np.where((self.y != normal_label))[0]
    noml_indices = np.where((self.y == normal_label))[0]
    noml_x = self.x[noml_indices]
    nbrs_local = NearestNeighbors(n_neighbors=n_neighbors).fit(noml_x)
    nbr_indices = noml_indices[nbrs_local.kneighbors([anom_x])[1].flatten()]
    rand_canddt_nor = np.setdiff1d(noml_indices, nbr_indices)
    rand_nor_indices = np.random.choice(rand_canddt_nor, rand_num, replace=False)
    triplets1 = [[anchor, positive, anom_idx] for anchor in rand_nor_indices for positive in nbr_indices]
    rand_canddt_ano = np.setdiff1d(anom_indices, anom_idx)
    if (len(rand_canddt_ano) < rand_num):
        rand_ano_indices = rand_canddt_ano
    else:
        rand_ano_indices = np.random.choice(rand_canddt_ano, rand_num, replace=False)
    triplets2 = [[anchor, anom_idx, negative] for anchor in rand_ano_indices for negative in nbr_indices]
    triplets = (triplets1 + triplets2)
    target1 = ([[0, 0, 1]] * len(triplets1))
    target2 = ([[1, 1, 0]] * len(triplets2))
    target = (target1 + target2)
    return (torch.LongTensor(np.array(triplets)), torch.LongTensor(np.array(target)))
def get_triplets(self, anom_idx, x, y, normal_label=0):
    self.x = x.cpu().data.numpy()
    self.y = y.cpu().data.numpy()
    n_neighbors = self.nbrs_num
    rand_num = self.rand_num
    anom_x = self.x[anom_idx]
    anom_indices = np.where((self.y != normal_label))[0]
    noml_indices = np.where((self.y == normal_label))[0]
    noml_x = self.x[noml_indices]
    nbrs_local = NearestNeighbors(n_neighbors=n_neighbors).fit(noml_x)
    nbr_indices = noml_indices[nbrs_local.kneighbors([anom_x])[1].flatten()]
    rand_canddt_nor = np.setdiff1d(noml_indices, nbr_indices)
    rand_nor_indices = np.random.choice(rand_canddt_nor, rand_num, replace=False)
    triplets1 = [[anchor, positive, anom_idx] for anchor in rand_nor_indices for positive in nbr_indices]
    rand_canddt_ano = np.setdiff1d(anom_indices, anom_idx)
    if (len(rand_canddt_ano) < rand_num):
        rand_ano_indices = rand_canddt_ano
    else:
        rand_ano_indices = np.random.choice(rand_canddt_ano, rand_num, replace=False)
    triplets2 = [[anchor, anom_idx, negative] for anchor in rand_ano_indices for negative in nbr_indices]
    triplets = (triplets1 + triplets2)
    target1 = ([[0, 0, 1]] * len(triplets1))
    target2 = ([[1, 1, 0]] * len(triplets2))
    target = (target1 + target2)
    return (torch.LongTensor(np.array(triplets)), torch.LongTensor(np.array(target)))