features.fourier_features()
Build a Fourier seasonality design matrix.
Usage
features.fourier_features(
duration,
period,
num_terms,
)Safe to call inside a model function (for example with h.duration of a Horizon), also under svi.run or the jitted forecast(). The matrix is computed in float64 and cached per argument tuple, then returned in the current default float dtype (float64 with x64 enabled, float32 otherwise).
Parameters
duration: IntScalar-
Number of time steps, a non-negative Python or NumPy integer (not a
float). period: RealScalar-
Seasonal period (in time steps): a positive, finite Python or NumPy integer or float, for example
7for daily data with a weekly season. A NumPy float is used at its exact binary value, sonp.float32(0.1)is the period0.10000000149011612, not0.1, and the two spellings are two memo entries. num_terms: IntScalar-
Number of harmonics, a non-negative Python or NumPy integer of at most
floor(period / 2); the output has2 * num_termscolumns (sine then cosine), none for0. The matrix samplest = 0, 1, ..., so harmonick > period / 2is above the Nyquist frequency of that grid and aliases onto the lower frequency(period - k) / period: same cosine samples, negated sine samples (harmonicperiod - kwhenperiodis an integer). For an even integerperiod,num_terms == period / 2is valid but its last sine column is zero up to rounding; the matching cosine column alternates between1and-1.
Returns
Float[Array, "duration two_num_terms"]-
The design matrix of shape
(duration, 2 * num_terms).
Raises
ValueError-
If
durationornum_termsis negative,periodis not positive and finite (0ornanwould cache an all-nanmatrix without an error, andinfa constant one), ornum_termsis larger thanperiod / 2(aliased harmonics).