def create_components( self, submodel_params: Iterable[NBeatsParams]) -> keras.Model: """ Create ensemble components (submodels and mixer) submodel_params: Sequence of sub-model params """ # 1 - create sub-models self.backcast_length = -1 for param in submodel_params: mdl = NBeatsTF(param) if mdl.backcast_length > self.backcast_length: self.backcast_length = mdl.backcast_length self.sub_models[mdl.name] = mdl if self.submodel_names is None: self.submodel_names = sorted(self.sub_models.keys()) else: # Are these models what we were expecting ? assert self.submodel_names == sorted(self.sub_models.keys()) # 2 - create mixer model. backast length the largest backast of submodels self.mixer = Mixer(self.backcast_length, len(self.sub_models), self.hidden_layer_units, method=self.weighted_aggregation_method) return self
def load(self, params: Iterable[Tuple[NBeatsParams, str]]): """ params: List((NBeatsParams, weight_path)) """ for p, d in params: mdl = NBeatsTF(p) if mdl.backcast_length > self.backcast_length: self.backcast_length = mdl.backcast_length mdl.load(d) self.sub_models.append(mdl) assert self.backcast_length > 0, 'Backast length not determined'