dig.xgraph.evaluation

Evaluation interfaces under dig.xgraph.evaluation.

ExplanationProcessor

Explanation Processor is edge mask explanation processor which can handle sparsity control and use data collector automatically.

XCollector

XCollector is a data collector which takes processed related prediction probabilities to calculate Fidelity+ and Fidelity-.

control_sparsity

Transform the mask where top 1 - sparsity values are set to inf.

class ExplanationProcessor(model: torch.nn.modules.module.Module, device: torch.device)[source]

Explanation Processor is edge mask explanation processor which can handle sparsity control and use data collector automatically.

Parameters
forward(data: torch_geometric.data.data.Data, masks: List[torch.Tensor], x_collector: dig.xgraph.evaluation.metrics.XCollector, **kwargs)[source]

Please refer to the main function in metric.py.

class XCollector(sparsity=None)[source]

XCollector is a data collector which takes processed related prediction probabilities to calculate Fidelity+ and Fidelity-.

Parameters

sparsity (float) – The Sparsity is use to transform the soft mask to a hard one.

Note

For more examples, see benchmarks/xgraph.

property accuracy

Return the accuracy for datasets with motif ground-truth

collect_data(masks: List[torch.Tensor], related_preds: dir, label: int = 0) None[source]

The function is used to collect related data. After collection, we can call fidelity, fidelity_inv, sparsity to calculate their values.

Parameters
  • masks (list) – It is a list of edge-level explanation for each class.

  • related_preds (list) – It is a list of dictionary for each class where each dictionary

  • sparsity. (includes 4 type predicted probabilities and) –

  • label (int) – The ground truth label. (default: 0)

property fidelity

Return the Fidelity+ value according to collected data.

property fidelity_inv

Return the Fidelity- value according to collected data.

new()[source]

Clear class members.

property sparsity

Return the Sparsity value.

property stability

Return the accuracy for datasets with motif ground-truth

control_sparsity(mask: torch.Tensor, sparsity: Optional[float] = None)[source]

Transform the mask where top 1 - sparsity values are set to inf. :param mask: Mask that need to transform. :type mask: torch.Tensor :param sparsity: Sparsity we need to control i.e. 0.7, 0.5 (Default: None). :type sparsity: float

Return type

torch.Tensor