attribench.result.InfidelityResult
- class attribench.result.InfidelityResult(method_names, perturbation_generators, activation_fns, num_samples)[source]
Bases:
GroupedMetricResultRepresents results from running the Infidelity metric.
- Parameters:
- method_namesList[str]
Names of attribution methods tested by Infidelity.
- perturbation_generatorsList[str]
Names of perturbation generators used by Infidelity.
- activation_fnsList[str]
Names of activation functions used by Infidelity.
- num_samplesint
Number of samples on which Infidelity was run.
Methods
Add a batch to the result (abstract method).
Retrieves a dataframe from the result for the given perturbation generator and activation function.
Load a result from an HDF5 file or a directory of CSV files.
Save the result to an HDF5 file or a nested directory of CSV files.
- abstract add(batch_result)
Add a batch to the result (abstract method).
- get_df(perturbation_generator, activation_fn, methods=None)[source]
Retrieves a dataframe from the result for the given perturbation generator and activation function. The dataframe contains a row for each method and a column for each sample. Each value is the Infidelity for the given method on the given sample.
- Parameters:
- perturbation_generatorstr
The perturbation generator to use.
- activation_fnstr
The activation function to use.
- methodsOptional[List[str]], optional
The methods to include. If None, includes all methods. Defaults to None.
- Returns:
- Tuple[pd.DataFrame, bool]
Dataframe containing results, and boolean indicating if higher is better.
- Return type:
Tuple[DataFrame,bool]
- classmethod load(path)
Load a result from an HDF5 file or a directory of CSV files. The format is inferred from the path: if the path is a directory, the result is loaded from a directory of CSV files, otherwise the result is loaded from an HDF5 file.
The specific subclass of MetricResult is inferred from the metadata stored in the file or directory, and the appropriate load method is called.
- Parameters:
- pathstr
Path to the file or directory.
- Returns:
- MetricResult
The loaded result.
- Return type:
- save(path, format)
Save the result to an HDF5 file or a nested directory of CSV files.
- Parameters:
- pathstr
Path to the file.
- formatstr
Format to save the result in. Options: hdf5, dir. If hdf5, the full result is stored in a single HDF5 file. If csv, the result is stored in a nested directory of CSV files.
- Return type:
None