autopycoin.models.Stack#
- class autopycoin.models.Stack(*args, **kwargs)[source]#
A stack is a series of blocks where each block produces two outputs, the forecast and the backcast.
Inside a stack all forecasts are sum up and compose the stack output. In the meantime, the backcast is given to the following block.
- Parameters
- blocks
tuple[autopycoin.models.BaseBlock] Blocks layers. they can be generic, seasonal or trend ones. You can also define your own block by subclassing BaseBlock.
- blocks
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=20, ... p_degree=2, ... n_neurons=16, ... drop_rate=0.1, ... name="trend_block") ... >>> seasonality_block = SeasonalityBlock(label_width=20, ... forecast_periods=[10], ... backcast_periods=[20], ... forecast_fourier_order=[10], ... backcast_fourier_order=[20], ... n_neurons=15, ... drop_rate=0.1, ... name="seasonality_block") ... ... # blocks creation >>> trend_blocks = [trend_block for _ in range(3)] >>> seasonality_blocks = [seasonality_block for _ in range(3)] ... ... # Stacks creation >>> 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") >>> model.compile(loss=QuantileLossError(quantiles=[0.5]))
- Attributes
blockstuple[autopycoin.models.BaseBlock]Return the list of blocks.
label_widthintReturn the label width.
input_widthintReturn the input width.
is_interpretableboolReturn True if the stack is interpretable.
stack_typestrReturn the type of the stack.
- property blocks: List[autopycoin.layers.nbeats_layers.BaseBlock]#
Return the list of blocks.