def test_create_keras_timeseriesgenerator_raise_error_on_neg_lookahead():
    """Check create_keras_timeseriesgenerator raises an error on negative lookahead"""
    X = np.array([[0, 1]])
    y = X.copy()
    with pytest.raises(ValueError):
        create_keras_timeseriesgenerator(X,
                                         y,
                                         batch_size=2,
                                         lookback_window=2,
                                         lookahead=-1)
Exemple #2
0
 def test_create_keras_timeseriesgenerator_raise_error_on_neg_lookahead(
         self):
     # Check that create_keras_timeseriesgenerator raises an error on negative
     # lookahead
     X = np.array([[0, 1]])
     with self.assertRaises(ValueError):
         create_keras_timeseriesgenerator(X,
                                          batch_size=2,
                                          lookback_window=2,
                                          lookahead=-1)
def test_create_keras_timeseriesgenerator_lb3_loah2_bs2():
    """
    Check right output is generated from create_keras_timeseriesgenerator
    We use lookback_window 2 to get some more interesting batches with lookahead 1
    """
    X = np.array([[0, 1], [2, 3], [4, 5], [6, 7], [8, 9]])
    y = X.copy()
    gen = create_keras_timeseriesgenerator(X,
                                           y,
                                           batch_size=2,
                                           lookback_window=2,
                                           lookahead=2)
    batch_1 = gen[0]
    batch_2 = gen[1]

    batch_1_x = batch_1[0].tolist()
    batch_1_y = batch_1[1].tolist()

    batch_2_x = batch_2[0].tolist()
    batch_2_y = batch_2[1].tolist()

    assert [[[0, 1], [2, 3]], [[2, 3], [4, 5]]] == batch_1_x
    assert [[6, 7], [8, 9]] == batch_1_y

    assert [] == batch_2_x  # No more elements left
    assert [] == batch_2_y
Exemple #4
0
    def test_create_keras_timeseriesgenerator_lb3_loah2_bs2(self):
        # Check that right output is generated from create_keras_timeseriesgenerator
        # We use lookback_window 2 to get some more interesting batches with lookahead 1
        X = np.array([[0, 1], [2, 3], [4, 5], [6, 7], [8, 9]])
        gen = create_keras_timeseriesgenerator(X,
                                               batch_size=2,
                                               lookback_window=2,
                                               lookahead=2)
        batch_1 = gen[0]
        batch_2 = gen[1]

        batch_1_x = batch_1[0].tolist()
        batch_1_y = batch_1[1].tolist()

        batch_2_x = batch_2[0].tolist()
        batch_2_y = batch_2[1].tolist()

        self.assertEquals([[[0, 1], [2, 3]], [[2, 3], [4, 5]]], batch_1_x)
        self.assertEqual([[6, 7], [8, 9]], batch_1_y)

        self.assertEqual([], batch_2_x)  # No more elements left
        self.assertEqual([], batch_2_y)
Exemple #5
0
    def test_create_keras_timeseriesgenerator_lb3_loah0_bs2(self):
        # Check that right output is generated from create_keras_timeseriesgenerator
        X = np.array([[0, 1], [2, 3], [4, 5], [6, 7], [8, 9]])
        gen = create_keras_timeseriesgenerator(X,
                                               batch_size=2,
                                               lookback_window=3,
                                               lookahead=0)
        batch_1 = gen[0]
        batch_2 = gen[1]

        batch_1_x = batch_1[0].tolist()
        batch_1_y = batch_1[1].tolist()

        batch_2_x = batch_2[0].tolist()
        batch_2_y = batch_2[1].tolist()

        self.assertEquals([[[0, 1], [2, 3], [4, 5]], [[2, 3], [4, 5], [6, 7]]],
                          batch_1_x)
        self.assertEqual([[4, 5], [6, 7]], batch_1_y)

        self.assertEqual([[[4, 5], [6, 7], [8, 9]]], batch_2_x)
        self.assertEqual([[8, 9]], batch_2_y)
def test_create_keras_timeseriesgenerator_lb3_loah0_bs2():
    """Check that right output is generated from create_keras_timeseriesgenerator"""
    X = np.array([[0, 1], [2, 3], [4, 5], [6, 7], [8, 9]])
    y = X.copy()
    gen = create_keras_timeseriesgenerator(X,
                                           y,
                                           batch_size=2,
                                           lookback_window=3,
                                           lookahead=0)
    batch_1 = gen[0]
    batch_2 = gen[1]

    batch_1_x = batch_1[0].tolist()
    batch_1_y = batch_1[1].tolist()

    batch_2_x = batch_2[0].tolist()
    batch_2_y = batch_2[1].tolist()

    assert [[[0, 1], [2, 3], [4, 5]], [[2, 3], [4, 5], [6, 7]]] == batch_1_x
    assert [[4, 5], [6, 7]] == batch_1_y

    assert [[[4, 5], [6, 7], [8, 9]]] == batch_2_x
    assert [[8, 9]] == batch_2_y