IF YOU WOULD LIKE TO GET AN ACCOUNT, please write an email to s dot adaszewski at gmail dot com. User accounts are meant only to report issues and/or generate pull requests. This is a purpose-specific Git hosting for ADARED projects. Thank you for your understanding!
Bläddra i källkod

Add test_parameter_count_01().

master
Stanislaw Adaszewski 4 år sedan
förälder
incheckning
03478e2667
3 ändrade filer med 58 tillägg och 0 borttagningar
  1. +33
    -0
      src/icosagon/convlayer.py
  2. +7
    -0
      src/icosagon/convolve.py
  3. +18
    -0
      tests/icosagon/test_convlayer.py

+ 33
- 0
src/icosagon/convlayer.py Visa fil

@@ -68,6 +68,33 @@ class DecagonLayer(torch.nn.Module):
self.next_layer_repr[fam.node_type_row].append(
Convolutions(fam.node_type_column, convolutions))
# def build_fam_two_node_types_sym(self, fam) -> None:
# convolutions_row = torch.nn.ModuleList()
# convolutions_column = torch.nn.ModuleList()
#
# if self.input_dim[fam.node_type_column] != \
# self.input_dim[fam.node_type_row]:
# raise ValueError('input_dim for row and column must be equal for a symmetric family')
#
# if self.output_dim[fam.node_type_column] != \
# self.output_dim[fam.node_type_row]:
# raise ValueError('output_dim for row and column must be equal for a symmetric family')
#
# for r in fam.relation_types:
# assert r.adjacency_matrix is not None and \
# r.adjacency_matrix_backward is not None
# conv = DropoutGraphConvActivation(self.input_dim[fam.node_type_column],
# self.output_dim[fam.node_type_row], r.adjacency_matrix,
# self.keep_prob, self.rel_activation)
# convolutions_row.append(conv)
# convolutions_column.append(conv.clone(r.adjacency_matrix_backward))
#
# self.next_layer_repr[fam.node_type_row].append(
# Convolutions(fam.node_type_column, convolutions_row))
#
# self.next_layer_repr[fam.node_type_column].append(
# Convolutions(fam.node_type_row, convolutions_column))
def build_fam_two_node_types(self, fam) -> None:
convolutions_row = torch.nn.ModuleList()
convolutions_column = torch.nn.ModuleList()
@@ -91,6 +118,12 @@ class DecagonLayer(torch.nn.Module):
self.next_layer_repr[fam.node_type_column].append(
Convolutions(fam.node_type_row, convolutions_column))
# def build_fam_two_node_types(self, fam) -> None:
# if fam.is_symmetric:
# self.build_fam_two_node_types_sym(fam)
# else:
# self.build_fam_two_node_types_asym(fam)
def build_family(self, fam) -> None:
if fam.node_type_row == fam.node_type_column:
self.build_fam_one_node_type(fam)


+ 7
- 0
src/icosagon/convolve.py Visa fil

@@ -48,3 +48,10 @@ class DropoutGraphConvActivation(torch.nn.Module):
x = self.graph_conv(x)
x = self.activation(x)
return x
def clone(self, adjacency_matrix) -> 'DropoutGraphConvActivation':
res = DropoutGraphConvActivation(self.input_dim,
self.output_dim, adjacency_matrix, self.keep_prob,
self.activation)
res.graph_conv.weight = self.graph_conv.weight
return res

+ 18
- 0
tests/icosagon/test_convlayer.py Visa fil

@@ -280,3 +280,21 @@ def test_module_nesting_06():
dummy_7 = Dummy7()
dummy_7 = dummy_7.to(device)
assert dummy_7.dummy_1[0][0].whatever.device == device
def test_parameter_count_01():
d = Data()
d.add_node_type('Dummy', 100)
fam = d.add_relation_family('Dummy-Dummy', 0, 0, True)
fam.add_relation_type('Dummy Relation 1',
_symmetric_random(100, 100).to_sparse())
fam.add_relation_type('Dummy Relation 2',
_symmetric_random(100, 100).to_sparse())
in_layer = OneHotInputLayer(d)
assert len(list(in_layer.parameters())) == 1
d_layer = DecagonLayer(in_layer.output_dim, output_dim=32, data=d,
keep_prob=1., rel_activation=lambda x: x,
layer_activation=lambda x: x)
assert len(list(d_layer.parameters())) == 2

Laddar…
Avbryt
Spara