Exemple #1
0
def test_train_with_generated_data_then_predict(docknet1: Docknet):
    np.random.seed(1)
    data_generator = DummyDataGenerator()
    samples, labels = data_generator.generate_balanced_shuffled_sample(8)
    docknet1.train(samples, labels, batch_size=4, max_number_of_epochs=40)
    predicted_labels = docknet1.predict(samples)
    predicted_labels = np.round(predicted_labels)
    assert_array_almost_equal(predicted_labels, labels)
Exemple #2
0
def test_to_json(docknet1: Docknet):
    # Set network parameters as for the dummy initializer in order to enforce a specific expected output
    docknet1.initializer.initialize(docknet1.layers)
    expected_path = os.path.join(data_dir, 'docknet1.json')
    with open(expected_path, 'rt', encoding='UTF-8') as fp:
        expected = fp.read()
    actual_file = io.StringIO()
    docknet1.to_json(actual_file, True)
    actual = actual_file.getvalue()
    assert actual == expected
Exemple #3
0
def test_train(docknet1: Docknet):
    docknet1.train(X, Y, batch_size=2, max_number_of_epochs=1)
    expected_optimized_W1 = optimized_W1
    expected_optimized_b1 = optimized_b1
    expected_optimized_W2 = optimized_W2
    expected_optimized_b2 = optimized_b2
    actual_optimized_W1 = docknet1.layers[1].params['W']
    actual_optimized_b1 = docknet1.layers[1].params['b']
    actual_optimized_W2 = docknet1.layers[2].params['W']
    actual_optimized_b2 = docknet1.layers[2].params['b']
    assert_array_almost_equal(actual_optimized_W1, expected_optimized_W1)
    assert_array_almost_equal(actual_optimized_b1, expected_optimized_b1)
    assert_array_almost_equal(actual_optimized_W2, expected_optimized_W2)
    assert_array_almost_equal(actual_optimized_b2, expected_optimized_b2)
Exemple #4
0
def docknet2():
    docknet1 = Docknet()
    docknet1.add_input_layer(2)
    docknet1.add_dense_layer(3, 'relu')
    docknet1.add_dense_layer(1, 'sigmoid')
    docknet1.cost_function = 'cross_entropy'
    docknet1.initializer = DummyInitializer()
    docknet1.optimizer = AdamOptimizer()
    yield docknet1
Exemple #5
0
def test_predict(docknet1: Docknet):
    # Set network parameters as for the dummy initializer in order to enforce a specific expected output
    docknet1.initializer.initialize(docknet1.layers)
    expected = Y_circ
    actual = docknet1.predict(X)
    assert_array_almost_equal(actual, expected)
Exemple #6
0
def docknet1() -> Docknet:
    docknet1 = Docknet()
    docknet1.add_input_layer(2)
    docknet1.add_dense_layer(3, 'relu')
    docknet1.add_dense_layer(1, 'sigmoid')
    docknet1.cost_function = 'cross_entropy'
    docknet1.initializer = DummyInitializer()
    docknet1.optimizer = GradientDescentOptimizer()
    yield docknet1