Utilities Module

Data Creator

bias_amplification.utils.datacreator.dataCreator(N=512, error_percent=0.1, shuffle=False, data_error_percent=None)[source]

This function generates a synthetic dataset for the bias amplification analysis. It creates a dataset with protected attributes, ground truth task label, biased task data label, model prediction without bias, and model prediction with bias.

Parameters:
N: int, default=512

The size of the dataset, must be >= 3.

error_percent: float, default=0.1

The error percentage of the model, must be between 0 and 0.25.

shuffle: boolean, default=False

Whether to shuffle the data.

data_error_percent: float, default=None

The error percentage of the data, must be between 0 and 0.25.

Returns:
P: numpy.ndarray, shape (N,)

The protected attributes.

D: numpy.ndarray, shape (N,)

The ground truth task labels.

D_bias: numpy.ndarray, shape (N,)

The biased task data labels.

M_unbias: numpy.ndarray, shape (N,)

The model predictions without bias.

M2: numpy.ndarray, shape (N,)

The model predictions with bias.

Examples

>>> from bias_amplification.utils.datacreator import dataCreator
>>> P, D, D_bias, M_unbias, M2 = dataCreator(
         N=1000, error_percent=0.1, shuffle=False, data_error_percent=0.05)
bias_amplification.utils.datacreator.validate_error_percent(error_percent, name)[source]

Checks if the error percentage is valid. It raises an error, otherwise.

Parameters:

error_percent: float

The error percentage to validate

name: str

The name of the error percentage to validate

Configuration

bias_amplification.utils.config.normalise(value: float | int | Tensor) float | int | Tensor[source]

This function normalises a value to be between 0 and 1.

Parameters:
value: float, int, or torch.Tensor

The value to normalise.

Returns:
value: float, int, or torch.Tensor

The normalised value.

Loss Functions

bias_amplification.utils.losses.ModifiedBCELoss(y_pred, y_true)[source]

This function computes the modified version of the BCE loss. The modified version of cross-entropy loss gives high values for better performance.

Parameters:
y_pred: torch.Tensor

The predicted values.

y_true: torch.Tensor

The true values.

Returns:
loss: torch.Tensor

The modified BCE loss.

bias_amplification.utils.losses.ModifiedMSELoss(y_pred, y_true)[source]

This function computes the modified version of the MSE loss. The modified version of MSE loss gives high values for better performance.

Parameters:
y_pred: torch.Tensor

The predicted values.

y_true: torch.Tensor

The true values.

Returns:
loss: torch.Tensor

The modified MSE loss.