pusion.util.transformer module

pusion.util.transformer.confusion_matrices_to_accuracy_vector(confusion_matrix_tensor)

Convert confusion matrices of respective classification to an accuracy vector.

Parameters

confusion_matrix_tensornumpy.array of shape (n_classifiers, n_classes, n_classes) Confusion matrices.

Returns

One-dimensional numpy.array of shape of length n_classifiers containing the accuracy for each confusion matrix.

pusion.util.transformer.confusion_matrix_to_accuracy(cm)

Calculate the accuracy out of the given confusion matrix.

Parameters

cmnumpy.array of shape (n_classes, n_classes). Confusion matrix.

Returns

The accuracy.

pusion.util.transformer.multilabel_cr_confusion_matrices_to_avg_accuracy(label_cms)

Calculate the average accuracy for the given confusion matrices generated from complementary redundant multilabel output.

Parameters

label_cmslist of confusion matrices given as 2-dimensional numpy.array respectively.

Returns

The average accuracy.

pusion.util.transformer.decision_tensor_to_decision_profiles(decision_tensor)

Transform the given decision tensor to decision profiles for each respective sample.

Parameters

decision_tensornumpy.array of shape (n_classifiers, n_samples, n_classes). Tensor of either crisp or continuous decision outputs by different classifiers per sample.

Returns

numpy.array of shape (n_samples, n_classifiers, n_classes). Decision profiles.

pusion.util.transformer.multilabel_predictions_to_decisions(predictions, threshold=0.5)

Transform a continuously valued tensor of multilabel decisions to crisp decision outputs.

Parameters
  • predictionsnumpy.array of any shape. Continuous predictions.

  • thresholdfloat. A threshold value, based on which the crisp output is constructed.

Returns

numpy.array of the same shape as predictions. Crisp decision outputs.

pusion.util.transformer.multiclass_predictions_to_decisions(predictions)

Transform a continuously valued matrix of multiclass decisions to crisp decision outputs.

Parameters

predictionsnumpy.array of shape (n_samples, n_classes). Continuous predictions.

Returns

numpy.array of the same shape as predictions. Crisp decision outputs.

pusion.util.transformer.multilabel_prediction_tensor_to_decision_tensor(predictions)

Transform a continuously valued tensor of multilabel decisions to crisp decision outputs.

Parameters

predictionsnumpy.array of shape (n_classifiers, n_samples, n_classes). Continuous predictions.

Returns

numpy.array of the same shape as predictions. Crisp decision outputs.

pusion.util.transformer.multiclass_prediction_tensor_to_decision_tensor(predictions)

Transform a continuously valued tensor of multiclass decisions to crisp decision outputs.

Parameters

predictionsnumpy.array of shape (n_classifiers, n_samples, n_classes). Continuous predictions.

Returns

numpy.array of the same shape as predictions. Crisp decision outputs.

pusion.util.transformer.decision_tensor_to_configs(decision_outputs)

Transform decision outputs to decision configs. A decision config shows concatenated classification outputs of each classifier per sample.

Parameters

decision_outputsnumpy.array of shape (n_classifiers, n_samples, n_classes) or a list of numpy.array elements of shape (n_samples, n_classes’), where n_classes’ is classifier-specific due to the coverage.

Returns

numpy.array of shape (n_samples, n_classes*), n_classes* is the sum of all classes covered by all classifiers.

pusion.util.transformer.multiclass_assignments_to_labels(assignments)

Transform multiclass assignments to labels. A matrix of shape (n_samples, n_classes) is converted to a vector of shape (n_samples,), with element-wise labels represented in integers from 0 to n_classes - 1.

Parameters

assignmentsnumpy.array of shape (n_samples, n_classes). Multiclass assignments.

Returns

numpy.array of shape (n_samples,) with an integer label per element.

pusion.util.transformer.transform_label_tensor_to_class_assignment_tensor(label_tensor, n_classes)

Transform a label tensor of shape (n_classifiers, n_samples) to the tensor of class assignments of shape (n_classifiers, n_samples, n_classes). A label is an integer between 0 and n_classes - 1.

Parameters
  • label_tensornumpy.array of shape (n_classifiers, n_samples). Label tensor.

  • n_classes – Number of classes to be considered.

Returns

numpy.array of shape (n_classifiers, n_samples, n_classes). Class assignment tensor (decision tensor).

pusion.util.transformer.transform_label_vector_to_class_assignment_matrix(label_vector, n_classes=None)

