pymc_forecast.features#
Seasonal feature builders: Fourier design matrices and periodic tiling.
- pymc_forecast.features.fourier_features(time, *, period, num_terms)[source]#
Build a labeled Fourier seasonality design matrix.
- Parameters:
time (
intorarray_like) – Either a Pythonintduration (phases0..duration-1) or an array of numeric time positions (e.g.np.arange(len(index))or fractional day-of-week positions). Only a built-ininttakes the duration branch; anything else (including a NumPy integer scalar) is converted withnp.asarray(time, dtype=float). The positions set the phase; the returned"time"coord carries them.period (
float) – Seasonal period, in the same units astime.num_terms (
int) – Number of harmonics; the output has2 * num_termscolumns.
- Returns:
xarray.DataArray– Dims("time", "fourier")with shape(n, 2 * num_terms). The"time"coord holds the positions (not the data’s time coords) and the"fourier"coord labels each harmonic (sin_1 .. sin_k, cos_1 .. cos_k).- Raises:
ValueError – If
num_terms < 1.
- pymc_forecast.features.periodic_repeat(pattern, duration, *, axis=0, period=None)[source]#
Tile a seasonal pattern to cover
durationtime steps.Works on numpy arrays and on PyTensor variables (e.g. a sampled seasonal latent inside a model). For PyTensor variables the length along
axisis always symbolic, soperiodmust be passed explicitly.- Parameters:
pattern (
numpy.ndarrayorpytensor.tensor.TensorVariable) – The seasonal pattern; its length alongaxisis the period unlessperiodis given.duration (
int) – Target length alongaxis.axis (
int, default0) – Axis to repeat along.period (
int, optional) – Explicit period; only the firstperiodentries ofpatternalongaxisare repeated.Nonereads it from a NumPypattern’s shape; it is required for every PyTensorpattern.
- Returns:
numpy.ndarrayorpytensor.tensor.TensorVariable– The tiled pattern with lengthdurationalongaxis: a NumPy array for a NumPypattern, otherwise a symbolic tensor.- Raises:
ValueError – If
periodisNoneand the length ofpatternalongaxisis symbolic (any PyTensorpattern).