Skip to content

Softmax

Softmax ¤

Bases: Aggregate_Base

Aggregate function based on softmax.

This class should be passed to an ensemble function/class for combining predictions.

Source code in aucmedi/ensemble/aggregate/softmax.py
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
class Softmax(Aggregate_Base):
    """ Aggregate function based on softmax.

    This class should be passed to an ensemble function/class for combining predictions.
    """
    #---------------------------------------------#
    #                Initialization               #
    #---------------------------------------------#
    def __init__(self):
        # No hyperparameter adjustment required for this method, therefore skip
        pass

    #---------------------------------------------#
    #                  Aggregate                  #
    #---------------------------------------------#
    def aggregate(self, preds):
        # Sum up predictions
        preds_sum = np.sum(preds, axis=0)
        # Calculate softmax
        pred = compute_softmax(preds_sum)
        # Return prediction
        return pred

compute_softmax(x) ¤

Compute softmax values for each sets of scores in x.

Source code in aucmedi/ensemble/aggregate/softmax.py
56
57
58
59
def compute_softmax(x):
    """Compute softmax values for each sets of scores in x."""
    e_x = np.exp(x - np.max(x))
    return e_x / e_x.sum()