Ejemplo n.º 1
0
def test_parallelized_predictor():
    dataset = ListDataset(
        data_iter=[{
            "start": "2012-01-01",
            "target": (np.zeros(20) + i).tolist()
        } for i in range(300)],
        freq="1H",
    )

    base_predictor = IdentityPredictor(freq="1H",
                                       prediction_length=10,
                                       num_samples=100)

    predictor = ParallelizedPredictor(base_predictor=base_predictor,
                                      num_workers=10,
                                      chunk_size=2)

    predictions = list(base_predictor.predict(dataset))
    parallel_predictions = list(predictor.predict(dataset))

    assert len(predictions) == len(parallel_predictions)

    for p, pp in zip(predictions, parallel_predictions):
        assert np.all(p.samples == pp.samples)
        assert np.all(p.index == pp.index)
Ejemplo n.º 2
0
 def setup_class(self):
     self.frequency = "D"
     self.prediction_length = 2
     timeseries_0 = {
         TIMESERIES_KEYS.START:
         "2018-01-01",
         TIMESERIES_KEYS.TARGET:
         np.array([12, 13, 14, 15]),
         TIMESERIES_KEYS.TARGET_NAME:
         "sales",
         TIMESERIES_KEYS.TIME_COLUMN_NAME:
         "date",
         TIMESERIES_KEYS.FEAT_DYNAMIC_REAL:
         np.array([[1, 0, 0, 0, 0, 1], [0, 0, 0, 1, 1, 0]]),
         TIMESERIES_KEYS.FEAT_DYNAMIC_REAL_COLUMNS_NAMES:
         ["is_holiday", "is_weekend"],
         TIMESERIES_KEYS.IDENTIFIERS: {
             "store": 1,
             "item": 1
         },
     }
     timeseries_1 = {
         TIMESERIES_KEYS.START:
         "2018-01-01",
         TIMESERIES_KEYS.TARGET:
         np.array([2, 3, 4, 5]),
         TIMESERIES_KEYS.TARGET_NAME:
         "sales",
         TIMESERIES_KEYS.TIME_COLUMN_NAME:
         "date",
         TIMESERIES_KEYS.FEAT_DYNAMIC_REAL:
         np.array([[1, 0, 0, 0, 0, 1], [0, 0, 0, 1, 1, 0]]),
         TIMESERIES_KEYS.FEAT_DYNAMIC_REAL_COLUMNS_NAMES:
         ["is_holiday", "is_weekend"],
         TIMESERIES_KEYS.IDENTIFIERS: {
             "store": 1,
             "item": 2
         },
     }
     self.gluon_dataset = ListDataset([timeseries_0, timeseries_1],
                                      freq=self.frequency)
     self.predictor = IdentityPredictor(prediction_length=2,
                                        freq="D",
                                        num_samples=100)