autopycoin.layers.TrendBlock#
- class autopycoin.layers.TrendBlock(*args, **kwargs)[source]#
Trend block definition.
This layer represents the smaller part of the nbeats model. Final layers are constrained which define a polynomial function of small degree p. Therefore it is possible to get explanation from this block.
- Parameters
- Raises
ValueErrordrop_rate is not between 0 and 1. 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 = NBEATS([trend_stacks, seasonality_stacks], name="interpretable_NBEATS")
- Attributes
label_widthintReturn the label_width.
input_widthintReturn the input_width.
p_degreeintReturn the degree of the trend equation.
input_specÌnputSpecInputSpec instance(s) describing the input format for this layer.
drop_ratefloatReturn the drop rate.
is_interpretableboolReturn True if the block is interpretable.
is_g_trainableboolReturn True if the last layer is trainable.
block_typestrReturn the block type.
- coefficient_factory(output_last_dim: int, p_degrees: tensorflow.python.framework.ops.Tensor) tensorflow.python.framework.ops.Tensor[source]#
Compute the coefficients used in the last layer a.k.a g layer.
- Parameters
- output_last_dim
int - p_degree: int
- output_last_dim
- Returns
- coefficientstensor with shape (p_degree, label_width)
Coefficients of the g layer.