Skip to content

Commit d1580ab

Browse files
committed
fix
1 parent 5413b26 commit d1580ab

File tree

36 files changed

+105
-176
lines changed

36 files changed

+105
-176
lines changed

graphgallery/data/_util.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
"""
2+
Unused
3+
"""
14
import functools
25
import operator
36
import sys
@@ -116,7 +119,7 @@ def _aligned_zeros(shape, dtype=float, order="C", align=None):
116119
offset = align - offset
117120
# Note: slices producing 0-size arrays do not necessarily change
118121
# data pointer --- so we use and allocate size+1
119-
buf = buf[offset:offset+size+1][:-1]
122+
buf = buf[offset:offset + size + 1][:-1]
120123
data = np.ndarray(shape, dtype, buf, order=order)
121124
data.fill(0)
122125
return data

graphgallery/data/utils.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
""" Utility functions for sparse matrix module
2+
3+
Unused
24
"""
35

46
import sys
@@ -296,13 +298,15 @@ def check_shape(args, current_shape=None):
296298
.format(current_size, new_shape))
297299
elif len(negative_indexes) == 1:
298300
skip = negative_indexes[0]
299-
specified = prod(new_shape[0:skip] + new_shape[skip+1:])
301+
specified = prod(new_shape[0:skip] + new_shape[skip + 1:])
300302
unspecified, remainder = divmod(current_size, specified)
301303
if remainder != 0:
302-
err_shape = tuple('newshape' if x < 0 else x for x in new_shape)
304+
err_shape = tuple('newshape' if x <
305+
0 else x for x in new_shape)
303306
raise ValueError('cannot reshape array of size {} into shape {}'
304307
''.format(current_size, err_shape))
305-
new_shape = new_shape[0:skip] + (unspecified,) + new_shape[skip+1:]
308+
new_shape = new_shape[0:skip] + \
309+
(unspecified,) + new_shape[skip + 1:]
306310
else:
307311
raise ValueError('can only specify one unknown dimension')
308312

graphgallery/nn/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
from graphgallery.nn.layers import *
22
from graphgallery.nn.models import *
3-
from graphgallery.nn.functions import *
3+
from graphgallery.nn.functions import *
4+
from graphgallery.nn.init import *

graphgallery/nn/layers/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,3 @@
2323

2424
else:
2525
from graphgallery.nn.layers.torch_layers.gcn import GraphConvolution
26-

graphgallery/nn/layers/tf_layers/misc.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,19 @@ def get_config(self):
111111

112112

113113
class Laplacian(Layer):
114-
def __init__(self, rate=-0.5, selfloop=1.0, *args, **kwargs):
114+
def __init__(self, rate=-0.5, fill_weight=1.0, *args, **kwargs):
115115
super().__init__(*args, **kwargs)
116116
if not rate:
117117
raise ValueError(
118118
f"`rate` must be an integer scalr larger than zero, but got {rate}.")
119119
self.rate = rate
120-
self.selfloop = selfloop
120+
self.fill_weight = fill_weight
121121
self.trainable = False
122122

123123
def call(self, adj):
124-
adj = adj + self.selfloop * tf.eye(tf.shape(adj)[0], dtype=adj.dtype)
124+
if self.fill_weight:
125+
adj = adj + self.fill_weight * \
126+
tf.eye(tf.shape(adj)[0], dtype=adj.dtype)
125127
d = tf.reduce_sum(adj, axis=1)
126128
d_power = tf.pow(d, self.rate)
127129
d_power_mat = tf.linalg.diag(d_power)

graphgallery/nn/layers/tf_layers/normalize.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def call(self, inputs, improved=False):
2222
edge_weight = tf.ones([edge_index.shape[0]], dtype=floatx())
2323

