Example #1
0
 def test_max_error_stopping_criteria(self):
     Trainer = namedtuple('Trainer', ['epoch', 'train_errors'])
     errors_fail = [0.5, 0.4, 0.3, 0.2, 0.1]
     errors_pass = [0.1, 0.1, 0.1, 0.1, 0.05]
     stopping_function = ml.max_error(0.1, max_epoch=10)
     assert not stopping_function(Trainer(5, errors_fail))
     assert stopping_function(Trainer(5, errors_pass))
Example #2
0
def test_mlp_ann_train_xor_logic_function(xor_dataset):
    ann = ml.ForwardFeedNetwork((2, 2, 1))
    trainer = ann.train(xor_dataset, None, 0.2,
                        ml.max_error(0.005, max_epoch=20000))
    assert trainer.epoch <= 20000
    results = ann.forward_feed(xor_dataset[:, :2])
    assert results.shape == (4, 1)
    results = results.reshape(4)
    assert results[0] < 0.5
    assert results[1] > 0.5
    assert results[2] > 0.5
    assert results[3] < 0.5