fl_server_ai.uncertainty.base ¶
Classes:
| Name | Description |
|---|---|
UncertaintyBase | Abstract base class for uncertainty estimation. |
Classes¶
UncertaintyBase ¶
Bases: ABC
flowchart TD
fl_server_ai.uncertainty.base.UncertaintyBase[UncertaintyBase]
click fl_server_ai.uncertainty.base.UncertaintyBase href "" "fl_server_ai.uncertainty.base.UncertaintyBase"
Abstract base class for uncertainty estimation.
This class defines the interface for uncertainty estimation in federated learning.
- API Reference
fl_server_aiuncertainty
- API Reference
fl_server_aiuncertainty
Methods:
| Name | Description |
|---|---|
expected_entropy | Calculate the mean entropy of the predictive distribution across the MC samples. |
get_options | Get uncertainty options from training options. |
interpret | Interpret the different network (model) outputs and calculate the uncertainty. |
mutual_information | Calculate the BALD (Bayesian Active Learning by Disagreement) of a model; |
prediction | Make a prediction using the given input and model. |
predictive_entropy | Calculate the entropy of the mean predictive distribution across the MC samples. |
to_json | Convert the given inference and uncertainty data to a JSON string. |
Source code in fl_server_ai/uncertainty/base.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | |
Functions¶
expected_entropy classmethod ¶
expected_entropy(predictions: Tensor) -> Tensor
Calculate the mean entropy of the predictive distribution across the MC samples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| Tensor | predictions of shape (n_mc x batch_size x n_classes) | required |
Returns:
| Type | Description |
|---|---|
Tensor | torch.Tensor: mean entropy of the predictive distribution |
Source code in fl_server_ai/uncertainty/base.py
get_options classmethod ¶
Get uncertainty options from training options.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| Model | Training | The Model or Training object to retrieve options for. | required |
Returns:
| Type | Description |
|---|---|
dict[str, Any] | Dict[str, Any]: Uncertainty options. |
Raises:
| Type | Description |
|---|---|
TypeError | If the given object is not a Model or Training. |
Source code in fl_server_ai/uncertainty/base.py
interpret classmethod ¶
Interpret the different network (model) outputs and calculate the uncertainty.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| Tensor | multiple network (model) outputs (N, batch_size, n_classes) | required |
Return
Tuple[torch.Tensor, Dict[str, Any]]: inference and uncertainty
Source code in fl_server_ai/uncertainty/base.py
mutual_information classmethod ¶
mutual_information(predictions: Tensor) -> Tensor
Calculate the BALD (Bayesian Active Learning by Disagreement) of a model; the difference between the mean of the entropy and the entropy of the mean of the predicted distribution on the predictions. This method is also sometimes referred to as the mutual information (MI).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| Tensor | predictions of shape (n_mc x batch_size x n_classes) | required |
Returns:
| Type | Description |
|---|---|
Tensor | torch.Tensor: difference between the mean of the entropy and the entropy of the mean of the predicted distribution |
Source code in fl_server_ai/uncertainty/base.py
prediction abstractmethod classmethod ¶
Make a prediction using the given input and model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| Tensor | The input to make a prediction for. | required |
| Model | The model to use for making the prediction. | required |
Returns:
| Type | Description |
|---|---|
tuple[Tensor, dict[str, Any]] | Tuple[torch.Tensor, Dict[str, Any]]: The prediction and any associated uncertainty. |
Source code in fl_server_ai/uncertainty/base.py
predictive_entropy classmethod ¶
predictive_entropy(predictions: Tensor) -> Tensor
Calculate the entropy of the mean predictive distribution across the MC samples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| Tensor | predictions of shape (n_mc x batch_size x n_classes) | required |
Returns:
| Type | Description |
|---|---|
Tensor | torch.Tensor: entropy of the mean predictive distribution |
Source code in fl_server_ai/uncertainty/base.py
to_json classmethod ¶
to_json(inference: Tensor, uncertainty: dict[str, Any] = {}, **json_kwargs) -> str
Convert the given inference and uncertainty data to a JSON string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
| Tensor | The inference to convert. | required |
| dict[str, Any] | The uncertainty to convert. | {} |
| Additional keyword arguments to pass to | {} |
Returns:
| Name | Type | Description |
|---|---|---|
str | str | A JSON string representation of the given inference and uncertainty data. |