- class Explain(model: torch.nn.Module, adj_matrix: numpy.typing.NDArray, features: numpy.typing.NDArray)
Bases:
object
An explainer class for instance-level explanations of Graph Neural Networks. Explanation is Probabilistic Graphical Model in a form of Bayesian network. This Bayesian network estimates the probability that node has the predicted role given a realization of other nodes.
How to build explanation:
explainer = Explain(model=model, A=A, X=X) pgm_explanation = explainer.structure_learning(28)
- Parameters:
model – (Module): The model to explain.
adj_matrix – (NDArray): Adjacency matrix of input data.
features – (NDArray): Feature matrix of input data.
- pgm_conditional_prob(target: int, pgm_explanation: pgmpy.models.BayesianNetwork, evidence_list: List[str]) float | None
Probability of target node, conditioned on the set of neighbours
- Parameters:
target – (int) Index of node explained
pgm_explanation – (Bayesian Net) The Bayesian Net explaining the target
evidence_list – ([str]]) List of neighbours to condition on
- Returns:
(float): The probability of the target node conditioned on ‘evidence_list’
- structure_learning(target: int | None = None, top_node: int | None = None, num_samples: int = 20, pred_threshold: float = 0.1, child: bool | None = None) pgmpy.models.BayesianNetwork
Learn structure of Bayesian Net, which represents pgm explanation of target node.
- Parameters:
target – (str): Index of the node to be explained
top_node – (int, optional): The number of top the most probable nodes for Bayesian Net. If None, all nodes would be used (default: ‘None’)
num_samples – (int): The number of samples for data generation, which is used for structure learning, more number of samples – better learning.
pred_threshold – (float): Probability that the features in each node is perturbed (default: 0.1)
child – (bool, Optional): If False or None, no-child constraint is applied (default: None)
- Returns:
(BayesianNetwork): Pgm explanation in Bayesian Net form