MCPcopy Create free account
hub / github.com/PythonOT/POT / TFGW_template_initialization

Function TFGW_template_initialization

ot/gnn/_utils.py:18–62  ·  view source on GitHub ↗

Initializes templates for the Template Fused Gromov Wasserstein layer. Returns the adjacency matrices and the features of the nodes of the templates. Adjacency matrices are initialized uniformly with values in :math:`[0,1]`. Node features are initialized following a normal distribut

(
    n_tplt, n_tplt_nodes, n_features, feature_init_mean=0.0, feature_init_std=1.0
)

Source from the content-addressed store, hash-verified

16
17
18def TFGW_template_initialization(
19 n_tplt, n_tplt_nodes, n_features, feature_init_mean=0.0, feature_init_std=1.0
20):
21 """
22 Initializes templates for the Template Fused Gromov Wasserstein layer.
23 Returns the adjacency matrices and the features of the nodes of the templates.
24 Adjacency matrices are initialized uniformly with values in :math:`[0,1]`.
25 Node features are initialized following a normal distribution.
26
27 Parameters
28 ----------
29
30 n_tplt: int
31 Number of templates.
32 n_tplt_nodes: int
33 Number of nodes per template.
34 n_features: int
35 Number of features for the nodes.
36 feature_init_mean: float, optional
37 Mean of the random normal law to initialize the template features.
38 feature_init_std: float, optional
39 Standard deviation of the random normal law to initialize the template features.
40
41 Returns
42 ----------
43 tplt_adjacencies: torch.Tensor, shape (n_templates, n_template_nodes, n_template_nodes)
44 Adjacency matrices for the templates.
45 tplt_features: torch.Tensor, shape (n_templates, n_template_nodes, n_features)
46 Node features for each template.
47 q: torch.Tensor, shape (n_templates, n_template_nodes)
48 weight on the template nodes.
49 """
50
51 tplt_adjacencies = torch.rand((n_tplt, n_tplt_nodes, n_tplt_nodes))
52 tplt_features = torch.Tensor(n_tplt, n_tplt_nodes, n_features)
53
54 torch.nn.init.normal_(tplt_features, mean=feature_init_mean, std=feature_init_std)
55
56 q = torch.zeros(n_tplt, n_tplt_nodes)
57
58 tplt_adjacencies = 0.5 * (
59 tplt_adjacencies + torch.transpose(tplt_adjacencies, 1, 2)
60 )
61
62 return tplt_adjacencies, tplt_features, q
63
64
65def FGW_distance_to_templates(

Callers 2

__init__Method · 0.85
__init__Method · 0.85

Calls 3

randMethod · 0.45
zerosMethod · 0.45
transposeMethod · 0.45

Tested by

no test coverage detected