Python torch_geometric.nn.MessagePassing() Examples

The following are 4 code examples of torch_geometric.nn.MessagePassing(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module torch_geometric.nn , or try the search function .
Example #1
Source File: gnn_explainer.py    From pytorch_geometric with MIT License 5 votes vote down vote up
def __set_masks__(self, x, edge_index, init="normal"):
        (N, F), E = x.size(), edge_index.size(1)

        std = 0.1
        self.node_feat_mask = torch.nn.Parameter(torch.randn(F) * 0.1)

        std = torch.nn.init.calculate_gain('relu') * sqrt(2.0 / (2 * N))
        self.edge_mask = torch.nn.Parameter(torch.randn(E) * std)

        for module in self.model.modules():
            if isinstance(module, MessagePassing):
                module.__explain__ = True
                module.__edge_mask__ = self.edge_mask 
Example #2
Source File: gnn_explainer.py    From pytorch_geometric with MIT License 5 votes vote down vote up
def __clear_masks__(self):
        for module in self.model.modules():
            if isinstance(module, MessagePassing):
                module.__explain__ = False
                module.__edge_mask__ = None
        self.node_feat_masks = None
        self.edge_mask = None 
Example #3
Source File: gnn_explainer.py    From pytorch_geometric with MIT License 5 votes vote down vote up
def __num_hops__(self):
        num_hops = 0
        for module in self.model.modules():
            if isinstance(module, MessagePassing):
                num_hops += 1
        return num_hops 
Example #4
Source File: gnn_explainer.py    From pytorch_geometric with MIT License 5 votes vote down vote up
def __flow__(self):
        for module in self.model.modules():
            if isinstance(module, MessagePassing):
                return module.flow
        return 'source_to_target'