datagenerator.uncertainty_aware

Attributes

w

Classes

UncertaintyAwareDataset

A dataset designed to investigate how feature attribution methods treat inputs

Module Contents

class datagenerator.uncertainty_aware.UncertaintyAwareDataset(n_features: int = 5, weights: torch.Tensor | None = None, common_features: int = 1, seed: int = 0, n_samples: int = 10, **kwargs: Any)

Bases: xaiunits.datagenerator.BaseFeaturesDataset

A dataset designed to investigate how feature attribution methods treat inputs features that equally impact model prediction.

In particular, uncertainty/common features are input features that contribution equally to output class prediction. feature attribution method is expected not to assign any attribution score to these uncertainty inputs. The last columns of the dataset are uncertainty/common features.

Users can also pass in their own weights if they wish to test for more complex uncertainty behavior, e.g. uncertainty/common feature only contribution equally to a subset of output classes.

Inherits from:

BaseFeaturesDataset: Base class for generating datasets with features and labels.

weighted_samples

Samples multiplied by weights.

Type:

torch.Tensor

weights

Weights matrix for feature transformation.

Type:

torch.Tensor

labels

Softmax output of weighted samples.

Type:

torch.Tensor

Initializes an UncertaintyAwareDataset object.

Parameters:
  • n_features (int) – Number of features in the dataset. Defaults to 5.

  • weights (torch.Tensor, optional) – Custom weights matrix for feature transformation. Defaults to None.

  • common_features (int) – Number of uncertainty/common features present. Defaults to 1.

  • seed (int) – Seed for random number generation. Defaults to 0.

  • n_samples (int) – Number of samples in the dataset. Defaults to 10.

  • **kwargs – Additional keyword arguments for the base class constructor.

common_features = 1
weighted_samples
weights
labels
mask
features = 'samples'
ground_truth_attribute = 'mask'
subset_data = ['samples', 'weighted_samples', 'mask']
subset_attribute
_create_weights(n_features: int, weights: torch.Tensor | None, common_features: int) torch.Tensor

Creates weights matrix based on common features.

Parameters:
  • n_features (int) – Number of features in the dataset.

  • weights (torch.Tensor) – Custom weights matrix for feature transformation.

  • common_features (list) – List of indices representing common features.

Returns:

Weights matrix for feature transformation.

Return type:

weights (torch.Tensor)

__getitem__(idx: int, others: list[str] = ['ground_truth_attribute']) Tuple[Any, Ellipsis]

Retrieve a sample and its associated label by index.

Parameters:
  • idx (int) – Index of the sample to retrieve.

  • others (list) – Additional items to retrieve. Defaults to [“ground_truth_attribute”].

Returns:

Tuple containing the sample and its label.

Return type:

tuple

generate_model(softmax_layer: bool = True) torch.nn.Module

Generates an UncertaintyNN model based on the dataset.

Returns:

Instance of UncertaintyNN model.

Return type:

model.UncertaintyNN

property default_metric: Callable

The default metric for evaluating the performance of explanation methods applied to this dataset.

For this dataset, the default metric is modified Mean Squared Error (MSE) loss function. This metric measures the MSE for common/uncertainty features which should be 0.

Returns:

A class that wraps around the default metric to be instantiated

within the pipeline.

Return type:

type

datagenerator.uncertainty_aware.w = None