modAL.utils

modAL.utils.make_linear_combination(*functions, weights: Optional[Sequence] = None) → Callable[source]

Takes the given functions and makes a function which returns the linear combination of the output of original functions. It works well with functions returning numpy arrays of the same shape.

Parameters:
  • *functions – Base functions for the linear combination.The functions shall have the same argument and if they return numpy arrays, the returned arrays shall have the same shape.
  • weights – Coefficients of the functions in the linear combination. The i-th given function will be multiplied with weights[i].
Returns:A function which returns the linear combination of the given functions output.
modAL.utils.make_product(*functions, exponents: Optional[Sequence] = None) → Callable[source]

Takes the given functions and makes a function which returns the product of the output of original functions. It works well with functions returning numpy arrays of the same shape.

Parameters:
  • *functions – Base functions for the product. The functions shall have the same argument and if they return numpy arrays, the returned arrays shall have the same shape.
  • exponents – Exponents of the functions in the product. The i-th given function in the product will be raised to the power of exponents[i].
Returns:

A function which returns the product function of the given functions output.

modAL.utils.make_query_strategy(utility_measure: Callable, selector: Callable) → Callable[source]

Takes the given utility measure and selector functions and makes a query strategy by combining them.

Parameters:
  • utility_measure – Utility measure, for instance vote_entropy(), but it can be a custom function as well. Should take a classifier and the unlabelled data and should return an array containing the utility scores.
  • selector – Function selecting instances for query. Should take an array of utility scores and should return an array containing the queried items.
Returns:

A function which returns queried instances given a classifier and an unlabelled pool.

modAL.utils.data_vstack(blocks: Container) → Union[list, numpy.ndarray, scipy.sparse.csr.csr_matrix][source]

Stack vertically both sparse and dense arrays.

Parameters:blocks – Sequence of modALinput objects.
Returns:New sequence of vertically stacked elements.
modAL.utils.multi_argmax(values: numpy.ndarray, n_instances: int = 1) → numpy.ndarray[source]

Selects the indices of the n_instances highest values.

Parameters:
  • values – Contains the values to be selected from.
  • n_instances – Specifies how many indices to return.
Returns:

The indices of the n_instances largest values.

modAL.utils.weighted_random(weights: numpy.ndarray, n_instances: int = 1) → numpy.ndarray[source]

Returns n_instances indices based on the weights.

Parameters:
  • weights – Contains the weights of the sampling.
  • n_instances – Specifies how many indices to return.
Returns:

n_instances random indices based on the weights.

modAL.utils.check_class_labels(*args) → bool[source]

Checks the known class labels for each classifier.

Parameters:*args – Classifier objects to check the known class labels.
Returns:True, if class labels match for all classifiers, False otherwise.
modAL.utils.check_class_proba(proba: numpy.ndarray, known_labels: Sequence, all_labels: Sequence) → numpy.ndarray[source]

Checks the class probabilities and reshapes it if not all labels are present in the classifier.

Parameters:
  • proba – The class probabilities of a classifier.
  • known_labels – The class labels known by the classifier.
  • all_labels – All class labels.
Returns:

Class probabilities augmented such that the probability of all classes is present. If the classifier is unaware of a particular class, all probabilities are zero.