cblearn.datasets.make_random_triplet_indices#

cblearn.datasets.make_random_triplet_indices(n_objects, size=1.0, random_state=None, repeat=True, monotonic=False, make_all=10000)[source]#

Sample random triplet indices.

If (almost) all triplets are requested, chooses directly from all possible triplets. Otherwise in an iterative approach candidates for triplets are generated to allow sampling for large n_objects.

>>> triplets = make_random_triplet_indices(n_objects=12, size=1000)
>>> triplets.shape
(1000, 3)
>>> np.unique(triplets)
array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11])
Parameters:
  • n_objects (int) – Number of objects to represent in triplets.

  • size (int | float) – Either absolute or relative number of triplets to generate.

  • random_state (None | int | RandomState) – Seed for random sampling.

  • repeat (bool) – Sample with repetitions

  • monotonic (bool) – Sample triplets (i, j, k), such that j < i < k.

  • make_all (int) – Choose from all triplets instead of iterative sampling, if the difference between all triplets to the requested number is smaller than this value.

Returns:

Numpy array (n_triplets, 3) of triplets.

n_triplets is determined through size. Size of 1. corresponds to all available triplets:

  • If monotonic=False \(\text{n_all_triplets}=3 \dot {\text{n_objects} \choose 3}\).

  • If monotonic=True \(\text{n_all_triplets}={\text{n_objects} \choose 3}\).

Raises:

ValueError – If repeat = False but more size is larger than all possible triplets for n_objects.

Return type:

ndarray