autopycoin.layers.SeasonalityBlock#
- class autopycoin.layers.SeasonalityBlock(*args, **kwargs)[source]#
Seasonality block definition.
This layer represents the smaller part of nbeats model. Its internal layers are defining a fourier series. We introduced notion of fourier orders and seasonality periods which is not used in the original paper. It is possible to get explanation from this block.
- Parameters
- label_width
int Horizon time to forecast.
- forecast_periods
int|float|List[int|float] Defines the periods used in the fourier equation. Default to label_width/2 as describe in the original paper.
- backcast_periods
int|float|List[int|float] Compute the fourier serie period in the backcasting equation. Default to input_width/2 as describe in the original paper.
- forecast_fourier_order
int|float|List[int|float] Compute the fourier orders. Each element is the order of its respective period. Default to label_width/2 as describe in the original paper.
- backcast_fourier_order
int|float|List[int|float] Compute the fourier orders. Each element is the order of its respective back period. Default to input_width/2 as describe in the original paper.
- n_neurons
int Number of neurons in the fully connected layers.
- drop_rate
float Rate of the dropout layer. This is used to estimate the epistemic error. Expected a value between 0 and 1. Default to 0.
- label_width
- Raises
- ValueError:
drop_rate not between 0 and 1. periods and forecast_fourier_order or their elements are not strictly positive values back_periods and backcast_fourier_order or their elements are not strictly positive values backcast_fourier_order and forecast_fourier_order don’t have the same length. all others arguments are not strictly positive integers.
Notes
input shape: N-D tensor with shape: (…, batch_size, time step). The most common situation would be a 2D input with shape (batch_size, time step).
output shape: N-D tensor with shape: (…, batch_size, units). For instance, for a 2D input with shape (batch_size, units), the output would have shape (batch_size, units). With a QuantileLossError with 2 quantiles or higher the output would have shape (quantiles, batch_size, units). If you add 2 variables, the output would have shape (variables, quantiles, batch_size, units).
Examples
>>> from autopycoin.layers import TrendBlock, SeasonalityBlock >>> from autopycoin.models import Stack, NBEATS >>> from autopycoin.losses import QuantileLossError >>> trend_block = TrendBlock(label_width=10, ... p_degree=2, ... n_neurons=16, ... drop_rate=0.1, ... name="trend_block") >>> seasonality_block = SeasonalityBlock(label_width=10, ... forecast_periods=[10], ... backcast_periods=[20], ... forecast_fourier_order=[10], ... backcast_fourier_order=[20], ... n_neurons=15, ... drop_rate=0.1, ... name="seasonality_block") >>> trend_blocks = [trend_block for _ in range(3)] >>> seasonality_blocks = [seasonality_block for _ in range(3)] >>> trend_stacks = Stack(trend_blocks, name="trend_stack") >>> seasonality_stacks = Stack(seasonality_blocks, name="seasonality_stack") >>> # model definition and compiling >>> model = NBEATS([trend_stacks, seasonality_stacks], name="interpretable_NBEATS")
- Attributes
label_widthintReturn the label_width.
input_widthintReturn the input_width.
input_specInputSpecInputSpec instance(s) describing the input format for this layer.
drop_ratefloatReturn the drop rate.
- periods
int|float|list[int|float] - back_periods
int|float|list[int|float] if not provided, then it is set during build method.
forecast_fourier_orderint|float|list[int|float]Return fourier order.
backcast_fourier_orderint|float|list[int|float]Return fourier order.