def train(self, df_train_subset, dataset_dict, grid_size, **kwargs): train_pts, train_region = ProcessData.get_time_space_points( df_train_subset, dataset_dict) if (isinstance(kwargs['region'], open_cp.data.RectangularRegion)): train_region = kwargs['region'] trained_model = kde.KDE(region=train_region, grid_size=grid_size) trained_model.time_kernel = kde.ExponentialTimeKernel(1) trained_model.space_kernel = kde.GaussianBaseProvider() trained_model.data = train_pts return trained_model
def test_time_delta_usage(gb_mock, data1): region = open_cp.data.RectangularRegion(xmin=0, xmax=100, ymin=20, ymax=50) predictor = kde.KDE(region, 20) predictor.data = data1 predictor.time_kernel = mock.MagicMock() predictor.time_unit = datetime.timedelta(hours=1) predictor.predict() assert len(predictor.time_kernel.call_args_list) == 1 assert len(predictor.time_kernel.call_args_list[0][0]) == 1 np.testing.assert_allclose(predictor.time_kernel.call_args_list[0][0][0], [48, 24, 0])
def test_construct(data1): region = open_cp.data.RectangularRegion(xmin=0, xmax=90, ymin=20, ymax=50) predictor = kde.KDE(region, 20) predictor.data = data1 pred = predictor.predict() assert pred.xsize == 20 assert pred.ysize == 20 assert pred.region().min == (0, 20) # Scaled up as grid size is 20 assert pred.region().max == (100, 60)
def test_kernel_constructed_correctly(gb_mock, data1): region = open_cp.data.RectangularRegion(xmin=0, xmax=100, ymin=20, ymax=50) predictor = kde.KDE(region, 20) predictor.data = data1 predictor.predict() assert len(gb_mock.call_args_list) == 1 call = gb_mock.call_args_list[0] assert len(call[0]) == 1 np.testing.assert_allclose(call[0][0], [[5, 50, 20], [30, 20, 10]]) np.testing.assert_allclose(gb_mock.return_value.weights, [1, 1, 1]) print(gb_mock.return_value.call_args_list)
def test_time_delta_usage_with_start_time(gb_mock, data1): region = open_cp.data.RectangularRegion(xmin=0, xmax=100, ymin=20, ymax=50) predictor = kde.KDE(region, 20) predictor.data = data1 predictor.time_kernel = mock.MagicMock() predictor.time_unit = datetime.timedelta(hours=1) predictor.predict(start_time=datetime.datetime(2017, 4, 22)) assert len(predictor.time_kernel.call_args_list) == 1 assert len(predictor.time_kernel.call_args_list[0][0]) == 1 np.testing.assert_allclose(predictor.time_kernel.call_args_list[0][0][0], [24, 0]) assert len(gb_mock.call_args_list) == 1 call = gb_mock.call_args_list[0] np.testing.assert_allclose(call[0][0], [[50, 20], [20, 10]])