MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / aggregate

Method aggregate

monai/metrics/average_precision.py:68–83  ·  view source on GitHub ↗

Typically `y_pred` and `y` are stored in the cumulative buffers at each iteration, This function reads the buffers and computes the Average Precision. Args: average: {``"macro"``, ``"weighted"``, ``"micro"``, ``"none"``} Type of averaging perform

(self, average: Average | str | None = None)

Source from the content-addressed store, hash-verified

66 return y_pred, y
67
68 def aggregate(self, average: Average | str | None = None) -> np.ndarray | float | npt.ArrayLike:
69 """
70 Typically `y_pred` and `y` are stored in the cumulative buffers at each iteration,
71 This function reads the buffers and computes the Average Precision.
72
73 Args:
74 average: {``"macro"``, ``"weighted"``, ``"micro"``, ``"none"``}
75 Type of averaging performed if not binary classification. Defaults to `self.average`.
76
77 """
78 y_pred, y = self.get_buffer()
79 # compute final value and do metric reduction
80 if not isinstance(y_pred, torch.Tensor) or not isinstance(y, torch.Tensor):
81 raise ValueError("y_pred and y must be PyTorch Tensor.")
82
83 return compute_average_precision(y_pred=y_pred, y=y, average=average or self.average)
84
85
86def _calculate(y_pred: torch.Tensor, y: torch.Tensor) -> float:

Callers 1

test_class_valueMethod · 0.95

Calls 2

get_bufferMethod · 0.80

Tested by 1

test_class_valueMethod · 0.76