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-.

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
  • model (torch.nn.Module) – The target model prepared to explain.

  • device (torch.device) – Specify running device: CPU or CUDA.

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.

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

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

  • 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.