deepdow.layers.transform module

Collection of layers focusing on transforming tensors while keeping the number of dimensions constant.

class Conv(n_input_channels, n_output_channels, kernel_size=3, method='2D')[source]

Bases: torch.nn.modules.module.Module

Convolutional layer.

Parameters
  • n_input_channels (int) – Number of input channels.

  • n_output_channels (int) – Number of output channels.

  • kernel_size (int) – Size of the kernel.

  • method (str, {'2D, '1D'}) – What type of convolution is used in the background.

forward(x)[source]

Perform forward pass.

Parameters

x (torch.Tensor) – Tensor of shape (n_samples, n_input_channels, lookback, n_assets) if `self.method=’2D’. Otherwise (n_samples, n_input_channels, lookback).

Returns

Tensor of shape (n_samples, n_output_channels, lookback, n_assets) if self.method=’2D’. Otherwise (n_samples, n_output_channels, lookback).

Return type

torch.Tensor

class RNN(n_channels, hidden_size, cell_type='LSTM', bidirectional=True, n_layers=1)[source]

Bases: torch.nn.modules.module.Module

Recurrent neural network layer.

Parameters
  • n_channels (int) – Number of input channels.

  • hidden_size (int) – Hidden state size. Alternatively one can see it as number of output channels.

  • cell_type (str, {'LSTM', 'RNN'}) – Type of the recurrent cell.

  • bidirectional (bool) – If True, then bidirectional. Note that hidden_size already takes this parameter into account.

  • n_layers (int) – Number of stacked layers.

forward(x)[source]

Perform forward pass.

Parameters

x (torch.Tensor) – Tensor of shape (n_samples, n_channels, lookback, n_assets).

Returns

Tensor of shape (n_samples, self.hidden_size, lookback, n_assets).

Return type

torch.Tensor