CollaborativeCoding.metrics.precision ===================================== .. py:module:: CollaborativeCoding.metrics.precision Classes ------- .. autoapisummary:: CollaborativeCoding.metrics.precision.Precision Module Contents --------------- .. py:class:: Precision(num_classes: int, macro_averaging: bool = False) Bases: :py:obj:`torch.nn.Module` Metric module for precision. Can calculate both the micro- and macro-averaged precision. Parameters ---------- num_classes : int Number of classes in the dataset. macro_averaging : bool Performs macro-averaging if True, otherwise micro-averaging. .. py:attribute:: num_classes .. py:attribute:: macro_averaging :value: False .. py:attribute:: y_true :value: [] .. py:attribute:: y_pred :value: [] .. py:method:: forward(y_true: torch.tensor, logits: torch.tensor) -> torch.tensor Add true and predicted values to the class-global lists. Parameters ---------- y_true : torch.tensor True labels logits : torch.tensor Predicted labels .. py:method:: _micro_avg_precision(y_true: torch.tensor, y_pred: torch.tensor) -> torch.tensor Compute micro-average precision by first calculating true/false positive across all classes and then find the precision. Parameters ---------- y_true : torch.tensor True labels y_pred : torch.tensor Predicted labels Returns ------- torch.tensor Micro-averaged precision .. py:method:: _macro_avg_precision(y_true: torch.tensor, y_pred: torch.tensor) -> torch.tensor Compute macro-average precision by finding true/false positives of each class separately then averaging across all classes. Parameters ---------- y_true : torch.tensor True labels y_pred : torch.tensor Predicted labels Returns ------- torch.tensor Macro-averaged precision .. py:method:: __returnmetric__() Return the micro- or macro-averaged precision. Returns ------- torch.tensor Micro- or macro-averaged precision .. py:method:: __reset__() Resets the class-global lists of true and predicted values to empty lists. Returns ------- None Returns None