cblearn.datasets.triplet_response#

cblearn.datasets.triplet_response(triplets, embedding, result_format=None, distance='euclidean')[source]#

Triplet responses for an embedding.

The default assumes Euclidean distances between embedding points.

>>> triplets = [[1, 0, 2], [1, 2, 0]]
>>> points = [[0], [4], [5]]
>>> triplets, response = triplet_response(triplets, points, result_format='list-boolean')
>>> triplets, response
(array([[1, 0, 2],
       [1, 0, 2]], dtype=uint32), array([False, False]))

To use alternative distance metrics, you can pass precomputed distances instead of an embedding.

>>> from sklearn.metrics import pairwise
>>> distances = pairwise.manhattan_distances(points)
>>> triplets, response = triplet_response(triplets, distances, result_format='list-boolean', distance='precomputed')
>>> response
array([False, False])
Parameters:
  • triplets (ndarray | COO | spmatrix) – Numpy array or sparse matrix of triplet indices

  • embedding (ndarray) – Numpy array of object coordinates, (n_objects, n_components)

  • result_format (str | None) – Format of the result. If none, keeps input format.

  • distance (str | Distance) – {‘euclidean’, ‘precomputed’}. Specifies distance metrix between embedding points or if distances are passed directly as distance matrix.

Returns:

Responses in format as defined by response_format either numpy array (n_triplets,) or sparse matrix

If return_indices is True, a tuple of indices and responses can be returned

Return type:

ndarray | COO | spmatrix