Пример #1
0
def test_set_and_get_weights():
    input_dimensions = 4
    number_of_nodes = 9
    model = SingleLayerNN(input_dimensions=input_dimensions, number_of_nodes=number_of_nodes)
    weights=model.get_weights()
    assert weights.ndim == 2 and \
           weights.shape[0] == number_of_nodes and \
           weights.shape[1] == (input_dimensions + 1)
    model.set_weights(np.ones((number_of_nodes, input_dimensions + 1)))
    weights = model.get_weights()
    assert weights.ndim == 2 and \
           weights.shape[0] == number_of_nodes and \
           weights.shape[1] == (input_dimensions + 1)
    assert np.array_equal(model.get_weights(), np.ones((number_of_nodes, input_dimensions + 1)))
Пример #2
0
def test_weight_initialization():
    input_dimensions = 2
    number_of_nodes = 5
    model = SingleLayerNN(input_dimensions=2, number_of_nodes=number_of_nodes)
    model.initialize_weights(seed=1)
    assert model.weights.ndim == 2 and model.weights.shape[0] == number_of_nodes and model.weights.shape[
        1] == input_dimensions + 1
    weights = np.array([[1.62434536, -0.61175641, -0.52817175],
                        [-1.07296862, 0.86540763, -2.3015387],
                        [1.74481176, -0.7612069, 0.3190391],
                        [-0.24937038, 1.46210794, -2.06014071],
                        [-0.3224172, -0.38405435, 1.13376944]])
    np.testing.assert_allclose(model.get_weights(), weights, rtol=1e-3, atol=1e-3)