Пример #1
0
def test_validation_split_5D():
    """Test the validation split with high dimensional data (5D)"""
    x0 = np.random.uniform(0, 1, (50, 4, 4, 4, 2))
    y0 = np.random.uniform(0, 1, (50, 4, 1, 1, 1))
    p0 = x0.copy()
    out = PhysicsGuidedNeuralNetwork.get_val_split(x0,
                                                   y0,
                                                   p0,
                                                   shuffle=False,
                                                   validation_split=0.3)
    x, y, p, x_val, y_val, p_val = out
    assert len(x0.shape) == 5
    assert len(y0.shape) == 5
    assert len(p0.shape) == 5
    assert len(x.shape) == 5
    assert len(y.shape) == 5
    assert len(p.shape) == 5
    assert len(x_val.shape) == 5
    assert len(y_val.shape) == 5
    assert len(p_val.shape) == 5
    assert (x_val == p_val).all()
    assert (x == p).all()
    assert (x == x0[-len(x):]).all()
    assert (y == y0[-len(y):]).all()
    assert (p == p0[-len(p):]).all()
    assert (x_val == x0[:len(x_val)]).all()
    assert (y_val == y0[:len(y_val)]).all()
    assert (p_val == p0[:len(p_val)]).all()
Пример #2
0
def test_validation_split_shuffle():
    """Test the validation split operation with shuffling"""
    out = PhysicsGuidedNeuralNetwork.get_val_split(X,
                                                   Y,
                                                   P,
                                                   shuffle=True,
                                                   validation_split=0.3)
    x, y, p, x_val, y_val, p_val = out

    assert (x_val == p_val).all()
    assert (x == p).all()

    assert id(x) != id(X)
    assert x.shape[1] == x.shape[1]
    assert len(x) == int(0.7 * len(X))
    assert len(x_val) == int(0.3 * len(X))

    assert id(y) != id(Y)
    assert y.shape[1] == y.shape[1]
    assert len(y) == int(0.7 * len(Y))
    assert len(y_val) == int(0.3 * len(Y))

    assert id(p) != id(P)
    assert p.shape[1] == p.shape[1]
    assert len(p) == int(0.7 * len(P))
    assert len(p_val) == int(0.3 * len(P))

    for i in range(len(x_val)):
        row = x_val[i, :]
        assert ~np.any(np.all((row == x), axis=1))

    for i in range(len(p_val)):
        row = p_val[i, :]
        assert ~np.any(np.all((row == p), axis=1))
Пример #3
0
def test_validation_split_no_shuffle():
    """Test the validation split operation without shuffling"""
    out = PhysicsGuidedNeuralNetwork.get_val_split(X,
                                                   Y,
                                                   P,
                                                   shuffle=False,
                                                   validation_split=0.3)
    x, y, p, x_val, y_val, p_val = out
    assert (x_val == p_val).all()
    assert (x == p).all()
    assert all(np.sqrt(x[:, 0]**2 + x[:, 1]**2).reshape((len(x), 1)) == y)
    assert (x_val == X[0:len(x_val)]).all()
    assert (y_val == Y[0:len(y_val)]).all()
    assert (p_val == P[0:len(p_val)]).all()