Skip to content

Agg base

Aggregate_Base ¤

Bases: ABC

An abstract base class for an Aggregation class.

Assembled predictions encoded in a NumPy matrix with shape (N_models, N_classes).
Example: [[0.5, 0.4, 0.1],
          [0.4, 0.3, 0.3],
          [0.5, 0.2, 0.3]]
-> shape (3, 3)

Merged prediction encoded in a NumPy matrix with shape (1, N_classes).
Example: [[0.4, 0.3, 0.3]]
-> shape (1, 3)
Create a custom Aggregation class
from aucmedi.ensemble.aggregate.agg_base import Aggregate_Base

class My_custom_Aggregate(Aggregate_Base):
    def __init__(self):                 # you can pass class variables here
        pass

    def aggregate(self, preds):
        preds_combined = np.mean(preds, axis=0)     # do some combination operation
        return preds_combined                       # return combined predictions

Required Functions

Function Description
__init__() Object creation function.
aggregate() Merge multiple class predictions into a single prediction.
Source code in aucmedi/ensemble/aggregate/agg_base.py
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
class Aggregate_Base(ABC):
    """ An abstract base class for an Aggregation class.

    ```
    Assembled predictions encoded in a NumPy matrix with shape (N_models, N_classes).
    Example: [[0.5, 0.4, 0.1],
              [0.4, 0.3, 0.3],
              [0.5, 0.2, 0.3]]
    -> shape (3, 3)

    Merged prediction encoded in a NumPy matrix with shape (1, N_classes).
    Example: [[0.4, 0.3, 0.3]]
    -> shape (1, 3)
    ```

    ???+ example "Create a custom Aggregation class"
        ```python
        from aucmedi.ensemble.aggregate.agg_base import Aggregate_Base

        class My_custom_Aggregate(Aggregate_Base):
            def __init__(self):                 # you can pass class variables here
                pass

            def aggregate(self, preds):
                preds_combined = np.mean(preds, axis=0)     # do some combination operation
                return preds_combined                       # return combined predictions
        ```

    !!! info "Required Functions"
        | Function            | Description                                                |
        | ------------------- | ---------------------------------------------------------- |
        | `__init__()`        | Object creation function.                                  |
        | `aggregate()`       | Merge multiple class predictions into a single prediction. |
    """
    #---------------------------------------------#
    #                Initialization               #
    #---------------------------------------------#
    @abstractmethod
    def __init__(self):
        """ Initialization function which will be called during the Aggregation object creation.

        This function can be used to pass variables and options in the Aggregation instance.
        There are no mandatory parameters for the initialization.
        """
        pass
    #---------------------------------------------#
    #                  Aggregate                  #
    #---------------------------------------------#
    @abstractmethod
    def aggregate(self, preds):
        """ Aggregate the image by merging multiple predictions into a single one.

        It is required to return the merged predictions (as NumPy matrix).
        It is possible to pass configurations through the initialization function for this class.

        Args:
            preds (numpy.ndarray):      Assembled predictions encoded in a NumPy matrix with shape (N_models, N_classes).
        Returns:
            pred (numpy.ndarray):       Merged prediction encoded in a NumPy matrix with shape (1, N_classes).
        """
        return pred

__init__() abstractmethod ¤

Initialization function which will be called during the Aggregation object creation.

This function can be used to pass variables and options in the Aggregation instance. There are no mandatory parameters for the initialization.

Source code in aucmedi/ensemble/aggregate/agg_base.py
65
66
67
68
69
70
71
72
@abstractmethod
def __init__(self):
    """ Initialization function which will be called during the Aggregation object creation.

    This function can be used to pass variables and options in the Aggregation instance.
    There are no mandatory parameters for the initialization.
    """
    pass

aggregate(preds) abstractmethod ¤

Aggregate the image by merging multiple predictions into a single one.

It is required to return the merged predictions (as NumPy matrix). It is possible to pass configurations through the initialization function for this class.

Parameters:

Name Type Description Default
preds numpy.ndarray

Assembled predictions encoded in a NumPy matrix with shape (N_models, N_classes).

required

Returns:

Name Type Description
pred numpy.ndarray

Merged prediction encoded in a NumPy matrix with shape (1, N_classes).

Source code in aucmedi/ensemble/aggregate/agg_base.py
76
77
78
79
80
81
82
83
84
85
86
87
88
@abstractmethod
def aggregate(self, preds):
    """ Aggregate the image by merging multiple predictions into a single one.

    It is required to return the merged predictions (as NumPy matrix).
    It is possible to pass configurations through the initialization function for this class.

    Args:
        preds (numpy.ndarray):      Assembled predictions encoded in a NumPy matrix with shape (N_models, N_classes).
    Returns:
        pred (numpy.ndarray):       Merged prediction encoded in a NumPy matrix with shape (1, N_classes).
    """
    return pred