Beispiel #1
0
 def _predict_time_series_top_down(self, dictionary, X=None):
     for key in self.level_nodes[self.level]:
         submodel = HierarchicalTopDown(
             model=self.model,
             hierarchy_tree=self.sub_trees_dictionary[key],
             root=key,
             method=self.method)
         submodel.models_ = self._extract_fitted_models(key)
         submodel.proportions = self._extract_proportions(key)
         dictionary.update(submodel.predict(X))
     return
Beispiel #2
0
def hierarchical_top_down_model_sgf(draw,
                                    time_series_forecasting_model1_no_cache):
    dataframes = draw(n_time_series_with_same_index(min_n=5))
    tree = draw(tree_construction(dataframes))
    method = "tdsgf"
    return HierarchicalTopDown(
        model=time_series_forecasting_model1_no_cache,
        hierarchy_tree=tree,
        method=method,
    )
Beispiel #3
0
 def _predict_new_time_series(self,
                              X: pd.DataFrame) -> Dict[str, pd.DataFrame]:
     new_time_series_dictionary = {}
     if self.level == 0:
         new_time_series_dictionary = HierarchicalTopDown._predict_new_time_series(
             self, X)
     elif self.level == max(list(self.level_nodes.keys())):
         new_time_series_dictionary = HierarchicalBottomUp._predict_new_time_series(
             self, X)
     else:
         self._predict_time_series_top_down(new_time_series_dictionary, X)
         self._predict_new_time_series_bottom_up(new_time_series_dictionary,
                                                 X)
     return new_time_series_dictionary
Beispiel #4
0
def hierarchical_top_down_model_sga_tree_by_hand(
        draw, time_series_forecasting_model1_no_cache):
    tree_adjacency_list = {
        "0": {},
        "1": {},
        "2": {
            "1": {},
            "4": {}
        },
        "3": {
            "0": {},
            "2": {}
        },
        "4": {},
    }
    tree = nx.DiGraph(tree_adjacency_list)
    root = "3"
    return HierarchicalTopDown(model=time_series_forecasting_model1_no_cache,
                               hierarchy_tree=tree,
                               root=root)
Beispiel #5
0
def hierarchical_basic_top_down_model_fp_method(
    time_series_forecasting_model1_no_cache, ):
    return HierarchicalTopDown(time_series_forecasting_model1_no_cache,
                               hierarchy_tree="infer",
                               method="tdfp")
Beispiel #6
0
def hierarchical_basic_top_down_model(time_series_forecasting_model1_no_cache):
    return HierarchicalTopDown(time_series_forecasting_model1_no_cache,
                               "infer")
Beispiel #7
0
 def test_prediction_values_top_down_tdfp(self):
     index = [
         "2000-01-01 00:00:00",
         "2000-01-01 00:00:01",
         "2000-01-01 00:00:02",
         "2000-01-01 00:00:03",
         "2000-01-01 00:00:04",
         "2000-01-01 00:00:05",
         "2000-01-01 00:00:06",
         "2000-01-01 00:00:07",
         "2000-01-01 00:00:08",
         "2000-01-01 00:00:09",
         "2000-01-01 00:00:10",
         "2000-01-01 00:00:11",
         "2000-01-01 00:00:12",
         "2000-01-01 00:00:13",
         "2000-01-01 00:00:14",
         "2000-01-01 00:00:15",
         "2000-01-01 00:00:16",
         "2000-01-01 00:00:17",
         "2000-01-01 00:00:18",
         "2000-01-01 00:00:19",
     ]
     time_series_model = AR(p=2, horizon=3)
     data1_list = [1 for i in range(20)]
     data2_list = [1 for i in range(10)] + [0 for i in range(10)]
     data3_list = [0 for i in range(10)] + [1 for i in range(10)]
     data1 = pd.DataFrame(index=index, data=data1_list)
     data2 = pd.DataFrame(index=index, data=data2_list)
     data3 = pd.DataFrame(index=index, data=data3_list)
     data = {"data1": data1, "data2": data2, "data3": data3}
     tree_adj = {"data1": ["data2", "data3"], "data2": [], "data3": []}
     values_prediction_data1 = [[1.0, 1.0, 1.0], [1.0, 1.0, 1.0],
                                [1.0, 1.0, 1.0]]
     values_prediction_child = [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0],
                                [0.0, 0.0, 0.0]]
     test_prediction_data1 = pd.DataFrame(
         data=values_prediction_data1,
         columns=["y_1", "y_2", "y_3"],
         index=[
             "2000-01-01 00:00:17", "2000-01-01 00:00:18",
             "2000-01-01 00:00:19"
         ],
     )
     test_prediction_data2 = pd.DataFrame(
         data=values_prediction_child,
         columns=["y_1", "y_2", "y_3"],
         index=[
             "2000-01-01 00:00:17", "2000-01-01 00:00:18",
             "2000-01-01 00:00:19"
         ],
     )
     test_prediction_data3 = pd.DataFrame(
         data=values_prediction_data1,
         columns=["y_1", "y_2", "y_3"],
         index=[
             "2000-01-01 00:00:17", "2000-01-01 00:00:18",
             "2000-01-01 00:00:19"
         ],
     )
     prediction = HierarchicalTopDown(
         model=time_series_model,
         hierarchy_tree=tree_adj,
         root="data1",
         method="tdfp",
     )
     test_prediction_data = {
         "data1": test_prediction_data1,
         "data2": test_prediction_data2,
         "data3": test_prediction_data3,
     }
     prediction = prediction.fit(data).predict()
     for key in test_prediction_data.keys():
         assert_frame_equal(test_prediction_data[key], prediction[key])
Beispiel #8
0
 def test_constructor(self, time_series_forecasting_model1_no_cache,
                      dataframes):
     tree = tree_construction(dataframes)
     HierarchicalTopDown(time_series_forecasting_model1_no_cache, tree)
Beispiel #9
0
 def test_basic_constructor(self, time_series_forecasting_model1_no_cache):
     HierarchicalTopDown(model=time_series_forecasting_model1_no_cache,
                         hierarchy_tree="infer")