def test_vector_conversion_to_datetime():
    flights_dataset = FlightsDataset()
    dt_vector = convert_year_month_array_to_datetime(
        flights_dataset.x[0, 0:5, :])
    expected_output_vector = [
        datetime(1949, 1, 15),
        datetime(1949, 2, 15),
        datetime(1949, 3, 15),
        datetime(1949, 4, 15),
        datetime(1949, 5, 15),
    ]
    assert np.all(expected_output_vector == dt_vector)
def test_train_loss_monitor_no_train_split():
    """
    Tests the LSTMTimeSeriesPredictor fitting
    """
    tsp = TimeSeriesPredictor(BenchmarkLSTM(hidden_dim=10),
                              early_stopping=EarlyStopping(
                                  monitor='train_loss', patience=15),
                              max_epochs=150,
                              train_split=None,
                              optimizer=torch.optim.Adam)
    tsp.fit(FlightsDataset())
    mean_r2_score = tsp.score(tsp.dataset)
    assert mean_r2_score > -300
예제 #3
0
def test_quantum_lstm_tsp_forecast(device):
    """
    Tests the Quantum LSTM forecast
    """
    cuda_check(device)

    tsp = TimeSeriesPredictor(
        QuantumLSTM(hidden_dim = 2),
        max_epochs=250,
        lr = 1e-4,
        early_stopping=EarlyStopping(patience=100, monitor='train_loss'),
        train_split=None,
        optimizer=Adam,
        device=device
    )

    whole_fd = FlightsDataset()
    # leave last N months for error assertion
    last_n = 24
    start = time.time()
    tsp.fit(FlightsDataset(pattern_length = 120, except_last_n = last_n))
    end = time.time()
    elapsed = timedelta(seconds = end - start)
    print(f"Fitting in {device} time delta: {elapsed}")
    mean_r2_score = tsp.score(tsp.dataset)
    assert mean_r2_score > -5

    netout, _ = tsp.forecast(last_n)

    # Select any training example just for comparison
    idx = np.random.randint(0, len(tsp.dataset))
    _, whole_y = whole_fd[idx]

    y_true = whole_y[-last_n:, :]   # get only known future outputs
    y_pred = netout[idx, -last_n:, :]    # get only last N predicted outputs
    r2s = r2_score(y_true, y_pred)
    assert r2s > -60
def test_transformer_tsp(device):
    '''univariate test'''
    cuda_check(device)

    start = time.time()
    tsp = TimeSeriesPredictor(
        Transformer(),
        max_epochs=50,
        train_split=None,
        device=device,
    )

    tsp.fit(FlightsDataset())
    score = tsp.score(tsp.dataset)
    assert score > -1
    end = time.time()
    elapsed = timedelta(seconds=end - start)
    print(f"Fitting in {device} time delta: {elapsed}")
예제 #5
0
def test_quantum_lstm_tsp_fitting(device):
    """
    Tests the Quantum LSTM TimeSeriesPredictor fitting
    """
    cuda_check(device)

    tsp = TimeSeriesPredictor(
        QuantumLSTM(),
        lr=1E-1,
        max_epochs=50,
        train_split=None,
        optimizer=Adam,
        device=device
    )

    start = time.time()
    tsp.fit(FlightsDataset())
    end = time.time()
    elapsed = timedelta(seconds = end - start)
    print("Fitting in {} time delta: {}".format(device, elapsed))
    mean_r2_score = tsp.score(tsp.dataset)
    assert mean_r2_score > -10
def test_dataset_shape():
    flights_dataset = FlightsDataset()
    assert flights_dataset.get_y_shape() == (1, 144, 1)
    assert flights_dataset.get_x_shape() == (1, 144, 2)
    fd = flights_dataset.make_future_dataframe(12)
    assert fd.shape == (1, 156, 2)
def test_conversion_to_datetime():
    flights_dataset = FlightsDataset()
    first_date = flights_dataset.x[0, 0, :]
    dt = convert_year_month_array_to_datetime(first_date)
    assert dt == datetime(1949, 1, 15)