nn Submodule

class torchcast.nn.EncoderDecoderTransformer(in_dim: int, hidden_dim: int, out_dim: int, num_encoder_layers: int, num_decoder_layers: int, exogenous_dim: int = 0, num_heads: int = 8, one_hot_encode_nan_inputs: bool = False, dropout: float = 0.1, embedding: ~torch.nn.modules.module.Module | None = None, norm: ~typing.Callable = <class 'torchcast.nn.layers.TimeLastLayerNorm'>)

Provides a complete encoder-decoder transformer network for time series forecasting.

class torchcast.nn.EncoderTransformer(in_dim: int, hidden_dim: int, out_dim: int, num_encoder_layers: int, num_classes: int = 0, exogenous_dim: int = 0, num_heads: int = 8, one_hot_encode_nan_inputs: bool = False, dropout: float = 0.1, embedding: ~torch.nn.modules.module.Module | None = None, norm: ~typing.Callable = <class 'torchcast.nn.layers.TimeLastLayerNorm'>)

Provides a complete encoder-only transformer network for time series forecasting.

class torchcast.nn.NaNEncoder(*args, **kwargs)

This module replaces NaN values in tensors with zeros, and appends a mask along the channel dimension specifying which values were NaNs, doubling the number of channels. It is used as a preprocessing step.

class torchcast.nn.TimeLastLayerNorm(normalized_shape: int | List[int] | Size, eps: float = 1e-05, elementwise_affine: bool = True, bias: bool = True, device=None, dtype=None)

This is an implementation of layer norm that expects the tensor to have the channel dimension as the 1st dimension instead of the last dimension, and the time as the last dimension instead of the 1st.

Criteria

We provide a collection of criteria classes that allow the target (or prediction) to be a NaN, and treat the loss on NaNs as zeros.

class torchcast.nn.L1Loss(reduction: str = 'mean')

This is an L1 loss that ignores NaN values.

class torchcast.nn.MSELoss(reduction: str = 'mean')

This is a mean-squared error loss that ignores NaN values.

class torchcast.nn.SmoothL1Loss(reduction: str = 'mean', beta: float = 1.0)

This is a smooth L1 loss that ignores NaN values.

Time Embeddings

Time embeddings are used to attach the time to each token in the input. They expect to be provided both the current tokens and the times of each token.

class torchcast.nn.JointEmbedding(modules: Iterable[Module] | None = None)

This takes a list of multiple time embeddings and applies them sequentially to the input sequence.

class torchcast.nn.PositionEmbedding(dim: int, scale: int = 1)

This layer attaches a positional embedding to the input sequence.

class torchcast.nn.TimeEmbedding(dim: int, frequencies: Iterable[str | int])

This layer attaches a temporal embedding to the input sequence.