make_indexes#
- scio.scores.utils.make_indexes(all_samples, all_groups=None, *, n_groups=None, metric, squeeze=True)[source]#
Prepare multiple search indexes.
For now only
faiss.IndexFlatL2orfaiss.IndexFlatIP. Note that distances returned when querying thesefaissindexes are respectively the squared euclidian distance and the inner product – which is a similarity measure, not a distance. In the latter case, the returned neighbors are still ordered from the “closest” (most similar) to the furthest.- Parameters:
all_samples (
tuple[Tensor, ...] | Tensor) – If aTensor, treated as(all_samples,). Tuple of tensors of shape(n_samples, *sample_shape)of common lengthn_samples. The samples from which to build search indexes, treated as vector samples.all_groups (
tuple[Tensor, ...] | Tensor, optional) – If not provided, treated astorch.zeros(n_samples). If aTensor, treated as(all_groups,). Tuple of tensors of shape(n_samples,). The group every sample belongs to. Values must be nonnegative integers.n_groups (
int, optional) – Ifall_groupsis not provided, treated as1. Else it is required to be anint. Group values inrange(n_groups)are considered. Empty indexes are possible (e.g. when there are no samples for a given group value).metric (
IndexMetricLike) – SeeIndexMetric.squeeze (
bool) – Whether to apply the postprocessing squeezing steps described inindexes. Defaults toTrue.
- Returns:
indexes (Nested tuples of
Index, optionally squeezed) – Every search index. Whenall_groupsandall_samplesare tuples, there arelen(all_groups) * len(all_samples) * n_groupsindexes. From outermost to innermost, nested tuples are respectively alongall_groups,all_samplesand group values. Finally, the following is applied ifsqueeze. Ifall_groupsorall_samplesareTensor, their respective tuple is squeezed. Furthermore, ifall_groupswas not provided the tuple corresponding to group value is squeezed.
Hint
Think of
all_samplesas layers activations stacked in a tuple along layers for example.Think of
all_groupsas(true_labels, pred_labels)for example.- Raises:
ValueError – If
n_groupsis not anint, despiteall_groupsbeingNone.
Note
For accurate output type specification, please refer to the associated source stub.