abx_numpy Package

abx_numpy Package

abx_numpy: Main module

Copyright 2015, Roland Thiolliere Licensed under GPLv3.

abx_numpy.abx_numpy.abx(classes, features, distance_function, cutoff=1000)[source]

Calculate the ABX score for a set of classes and a features matrix.

The order of the ‘classes’ and the ‘features’ arrays must be the same.

Parameters:

classes : array (n_items)

1-D array containing the class labels of the items.

features : array (n_items, dim_features)

2-D array containing the features of the items.

distance_function : callable

Distance function to use.

cutoff : int, optionnal

Cutoff to use for sample (number of items kept). None for no sample. Default to 1000.

Returns:

average : float

average abx score

labels : array (n_classes)

1D array containing the unique classes

scores : array (n_classes, n_classes)

2D array containing the abx scores for each pair of classes. The diagonal contains nan values

abx_numpy.abx_numpy.compute_distances(features, distance_function)[source]

Compute the distance matrix for an array of features and a distance function.

Parameters:

features : array (n_items, dim_features)

2-D array containing the features of the items.

distance_function : callable

Distance function to use.

Returns:

distances : array (n_items, n_items)

2-D array containing the pairwise distance of the items.

abx_numpy.abx_numpy.sample(classes, features, cutoff, is_sorted=False)[source]

‘Fair’ sampling (non-uniform, inverse to the class weight)

Parameters:

classes : array (n_items)

1-D array containing the class labels of the items.

features : array (n_items, dim_features)

2-D array containing the features of the items.

cutoff : int

Cutoff to use for sample (number of items kept).

Returns:

sampled classes, sampled features

abx_numpy.abx_numpy.score(classes, distances, is_sorted=False)[source]

Compute the ABX score for a set of sorted classes and a distance matrix.

Returns:

average : float

average abx score

labels : array (n_classes)

1D array containing the unique classes

scores : array (n_classes, n_classes)

2D array containing the abx scores for each pair of classes. The diagonal contains nan values

abx_numpy.abx_numpy.sort(classes, features)[source]

Sort classes according to labels and features according to the new order

lib Module

@author: Roland Thiolliere

abx_numpy.lib.unique_sorted(array)[source]

Performs unique on a sorted array and return the unique elements and the indexes of the first element of each block.