|
|
@@ -10,20 +10,36 @@ from decagon_pytorch.convolve import MultiDGCA |
|
|
|
import decagon_pytorch.convolve
|
|
|
|
|
|
|
|
|
|
|
|
def _make_symmetric(x: torch.Tensor):
|
|
|
|
x = (x + x.transpose(0, 1)) / 2
|
|
|
|
return x
|
|
|
|
|
|
|
|
|
|
|
|
def _symmetric_random(n_rows, n_columns):
|
|
|
|
return _make_symmetric(torch.rand((n_rows, n_columns),
|
|
|
|
dtype=torch.float32).round())
|
|
|
|
|
|
|
|
|
|
|
|
def _some_data_with_interactions():
|
|
|
|
d = Data()
|
|
|
|
d.add_node_type('Gene', 1000)
|
|
|
|
d.add_node_type('Drug', 100)
|
|
|
|
d.add_relation_type('Target', 1, 0,
|
|
|
|
|
|
|
|
fam = d.add_relation_family('Drug-Gene', 1, 0, True)
|
|
|
|
fam.add_relation_type('Target', 1, 0,
|
|
|
|
torch.rand((100, 1000), dtype=torch.float32).round())
|
|
|
|
d.add_relation_type('Interaction', 0, 0,
|
|
|
|
torch.rand((1000, 1000), dtype=torch.float32).round())
|
|
|
|
d.add_relation_type('Side Effect: Nausea', 1, 1,
|
|
|
|
torch.rand((100, 100), dtype=torch.float32).round())
|
|
|
|
d.add_relation_type('Side Effect: Infertility', 1, 1,
|
|
|
|
torch.rand((100, 100), dtype=torch.float32).round())
|
|
|
|
d.add_relation_type('Side Effect: Death', 1, 1,
|
|
|
|
torch.rand((100, 100), dtype=torch.float32).round())
|
|
|
|
|
|
|
|
fam = d.add_relation_family('Gene-Gene', 0, 0, True)
|
|
|
|
fam.add_relation_type('Interaction', 0, 0,
|
|
|
|
_symmetric_random(1000, 1000))
|
|
|
|
|
|
|
|
fam = d.add_relation_family('Drug-Drug', 1, 1, True)
|
|
|
|
fam.add_relation_type('Side Effect: Nausea', 1, 1,
|
|
|
|
_symmetric_random(100, 100))
|
|
|
|
fam.add_relation_type('Side Effect: Infertility', 1, 1,
|
|
|
|
_symmetric_random(100, 100))
|
|
|
|
fam.add_relation_type('Side Effect: Death', 1, 1,
|
|
|
|
_symmetric_random(100, 100))
|
|
|
|
return d
|
|
|
|
|
|
|
|
|
|
|
@@ -80,13 +96,14 @@ def test_decagon_layer_04(): |
|
|
|
|
|
|
|
d = Data()
|
|
|
|
d.add_node_type('Dummy', 100)
|
|
|
|
d.add_relation_type('Dummy Relation', 0, 0,
|
|
|
|
torch.rand((100, 100), dtype=torch.float32).round().to_sparse())
|
|
|
|
fam = d.add_relation_family('Dummy-Dummy', 0, 0, True)
|
|
|
|
fam.add_relation_type('Dummy Relation', 0, 0,
|
|
|
|
_symmetric_random(100, 100).to_sparse())
|
|
|
|
|
|
|
|
in_layer = OneHotInputLayer(d)
|
|
|
|
|
|
|
|
multi_dgca = MultiDGCA([10], 32,
|
|
|
|
[r.adjacency_matrix for r in d.relation_types[0, 0]],
|
|
|
|
[r.adjacency_matrix for r in fam.relation_types[0, 0]],
|
|
|
|
keep_prob=1., activation=lambda x: x)
|
|
|
|
|
|
|
|
d_layer = DecagonLayer(in_layer.output_dim, 32, d,
|
|
|
@@ -121,15 +138,16 @@ def test_decagon_layer_05(): |
|
|
|
|
|
|
|
d = Data()
|
|
|
|
d.add_node_type('Dummy', 100)
|
|
|
|
d.add_relation_type('Dummy Relation 1', 0, 0,
|
|
|
|
torch.rand((100, 100), dtype=torch.float32).round().to_sparse())
|
|
|
|
d.add_relation_type('Dummy Relation 2', 0, 0,
|
|
|
|
torch.rand((100, 100), dtype=torch.float32).round().to_sparse())
|
|
|
|
fam = d.add_relation_family('Dummy-Dummy', 0, 0, True)
|
|
|
|
fam.add_relation_type('Dummy Relation 1', 0, 0,
|
|
|
|
_symmetric_random(100, 100).to_sparse())
|
|
|
|
fam.add_relation_type('Dummy Relation 2', 0, 0,
|
|
|
|
_symmetric_random(100, 100).to_sparse())
|
|
|
|
|
|
|
|
in_layer = OneHotInputLayer(d)
|
|
|
|
|
|
|
|
multi_dgca = MultiDGCA([100, 100], 32,
|
|
|
|
[r.adjacency_matrix for r in d.relation_types[0, 0]],
|
|
|
|
[r.adjacency_matrix for r in fam.relation_types[0, 0]],
|
|
|
|
keep_prob=1., activation=lambda x: x)
|
|
|
|
|
|
|
|
d_layer = DecagonLayer(in_layer.output_dim, output_dim=32, data=d,
|
|
|
|