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

Method _normalize_probabilities

monai/transforms/compose.py:748–766  ·  view source on GitHub ↗
(self, weights)

Source from the content-addressed store, hash-verified

746
747 # Modified from OneOf
748 def _normalize_probabilities(self, weights):
749 if weights is None or len(self.transforms) == 0:
750 return None
751
752 weights = np.array(weights)
753
754 n_weights = len(weights)
755 if n_weights != len(self.transforms):
756 raise ValueError(f"Expected len(weights)={len(self.transforms)}, got: {n_weights}.")
757
758 if np.any(weights < 0):
759 raise ValueError(f"Probabilities must be greater than or equal to zero, got {weights}.")
760
761 if np.all(weights == 0):
762 raise ValueError(f"At least one probability must be greater than zero, got {weights}.")
763
764 weights = weights / weights.sum()
765
766 return ensure_tuple(list(weights))
767
768 def __call__(self, data, start=0, end=None, threading=False, lazy: bool | None = None):
769 if start != 0:

Callers 1

__init__Method · 0.95

Calls 2

ensure_tupleFunction · 0.90
arrayMethod · 0.80

Tested by

no test coverage detected