Models Module¶
Here are contained the LSTM models developed for price prediction.
This module contains the architectures for long short term memory neural networks.
Author: Oliver Boom Github Alias: OliverJBoom

class
Foresight.models.
LSTM
(num_features, hidden_dim, dense_hidden, output_dim, batch_size, series_length, device, dropout=0.1, num_layers=2)[source]¶ A Long Short Term Memory network model with an additional dense layer
Parameters:  num_features (int) – The number of features in the dataset
 hidden_dim (int) – The number of neurons in the LSTMs hidden layer/s
 dense_hidden (int) – The number of neurons in the dense layers
 output_dim (int) – The number of neurons in the output layer
 batch_size (int) – The number of items in each batch
 series_length (Int) – The length of the time series
 device (string) – The device to run on (Cpu or CUDA)
 dropout (float) – The probability of dropout
 num_layers (int) – The number of stacked LSTM layers

forward
(x)[source]¶ Forward pass through the neural network
Parameters: x (torch.Tensor) – The input into the network
Initialised the hidden state to be zeros. This clears the hidden state between batches. If you are running a stateful LSTM then this needs to be changed.
To change to a stateful LSTM requires not detaching the backprop and storing the computational graph. This strongly increases runtime and shouldn’t make a big difference. Hence a stateful LSTM was not used.
Parameters: batch_size (string) – The batch size to be zeroed

class
Foresight.models.
LSTM_deeper
(num_features, hidden_dim, dense_hidden, dense_hidden_2, output_dim, batch_size, series_length, device, dropout=0.1, num_layers=2)[source]¶ A Long Short Term Memory network model with two additional dense layers
Parameters:  num_features (int) – The number of features in the dataset
 hidden_dim (int) – The number of neurons in the LSTMs hidden layer/s
 dense_hidden (int) – The number of neurons in the first dense layer
 dense_hidden_2 (int) – The number of neurons in the second dense layer
 output_dim (int) – The number of neurons in the output layer
 batch_size (int) – The number of items in each batch
 series_length (Int) – The length of the time series
 device (string) – The device to run on (Cpu or CUDA)
 dropout (float) – The probability of dropout
 num_layers (int) – The number of stacked LSTM layers

forward
(x)[source]¶ Forward pass through the neural network
Parameters: x (torch.Tensor) – The input into the network
Initialised the hidden state to be zeros. This clears the hidden state between batches. If you are running a stateful LSTM then this needs to be changed.
To change to a stateful LSTM requires not detaching the backprop and storing the computational graph. This strongly increases runtime and shouldn’t make a big difference. Hence a stateful LSTM was not used.
Parameters: batch_size (string) – The batch size to be zeroed

class
Foresight.models.
LSTM_shallow
(num_features, hidden_dim, output_dim, batch_size, series_length, device, dropout=0.1, num_layers=2)[source]¶ A Long Short Term Memory network model that passes staight from the LSTM layer to predictions
Parameters:  num_features (int) – The number of features in the dataset
 hidden_dim (int) – The number of neurons in the LSTMs hidden layer/s
 output_dim (int) – The number of neurons in the output layer
 batch_size (int) – The number of items in each batch
 series_length (Int) – The length of the time series
 device (string) – The device to run on (Cpu or CUDA)
 dropout (float) – The probability of dropout
 num_layers (int) – The number of stacked LSTM layers

forward
(x)[source]¶ Forward pass through the neural network
Parameters: x (torch.Tensor) – The input into the network
Initialised the hidden state to be zeros. This clears the hidden state between batches. If you are running a stateful LSTM then this needs to be changed.
To change to a stateful LSTM requires not detaching the backprop and storing the computational graph. This strongly increases runtime and shouldn’t make a big difference. Hence a stateful LSTM was not used.
Parameters: batch_size (string) – The batch size to be zeroed