2424
fill_weight = 2.0 if improved else 1.0
25-
edge_index, edge_weight = self.add_selfloop_edge(
25+
edge_index, edge_weight = self.add_selfloops_edge(
2626
edge_index, n_nodes, edge_weight=edge_weight, fill_weight=fill_weight)
2727

2828
row = tf.gather(edge_index, 0, axis=1)
@@ -41,7 +41,7 @@ def call(self, inputs, improved=False):
4141
return edge_index, noremd_edge_weight
4242

4343
@staticmethod
44-
def add_selfloop_edge(edge_index, n_nodes, edge_weight=None, fill_weight=1.0):
44+
def add_selfloops_edge(edge_index, n_nodes, edge_weight=None, fill_weight=1.0):
4545
diagnal_edge_index = tf.reshape(
4646
tf.repeat(tf.range(n_nodes, dtype=intx()), 2), [n_nodes, 2])
4747

Lines changed: 16 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,40 @@
1-
import numpy as np
21
import torch
2+
import math
3+
import numpy as np
34
from torch.nn.parameter import Parameter
45
from torch.nn import Module
6+
from graphgallery.nn.init import kaiming_uniform, zeros
57

8+
# TODO: change dtypes of trainable weights based on `floax`
69
class GraphConvolution(Module):
7-
def __init__(self, input_channels, output_channels, use_bias=False):
10+
def __init__(self, in_channels, out_channels, use_bias=False):
811
super().__init__()
9-
self.input_channels = input_channels
10-
self.output_channels = output_channels
11-
self.kernel = Parameter(torch.FloatTensor(input_channels, output_channels))
12-
12+
self.in_channels = in_channels
13+
self.out_channels = out_channels
14+
self.kernel = Parameter(torch.Tensor(in_channels, out_channels))
15+
1316
if use_bias:
14-
self.bias = Parameter(torch.FloatTensor(output_channels))
17+
self.bias = Parameter(torch.Tensor(out_channels))
1518
else:
1619
self.register_parameter('bias', None)
17-
20+
1821
self.reset_parameters()
1922

2023
def reset_parameters(self):
21-
stdv = 1. / np.sqrt(self.kernel.size(1))
22-
self.kernel.data.uniform_(-stdv, stdv)
23-
if self.bias is not None:
24-
self.bias.data.uniform_(-stdv, stdv)
24+
kaiming_uniform(self.kernel, a=math.sqrt(5))
25+
zeros(self.bias)
2526

2627
def forward(self, inputs):
2728
x, adj = inputs
2829
h = torch.spmm(x, self.kernel)
2930
output = torch.spmm(adj, h)
30-
31+
3132
if self.bias is not None:
3233
return output + self.bias
3334
else:
3435
return output
3536

3637
def __repr__(self):
3738
return self.__class__.__name__ + ' (' \
38-
+ str(self.input_channels) + ' -> ' \
39-
+ str(self.output_channels) + ')'
40-
41-
42-
class ListModule(Module):
43-
"""
44-
Abstract list layer class.
45-
"""
46-
def __init__(self, *args):
47-
"""
48-
Module initializing.
49-
"""
50-
super().__init__()
51-
idx = 0
52-
for module in args:
53-
self.add_module(str(idx), module)
54-
idx += 1
55-
56-
def __getitem__(self, idx):
57-
"""
58-
Getting the indexed layer.
59-
"""
60-
if idx < 0 or idx >= len(self._modules):
61-
raise IndexError('index {} is out of range'.format(idx))
62-
it = iter(self._modules.values())
63-
for i in range(idx):
64-
next(it)
65-
return next(it)
66-
67-
def __iter__(self):
68-
"""
69-
Iterating on the layers.
70-
"""
71-
return iter(self._modules.values())
72-
73-
def __len__(self):
74-
"""
75-
Number of layers.
76-
"""
77-
return len(self._modules)
39+
+ str(self.in_channels) + ' -> ' \
40+
+ str(self.out_channels) + ')'

graphgallery/nn/layers/torch_layers/inits.py

Lines changed: 0 additions & 61 deletions
This file was deleted.

graphgallery/nn/models/get_activation.py

100644100755
File mode changed.

graphgallery/nn/models/semisupervised/experimental/edgeconv.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def process_step(self):
8585
self.feature_inputs, self.structure_inputs = T.astensors(
8686
attr_matrix, (edge_index, edge_weight))
8787

88+
# use decorator to make sure all list arguments have the same length
8889
@EqualVarLength()
8990
def build(self, hiddens=[16], activations=['relu'], dropouts=[0.5],
9091
l2_norms=[5e-4], lr=0.01, use_bias=False):

0 commit comments

Comments
 (0)