コード例 #1
0
 def create_transformation(self) -> Transformation:
     return Chain([
         AsNumpyArray(
             field=FieldName.TARGET,
             expected_ndim=2,
         ),
         # maps the target to (1, T)
         # if the target data is uni dimensional
         ExpandDimArray(
             field=FieldName.TARGET,
             axis=None,
         ),
         AddObservedValuesIndicator(
             target_field=FieldName.TARGET,
             output_field=FieldName.OBSERVED_VALUES,
         ),
         AddTimeFeatures(
             start_field=FieldName.START,
             target_field=FieldName.TARGET,
             output_field=FieldName.FEAT_TIME,
             time_features=self.time_features,
             pred_length=self.prediction_length,
         ),
         VstackFeatures(
             output_field=FieldName.FEAT_TIME,
             input_fields=[FieldName.FEAT_TIME],
         ),
         SetFieldIfNotPresent(field=FieldName.FEAT_STATIC_CAT, value=[0]),
         TargetDimIndicator(
             field_name="target_dimension_indicator",
             target_field=FieldName.TARGET,
         ),
         AsNumpyArray(field=FieldName.FEAT_STATIC_CAT, expected_ndim=1),
         InstanceSplitter(
             target_field=FieldName.TARGET,
             is_pad_field=FieldName.IS_PAD,
             start_field=FieldName.START,
             forecast_start_field=FieldName.FORECAST_START,
             train_sampler=ExpectedNumInstanceSampler(num_instances=1),
             past_length=self.history_length,
             future_length=self.prediction_length,
             time_series_fields=[
                 FieldName.FEAT_TIME,
                 FieldName.OBSERVED_VALUES,
             ],
             pick_incomplete=self.pick_incomplete,
         ),
         RenameFields({
             f"past_{FieldName.TARGET}":
             f"past_{FieldName.TARGET}_cdf",
             f"future_{FieldName.TARGET}":
             f"future_{FieldName.TARGET}_cdf",
         }),
     ])
コード例 #2
0
ファイル: deepvar_estimator.py プロジェクト: east0/pytorch-ts
    def create_transformation(self) -> Transformation:
        def use_marginal_transformation(
            marginal_transformation: bool, ) -> Transformation:
            if marginal_transformation:
                return CDFtoGaussianTransform(
                    target_field=FieldName.TARGET,
                    observed_values_field=FieldName.OBSERVED_VALUES,
                    max_context_length=self.conditioning_length,
                    target_dim=self.target_dim,
                )
            else:
                return RenameFields({
                    f"past_{FieldName.TARGET}":
                    f"past_{FieldName.TARGET}_cdf",
                    f"future_{FieldName.TARGET}":
                    f"future_{FieldName.TARGET}_cdf",
                })

        return Chain([
            AsNumpyArray(
                field=FieldName.TARGET,
                expected_ndim=1 + len(self.distr_output.event_shape),
            ),
            # maps the target to (1, T)
            # if the target data is uni dimensional
            ExpandDimArray(
                field=FieldName.TARGET,
                axis=0 if self.distr_output.event_shape[0] == 1 else None,
            ),
            AddObservedValuesIndicator(
                target_field=FieldName.TARGET,
                output_field=FieldName.OBSERVED_VALUES,
            ),
            AddTimeFeatures(
                start_field=FieldName.START,
                target_field=FieldName.TARGET,
                output_field=FieldName.FEAT_TIME,
                time_features=self.time_features,
                pred_length=self.prediction_length,
            ),
            VstackFeatures(
                output_field=FieldName.FEAT_TIME,
                input_fields=[FieldName.FEAT_TIME],
            ),
            SetFieldIfNotPresent(field=FieldName.FEAT_STATIC_CAT, value=[0]),
            TargetDimIndicator(
                field_name="target_dimension_indicator",
                target_field=FieldName.TARGET,
            ),
            AsNumpyArray(field=FieldName.FEAT_STATIC_CAT, expected_ndim=1),
            InstanceSplitter(
                target_field=FieldName.TARGET,
                is_pad_field=FieldName.IS_PAD,
                start_field=FieldName.START,
                forecast_start_field=FieldName.FORECAST_START,
                train_sampler=ExpectedNumInstanceSampler(num_instances=1),
                past_length=self.history_length,
                future_length=self.prediction_length,
                time_series_fields=[
                    FieldName.FEAT_TIME,
                    FieldName.OBSERVED_VALUES,
                ],
                pick_incomplete=self.pick_incomplete,
            ),
            use_marginal_transformation(self.use_marginal_transformation),
        ])