autopycoin.layers.GenericBlock#

class autopycoin.layers.GenericBlock(*args, **kwargs)[source]#

Generic block definition as described in the paper.

This layer represents the smaller part of a nbeats model. We can’t have explanation from this block because g coefficients are learnt.

Parameters
label_widthint

Horizon time to forecast.

g_forecast_neuronsint

Dimensionality if the gf layer.

g_backcast_neuronsint

Dimensionality if the gb layer.

n_neuronsint

Number of neurons in Fully connected layers.

drop_ratefloat

Rate of the dropout layer. This is used to estimate the epistemic error. Expected a value between 0 and 1. Default to 0.1.

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 GenericBlock
>>> from autopycoin.models import Stack, NBEATS
>>> from autopycoin.losses import QuantileLossError
>>> generic_block = GenericBlock(label_width=10,
...                          n_neurons=16,
...                          g_forecast_neurons=16,
...                          g_backcast_neurons=16,
...                          drop_rate=0.1,
...                          name="generic_block")
>>> generic_blocks = [generic_block for _ in range(3)]
>>> generic_stacks = Stack(generic_blocks, name="generic_stack")
>>> # Model definition and compiling
>>> model = NBEATS([generic_stacks, generic_stacks], name="generic_NBEATS")
Attributes
label_widthint

Return the label_width.

input_widthint

Return the input_width.

input_specInputSpec

InputSpec instance(s) describing the input format for this layer.

drop_ratefloat

Return the drop rate.

coefficient_factory(output_last_dim: int, neurons: int) tensorflow.python.framework.ops.Tensor[source]#

Compute the coefficients used in the last layer a.k.a g layer. This function is used in _get_forecast_coefficients and _get_backcast_coefficients.

Parameters
output_last_dimint
neuronsint
Returns
coefficientstensor with shape (label_width, neurons)

Coefficients of the g layer.

property g_backcast_neurons#

Return the dimension of the gb layer.

property g_forecast_neurons#

Return the dimension of the gf layer.

get_coefficients(output_last_dim: int, branch_name: str) tensorflow.python.framework.ops.Tensor[source]#

Return the coefficients used in forecast and backcast layer a.k.a g layer.

Parameters
output_last_dimint
branch_namestr
Returns
coefficients: Tensor of shape (d0, …, label_width)