Exemple #1
0
 def compute_data_from_recipe(
     self,
     num_steps: int,
     constant: Optional[float] = None,
     one_to_zero: float = 0.1,
     zero_to_one: float = 0.1,
     scale_features: float = 200,
 ) -> TrainDatasets:
     recipe = []
     recipe_type = Constant(constant)
     if self.is_noise:
         recipe_type += RandomGaussian()  # Use default stddev = 1.0
     if self.is_trend:
         recipe_type += LinearTrend()
     if self.is_promotions:
         recipe.append(
             ("binary_causal", BinaryMarkovChain(one_to_zero, zero_to_one))
         )
         recipe.append(
             (FieldName.FEAT_DYNAMIC_REAL, Stack(["binary_causal"]))
         )
         recipe_type += scale_features * Lag("binary_causal", lag=0)
     if self.holidays:
         # Compute dates array
         dates = list(
             pd.period_range(self.start, periods=num_steps, freq=self.freq)
         )
         recipe.append(
             ("binary_holidays", BinaryHolidays(dates, self.holidays))
         )
         recipe.append(
             (FieldName.FEAT_DYNAMIC_REAL, Stack(["binary_holidays"]))
         )
         recipe_type += scale_features * Lag("binary_holidays", lag=0)
     recipe.append((FieldName.TARGET, recipe_type))
     max_train_length = num_steps - self.prediction_length
     data = RecipeDataset(
         recipe=recipe,
         metadata=self.metadata,
         max_train_length=max_train_length,
         prediction_length=self.prediction_length,
         # Add 1 time series at a time in the loop for different constant
         # valus per time series
         num_timeseries=1,
     )
     generated = data.generate()
     return generated
Exemple #2
0
 def compute_data_from_recipe(
     self,
     num_steps: int,
     constant: Optional[float] = None,
     one_to_zero: float = 0.1,
     zero_to_one: float = 0.1,
     scale_features: float = 200,
 ) -> TrainDatasets:
     recipe = []
     recipe_type = Constant(constant)
     if self.is_noise:
         recipe_type += RandomGaussian()  # Use default stddev = 1.0
     if self.is_trend:
         recipe_type += LinearTrend()
     if self.is_promotions:
         recipe.append(
             ('binary_causal', BinaryMarkovChain(one_to_zero, zero_to_one)))
         recipe.append(('feat_dynamic_real', Stack(['binary_causal'])))
         recipe_type += scale_features * Lag('binary_causal', lag=0)
     if self.holidays:
         timestamp = self.init_date()
         # Compute dates array
         dates = []
         for i in range(num_steps):
             dates.append(timestamp)
             timestamp += 1
         recipe.append(('binary_holidays', Binary(dates, self.holidays)))
         recipe.append(('feat_dynamic_real', Stack(['binary_holidays'])))
         recipe_type += scale_features * Lag('binary_holidays', lag=0)
     recipe.append(('target', recipe_type))
     max_train_length = num_steps - self.prediction_length
     data = RecipeDataset(
         recipe=recipe,
         metadata=self.metadata,
         max_train_length=max_train_length,
         prediction_length=self.prediction_length,
         num_timeseries=
         1,  # Add 1 time series at a time in the loop for different constant valus per time series
     )
     generated = data.generate()
     return generated
Exemple #3
0
        Debug(),
        RandomGaussian(),
        RandomBinary(),
        RandomSymmetricDirichlet(),
        BinaryMarkovChain(0.1, 0.1),
        Constant(1),
        LinearTrend(),
        RandomCat([10]),
        Lag("foo", 1),
        ForEachCat(RandomGaussian()),
        Eval("np.random.rand(length)"),
        SmoothSeasonality(Constant(12), Constant(0)),
        Add(["foo", "foo"]),
        Mul(["foo", "foo"]),
        NanWhere("foo", "foo"),
        Stack([Ref("foo"), Ref("foo")]),
        RandomGaussian() + RandomGaussian(),
        RandomGaussian() * RandomGaussian(),
        RandomGaussian() / RandomGaussian(),
    ],
)
def test_call_and_repr(func) -> None:
    global_state = {}
    x = evaluate(BASE_RECIPE, length=10, global_state=global_state)
    kwargs = dict(foo=42, bar=23)
    np.random.seed(0)
    ret = func(
        x,
        field_name="bar",
        length=10,
        global_state=global_state.copy(),
Exemple #4
0
        RandomGaussian(),
        RandomBinary(),
        RandomSymmetricDirichlet(),
        BinaryMarkovChain(0.1, 0.1),
        Constant(1),
        LinearTrend(),
        RandomCat([10]),
        Lag("foo", 1),
        ForEachCat(RandomGaussian()),
        Expr("np.random.rand(length)"),
        SmoothSeasonality(Constant(12), Constant(0)),
        Add(['foo', 'foo']),
        Mul(['foo', 'foo']),
        NanWhere('foo', 'foo'),
        NanWhereNot('foo', 'foo'),
        Stack(['foo', 'foo']),
        RandomGaussian() + RandomGaussian(),
        RandomGaussian() * RandomGaussian(),
        RandomGaussian() / RandomGaussian(),
    ],
)
def test_call_and_repr(func) -> None:
    global_state = {}
    x = evaluate_recipe(BASE_RECIPE, length=10, global_state=global_state)
    kwargs = dict(foo=42, bar=23)
    np.random.seed(0)
    ret = func(
        x,
        field_name='bar',
        length=10,
        global_state=global_state.copy(),
Exemple #5
0
        RandomGaussian(),
        RandomBinary(),
        RandomSymmetricDirichlet(),
        BinaryMarkovChain(0.1, 0.1),
        Constant(1),
        LinearTrend(),
        RandomCat([10]),
        Lag("foo", 1),
        ForEachCat(RandomGaussian()),
        Expr("np.random.rand(length)"),
        SmoothSeasonality(Constant(12), Constant(0)),
        Add(["foo", "foo"]),
        Mul(["foo", "foo"]),
        NanWhere("foo", "foo"),
        NanWhereNot("foo", "foo"),
        Stack(["foo", "foo"]),
        RandomGaussian() + RandomGaussian(),
        RandomGaussian() * RandomGaussian(),
        RandomGaussian() / RandomGaussian(),
    ],
)
def test_call_and_repr(func) -> None:
    global_state = {}
    x = evaluate_recipe(BASE_RECIPE, length=10, global_state=global_state)
    kwargs = dict(foo=42, bar=23)
    np.random.seed(0)
    ret = func(
        x,
        field_name="bar",
        length=10,
        global_state=global_state.copy(),