Transform labels to multiclass assignments. A vector of shape (n_samples,), with element-wise labels is converted to the assignment matrix of shape (n_samples, n_classes).

Parameters
  • label_vectornumpy.array of shape (n_samples,) with an integer label per element.

  • n_classes – Number of classes to be considered.

Returns

numpy.array of shape (n_samples, n_classes). Multiclass assignments.

pusion.util.transformer.class_assignment_tensor_to_label_tensor(class_assignment_tensor)

Transform multiclass class assignments into a label tensor. A tensor of shape (n_classifiers, n_samples, n_classes) is converted into a tensor of shape (n_classifiers, n_samples) holding the class identifier (label) in each element.

Parameters

class_assignment_tensornumpy.array of shape (n_classifiers, n_samples, n_classes). Class assignment tensor (decision tensor).

Returns

numpy.array of shape (n_classifiers, n_samples). Label tensor.

pusion.util.transformer.class_assignment_matrix_to_label_vector(class_assignment_matrix)

Transform multiclass class assignments into a label vector. A matrix of shape (n_samples, n_classes) is converted into a vector of shape (n_samples,) holding the class identifier (label) in each element.

Parameters

class_assignment_matrixnumpy.array of shape (n_samples, n_classes). Class assignment matrix (decision matrix).

Returns

numpy.array of shape (n_samples,). Label vector.

pusion.util.transformer.multilabel_to_multiclass_assignments(decision_tensor)

Transform the multilabel decision tensor to the equivalent multiclass decision tensor using the power set method. The multilabel class assignments are considered as a binary number which represents a new class in the multiclass decision space. E.g. the assignment to the classes 0 and 2 ([1,0,1]) is converted to the class 5, which is one of the 2^3 classes in the multiclass decision space. This method is inverse to the multiclass_to_multilabel_assignments method.

Parameters

decision_tensornumpy.array of shape (n_classifiers, n_samples, n_classes). Tensor of crisp multilabel decision outputs by different classifiers per sample.

Returns

numpy.array of shape (n_classifiers, n_samples, 2^n_classes). Tensor of crisp multiclass decision outputs by different classifiers per sample.

pusion.util.transformer.multiclass_to_multilabel_assignments(decision_tensor)

Transform the multiclass decision tensor to the equivalent multilabel decision tensor using the inverse power set method. The multiclass assignment is considered as a decimal which is converted to a binary number, which in turn represents the multilabel class assignment. E.g. the class assignment to the class 3 ([0,0,0,1]) is converted to the multilabel class assignment [1,1] (classes 0 and 1 in the multilabel decision space). This method is inverse to the multilabel_to_multiclass_assignments method.

Parameters

decision_tensornumpy.array of shape (n_classifiers, n_samples, n_classes). Tensor of crisp multilabel decision outputs by different classifiers per sample.

Returns

numpy.array of shape (n_classifiers, n_samples, log_2(n_classes)). Tensor of crisp multiclass decision outputs by different classifiers per sample.

pusion.util.transformer.tensorize(decision_outputs)

Convert list decision outputs to numpy.array decision tensor, if possible.

pusion.util.transformer.intercept_normal_class(y, override=False)

Intercept the normal class for the given decision matrix, i.e. a normal class is assigned to each zero vector class assignment. E.g. the assignment [0,0,0,0] is transformed to [1,0,0,0], under the assumption that 0 is a normal class.

Parameters
  • ynumpy.array of shape (n_samples, n_classes). Matrix of decision outputs.

  • override – If true, the class 0 is assumed as a normal class. Otherwise a new class is prepended to existing classes.

Returns

numpy.array of shape (n_samples, n_classes) for override=False. numpy.array of shape (n_samples, n_classes + 1) for override=True. Matrix of decision outputs with intercepted normal class.

pusion.util.transformer.intercept_normal_class_in_tensor(decision_tensor, override=False)

Intercept the normal class for the given decision matrix, i.e. a normal class is assigned to each zero vector class assignment. E.g. the assignment [0,0,0,0] is transformed to [1,0,0,0], under the assumption that 0 is a normal class.

Parameters
  • decision_tensornumpy.array of shape (n_classifiers, n_samples, n_classes). Tensor of decision outputs by different classifiers per sample.

  • override – If true, the class 0 is assumed as a normal class. Otherwise a new class is prepended to existing classes.

Returns

numpy.array of shape (n_samples, n_classes) for override=False. numpy.array of shape (n_samples, n_classes + 1) for override=True. Matrix of decision outputs with intercepted normal class.