dig.xgraph.evaluation¶
Evaluation interfaces under dig.xgraph.evaluation
.
Explanation Processor is edge mask explanation processor which can handle sparsity control and use data collector automatically. |
|
XCollector is a data collector which takes processed related prediction probabilities to calculate Fidelity+ and Fidelity-. |
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
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.
- 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.
- property fidelity¶
Return the Fidelity+ value according to collected data.
Note
Please refer to Explainability in Graph Neural Networks: A Taxonomic Survey for details.
- property fidelity_inv¶
Return the Fidelity- value according to collected data.
Note
Please refer to Explainability in Graph Neural Networks: A Taxonomic Survey for details.
- 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