Пример #1
0
class LSTMForecaster(TFParkForecaster):
    """
    Vanilla LSTM Forecaster
    """
    def __init__(self,
                 target_dim=1,
                 feature_dim=1,
                 lstm_1_units=16,
                 dropout_1=0.2,
                 lstm_2_units=8,
                 dropout_2=0.2,
                 metric="mean_squared_error",
                 lr=0.001,
                 loss="mse",
                 uncertainty: bool = False):
        """
        Build a LSTM Forecast Model.

        :param target_dim: dimension of model output
        :param feature_dim: dimension of input feature
        :param lstm_1_units: num of units for the 1st LSTM layer
        :param dropout_1: p for the 1st dropout layer
        :param lstm_2_units: num of units for the 2nd LSTM layer
        :param dropout_2: p for the 2nd dropout layer
        :param metric: the metric for validation and evaluation
        :param lr: learning rate
        :param uncertainty: whether to return uncertainty
        :param loss: the target function you want to optimize on
        """
        #
        self.target_dim = target_dim
        self.check_optional_config = False
        self.uncertainty = uncertainty

        self.model_config = {
            "lr": lr,
            "lstm_1_units": lstm_1_units,
            "dropout_1": dropout_1,
            "lstm_2_units": lstm_2_units,
            "dropout_2": dropout_2,
            "metric": metric,
            "feature_num": feature_dim,
            "loss": loss
        }
        self.internal = None

        super().__init__()

    def _build(self):
        """
        Build LSTM Model in tf.keras
        """
        # build model with TF/Keras
        self.internal = LSTMKerasModel(
            check_optional_config=self.check_optional_config,
            future_seq_len=self.target_dim)
        return self.internal._build(mc=self.uncertainty, **self.model_config)
Пример #2
0
class LSTMForecaster(Forecaster):
    """
    Vanilla LSTM Forecaster
    """
    def __init__(self,
                 horizon=1,
                 feature_dim=1,
                 lstm_1_units=16,
                 dropout_1=0.2,
                 lstm_2_units=8,
                 dropout_2=0.2,
                 metric="mean_squared_error",
                 lr=0.001,
                 uncertainty: bool = False):
        """
        Build a LSTM Forecast Model.

        @param horizon: steps to look forward
        @param feature_dim: dimension of input feature
        @param lstm_1_units: num of units for the 1st LSTM layer
        @param dropout_1: p for the 1st dropout layer
        @param lstm_2_units: num of units for the 2nd LSTM layer
        @param dropout_2: p for the 2nd dropout layer
        @param metric: the metric for validation and evaluation
        @param lr: learning rate
        @param uncertainty: whether to return uncertainty
        """
        #
        self.horizon = horizon
        self.check_optional_config = False
        self.uncertainty = uncertainty

        self.model_config = {
            "lr": lr,
            "lstm_1_units": lstm_1_units,
            "dropout_1": dropout_1,
            "lstm_2_units": lstm_2_units,
            "dropout_2": dropout_2,
            "metric": metric,
            "feature_num": feature_dim
        }
        self.internal = None

        super().__init__()

    def _build(self):
        """
        Build LSTM Model in tf.keras
        """
        # build model with TF/Keras
        self.internal = LSTMKerasModel(
            check_optional_config=self.check_optional_config,
            future_seq_len=self.horizon)
        return self.internal._build(mc=self.uncertainty, **self.model_config)