|
@@ -5,7 +5,8 @@ from icosagon.trainprep import PreparedData, \ |
|
|
PreparedRelationFamily, \
|
|
|
PreparedRelationFamily, \
|
|
|
PreparedRelationType, \
|
|
|
PreparedRelationType, \
|
|
|
TrainValTest, \
|
|
|
TrainValTest, \
|
|
|
norm_adj_mat_one_node_type
|
|
|
|
|
|
|
|
|
norm_adj_mat_one_node_type, \
|
|
|
|
|
|
prepare_training
|
|
|
import torch
|
|
|
import torch
|
|
|
from icosagon.input import OneHotInputLayer
|
|
|
from icosagon.input import OneHotInputLayer
|
|
|
from icosagon.convlayer import DecagonLayer
|
|
|
from icosagon.convlayer import DecagonLayer
|
|
@@ -26,11 +27,12 @@ def test_model_01(): |
|
|
fam = d.add_relation_family('Dummy-Dummy', 0, 0, False)
|
|
|
fam = d.add_relation_family('Dummy-Dummy', 0, 0, False)
|
|
|
fam.add_relation_type('Dummy Rel', torch.rand(10, 10).round())
|
|
|
fam.add_relation_type('Dummy Rel', torch.rand(10, 10).round())
|
|
|
|
|
|
|
|
|
m = Model(d)
|
|
|
|
|
|
|
|
|
prep_d = prepare_training(d, TrainValTest(.8, .1, .1))
|
|
|
|
|
|
|
|
|
assert m.data == d
|
|
|
|
|
|
|
|
|
m = Model(prep_d)
|
|
|
|
|
|
|
|
|
|
|
|
assert m.prep_d == prep_d
|
|
|
assert m.layer_dimensions == [32, 64]
|
|
|
assert m.layer_dimensions == [32, 64]
|
|
|
assert (m.ratios.train, m.ratios.val, m.ratios.test) == (.8, .1, .1)
|
|
|
|
|
|
assert m.keep_prob == 1.
|
|
|
assert m.keep_prob == 1.
|
|
|
assert _is_identity_function(m.rel_activation)
|
|
|
assert _is_identity_function(m.rel_activation)
|
|
|
assert m.layer_activation == torch.nn.functional.relu
|
|
|
assert m.layer_activation == torch.nn.functional.relu
|
|
@@ -38,7 +40,6 @@ def test_model_01(): |
|
|
assert m.lr == 0.001
|
|
|
assert m.lr == 0.001
|
|
|
assert m.loss == torch.nn.functional.binary_cross_entropy_with_logits
|
|
|
assert m.loss == torch.nn.functional.binary_cross_entropy_with_logits
|
|
|
assert m.batch_size == 100
|
|
|
assert m.batch_size == 100
|
|
|
assert isinstance(m.prep_d, PreparedData)
|
|
|
|
|
|
assert isinstance(m.seq, torch.nn.Sequential)
|
|
|
assert isinstance(m.seq, torch.nn.Sequential)
|
|
|
assert isinstance(m.opt, torch.optim.Optimizer)
|
|
|
assert isinstance(m.opt, torch.optim.Optimizer)
|
|
|
|
|
|
|
|
@@ -50,7 +51,9 @@ def test_model_02(): |
|
|
mat = torch.rand(10, 10).round().to_sparse()
|
|
|
mat = torch.rand(10, 10).round().to_sparse()
|
|
|
fam.add_relation_type('Dummy Rel', mat)
|
|
|
fam.add_relation_type('Dummy Rel', mat)
|
|
|
|
|
|
|
|
|
m = Model(d, ratios=TrainValTest(1., 0., 0.))
|
|
|
|
|
|
|
|
|
prep_d = prepare_training(d, TrainValTest(1., 0., 0.))
|
|
|
|
|
|
|
|
|
|
|
|
m = Model(prep_d)
|
|
|
|
|
|
|
|
|
assert isinstance(m.prep_d, PreparedData)
|
|
|
assert isinstance(m.prep_d, PreparedData)
|
|
|
assert isinstance(m.prep_d.relation_families, list)
|
|
|
assert isinstance(m.prep_d.relation_families, list)
|
|
@@ -76,7 +79,9 @@ def test_model_03(): |
|
|
mat = torch.rand(10, 10).round().to_sparse()
|
|
|
mat = torch.rand(10, 10).round().to_sparse()
|
|
|
fam.add_relation_type('Dummy Rel', mat)
|
|
|
fam.add_relation_type('Dummy Rel', mat)
|
|
|
|
|
|
|
|
|
m = Model(d, ratios=TrainValTest(1., 0., 0.))
|
|
|
|
|
|
|
|
|
prep_d = prepare_training(d, TrainValTest(1., 0., 0.))
|
|
|
|
|
|
|
|
|
|
|
|
m = Model(prep_d)
|
|
|
|
|
|
|
|
|
state_dict = m.opt.state_dict()
|
|
|
state_dict = m.opt.state_dict()
|
|
|
assert isinstance(state_dict, dict)
|
|
|
assert isinstance(state_dict, dict)
|
|
@@ -97,7 +102,9 @@ def test_model_04(): |
|
|
fam.add_relation_type('Dummy Rel 1', mat)
|
|
|
fam.add_relation_type('Dummy Rel 1', mat)
|
|
|
fam.add_relation_type('Dummy Rel 2', mat.clone())
|
|
|
fam.add_relation_type('Dummy Rel 2', mat.clone())
|
|
|
|
|
|
|
|
|
m = Model(d, ratios=TrainValTest(1., 0., 0.))
|
|
|
|
|
|
|
|
|
prep_d = prepare_training(d, TrainValTest(1., 0., 0.))
|
|
|
|
|
|
|
|
|
|
|
|
m = Model(prep_d)
|
|
|
|
|
|
|
|
|
assert len(list(m.seq[0].parameters())) == 1
|
|
|
assert len(list(m.seq[0].parameters())) == 1
|
|
|
assert len(list(m.seq[1].parameters())) == 2
|
|
|
assert len(list(m.seq[1].parameters())) == 2
|
|
@@ -119,7 +126,9 @@ def test_model_05(): |
|
|
fam.add_relation_type('Dummy Rel 2-1', mat)
|
|
|
fam.add_relation_type('Dummy Rel 2-1', mat)
|
|
|
fam.add_relation_type('Dummy Rel 2-2', mat.clone())
|
|
|
fam.add_relation_type('Dummy Rel 2-2', mat.clone())
|
|
|
|
|
|
|
|
|
m = Model(d, ratios=TrainValTest(1., 0., 0.))
|
|
|
|
|
|
|
|
|
prep_d = prepare_training(d, TrainValTest(1., 0., 0.))
|
|
|
|
|
|
|
|
|
|
|
|
m = Model(prep_d)
|
|
|
|
|
|
|
|
|
assert len(list(m.seq[0].parameters())) == 1
|
|
|
assert len(list(m.seq[0].parameters())) == 1
|
|
|
assert len(list(m.seq[1].parameters())) == 4
|
|
|
assert len(list(m.seq[1].parameters())) == 4
|
|
@@ -127,7 +136,7 @@ def test_model_05(): |
|
|
assert len(list(m.seq[3].parameters())) == 6
|
|
|
assert len(list(m.seq[3].parameters())) == 6
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_model_05():
|
|
|
|
|
|
|
|
|
def test_model_06():
|
|
|
d = Data()
|
|
|
d = Data()
|
|
|
d.add_node_type('Dummy', 10)
|
|
|
d.add_node_type('Dummy', 10)
|
|
|
d.add_node_type('Foobar', 20)
|
|
|
d.add_node_type('Foobar', 20)
|
|
@@ -142,7 +151,9 @@ def test_model_05(): |
|
|
fam.add_relation_type('Dummy Rel 2-1', mat)
|
|
|
fam.add_relation_type('Dummy Rel 2-1', mat)
|
|
|
fam.add_relation_type('Dummy Rel 2-2', mat.clone())
|
|
|
fam.add_relation_type('Dummy Rel 2-2', mat.clone())
|
|
|
|
|
|
|
|
|
m = Model(d, ratios=TrainValTest(1., 0., 0.))
|
|
|
|
|
|
|
|
|
prep_d = prepare_training(d, TrainValTest(1., 0., 0.))
|
|
|
|
|
|
|
|
|
|
|
|
m = Model(prep_d)
|
|
|
|
|
|
|
|
|
assert len(list(m.seq[0].parameters())) == 2
|
|
|
assert len(list(m.seq[0].parameters())) == 2
|
|
|
assert len(list(m.seq[1].parameters())) == 6
|
|
|
assert len(list(m.seq[1].parameters())) == 6
|
|
@@ -150,49 +161,53 @@ def test_model_05(): |
|
|
assert len(list(m.seq[3].parameters())) == 6
|
|
|
assert len(list(m.seq[3].parameters())) == 6
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_model_06():
|
|
|
|
|
|
|
|
|
def test_model_07():
|
|
|
d = Data()
|
|
|
d = Data()
|
|
|
d.add_node_type('Dummy', 10)
|
|
|
d.add_node_type('Dummy', 10)
|
|
|
fam = d.add_relation_family('Dummy-Dummy', 0, 0, False)
|
|
|
fam = d.add_relation_family('Dummy-Dummy', 0, 0, False)
|
|
|
fam.add_relation_type('Dummy Rel', torch.rand(10, 10).round())
|
|
|
fam.add_relation_type('Dummy Rel', torch.rand(10, 10).round())
|
|
|
|
|
|
|
|
|
|
|
|
prep_d = prepare_training(d, TrainValTest(.8, .1, .1))
|
|
|
|
|
|
|
|
|
with pytest.raises(TypeError):
|
|
|
with pytest.raises(TypeError):
|
|
|
m = Model(1)
|
|
|
m = Model(1)
|
|
|
|
|
|
|
|
|
with pytest.raises(TypeError):
|
|
|
with pytest.raises(TypeError):
|
|
|
m = Model(d, layer_dimensions=1)
|
|
|
|
|
|
|
|
|
m = Model(prep_d, layer_dimensions=1)
|
|
|
|
|
|
|
|
|
with pytest.raises(TypeError):
|
|
|
with pytest.raises(TypeError):
|
|
|
m = Model(d, ratios=1)
|
|
|
|
|
|
|
|
|
m = Model(prep_d, ratios=1)
|
|
|
|
|
|
|
|
|
with pytest.raises(ValueError):
|
|
|
with pytest.raises(ValueError):
|
|
|
m = Model(d, keep_prob='x')
|
|
|
|
|
|
|
|
|
m = Model(prep_d, keep_prob='x')
|
|
|
|
|
|
|
|
|
with pytest.raises(TypeError):
|
|
|
with pytest.raises(TypeError):
|
|
|
m = Model(d, rel_activation='x')
|
|
|
|
|
|
|
|
|
m = Model(prep_d, rel_activation='x')
|
|
|
|
|
|
|
|
|
with pytest.raises(TypeError):
|
|
|
with pytest.raises(TypeError):
|
|
|
m = Model(d, layer_activation='x')
|
|
|
|
|
|
|
|
|
m = Model(prep_d, layer_activation='x')
|
|
|
|
|
|
|
|
|
with pytest.raises(TypeError):
|
|
|
with pytest.raises(TypeError):
|
|
|
m = Model(d, dec_activation='x')
|
|
|
|
|
|
|
|
|
m = Model(prep_d, dec_activation='x')
|
|
|
|
|
|
|
|
|
with pytest.raises(ValueError):
|
|
|
with pytest.raises(ValueError):
|
|
|
m = Model(d, lr='x')
|
|
|
|
|
|
|
|
|
m = Model(prep_d, lr='x')
|
|
|
|
|
|
|
|
|
with pytest.raises(TypeError):
|
|
|
with pytest.raises(TypeError):
|
|
|
m = Model(d, loss=1)
|
|
|
|
|
|
|
|
|
m = Model(prep_d, loss=1)
|
|
|
|
|
|
|
|
|
with pytest.raises(ValueError):
|
|
|
with pytest.raises(ValueError):
|
|
|
m = Model(d, batch_size='x')
|
|
|
|
|
|
|
|
|
m = Model(prep_d, batch_size='x')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_model_07():
|
|
|
|
|
|
|
|
|
def test_model_08():
|
|
|
d = Data()
|
|
|
d = Data()
|
|
|
d.add_node_type('Dummy', 10)
|
|
|
d.add_node_type('Dummy', 10)
|
|
|
fam = d.add_relation_family('Dummy-Dummy', 0, 0, False)
|
|
|
fam = d.add_relation_family('Dummy-Dummy', 0, 0, False)
|
|
|
fam.add_relation_type('Dummy Rel', torch.rand(10, 10).round())
|
|
|
fam.add_relation_type('Dummy Rel', torch.rand(10, 10).round())
|
|
|
|
|
|
|
|
|
m = Model(d)
|
|
|
|
|
|
|
|
|
prep_d = prepare_training(d, TrainValTest(.8, .1, .1))
|
|
|
|
|
|
|
|
|
|
|
|
m = Model(prep_d)
|
|
|
|
|
|
|
|
|
m.run_epoch()
|
|
|
m.run_epoch()
|