module: utils¶
This module is a collection of helpful functions.
-
annotlib.utils.check_indices(indices, max_index, parameter_name='indices')[source]¶ This function checks whether the given indices are valid.
Parameters: - indices: array-like, shape (n_indices)
Array of indices to test.
- max_index: int
The maximal allowed index.
- parameter_name: str,
The name of the indices array, which is printed in case of error.
Returns: - indices: numpy.ndarray, shape (n_indices)
Is returned, if 0<= indices[i] <= max_index for all i and if indices contains no duplicates.
-
annotlib.utils.check_labelling_array(arr, shape, parameter_name='arr')[source]¶ This function checks whether the given array has the given shape and all its values are in the interval [0, 1].
Parameters: - arr: array-like
Array whose shape is checked.
- shape: array-like
The expected shape of the given array arr.
- parameter_name: str,
The name of the indices array, which is printed in case of error.
Returns: - arr: array-like
Array whose shape is checked.
-
annotlib.utils.check_positive_integer(value, parameter_name='value')[source]¶ This function checks whether the given value is a positive integer.
Parameters: - value: numeric,
Value to check.
- parameter_name: str,
The name of the indices array, which is printed in case of error.
Returns: - value: int,
Checked and converted int.
-
annotlib.utils.check_range(arr, min_value, max_value, parameter_name='arr')[source]¶ This function tests whether all elements of an array are in a given range.
Parameters: - arr: array-like,
Array.
- min_value: float
Minimal number.
- max_value: float
Maximal number.
- parameter_name: str,
The name of the array arr, which is printed in case of error.
Returns: - arr: numpy.ndarray
Is returned, if min <= arr[i] <= max for all arr[i].
-
annotlib.utils.check_shape(arr, shape, parameter_name='arr')[source]¶ This function checks whether the given array has the expected shape.
Parameters: - arr: array-like
Array whose shape is checked.
- shape: array-like
The expected shape of the given array arr.
- parameter_name: str,
The name of the indices array, which is printed in case of error.
Returns: - arr: array-like
Array whose shape is checked.
-
annotlib.utils.transform_confidences(C, n_classes)[source]¶ Originally, non-adversarial annotators provide confidences in the interval [1/n_classes, 1]. In contrast, adversarial annotators have confidences in [0, 1/n_classes]. This function transforms the confidences into an interval [0, 1] for both annotator types. However, the meaning of the confidences is contrary. A class label provided by an adversarial annotator with confidence 1 is wrong in any case, whereas a class label provided by a non-adversarial annotator with confidence 1 is true in any case.
Parameters: - C: array-like, shape (n_samples, n_annotators)
confidences to be transformed.
- n_classes: int
Number of classes.
Returns: - C_trans: array-like, shape (n_samples, n_annotators)
Transformed confidences.