WeeklyFourier.apply#

WeeklyFourier.apply(dayofperiod, result_callback=None)#

Apply fourier seasonality to day of year.

Must be used within a PyMC model context.

Parameters:
dayofperiodpt.TensorLike

Day of year or weekday

result_callbackCallable[[pt.TensorVariable], None], optional

Callback function to apply to the result, by default None

Returns:
pt.TensorVariable

Fourier seasonality

Examples

Save off the result before summing through the prefix dimension.

import pandas as pd

import pymc as pm

from pymc_marketing.mmm import YearlyFourier

fourier = YearlyFourier(n_order=3)

def callback(result):
    pm.Deterministic("fourier_trend", result, dims=("date", "fourier"))

dates = pd.date_range("2023-01-01", periods=52, freq="W-MON")

coords = {
    "date": dates,
}
with pm.Model(coords=coords) as model:
    dayofyear = dates.dayofyear.to_numpy()
    fourier.apply(dayofyear, result_callback=callback)