<filename>rvagene/encoder.py
## citation : https://github.com/tejaslodaya/timeseries-clustering-vae

from torch import nn

class Encoder(nn.Module):
    """
    Encoder network containing enrolled LSTM
    :param number_of_features: number of input features
    :param hidden_size: hidden size of the RNN
    :param hidden_layer_depth: number of layers in RNN
    :param latent_length: latent vector length
    :param dropout: percentage of nodes to dropout
    """
    def __init__(self, number_of_features, hidden_size, hidden_layer_depth, latent_length, dropout, block = 'LSTM'):

        super(Encoder, self).__init__()

        self.number_of_features = number_of_features
        self.hidden_size = hidden_size
        self.hidden_layer_depth = hidden_layer_depth
        self.latent_length = latent_length

        if block == 'LSTM':
            self.model = nn.LSTM(self.number_of_features, self.hidden_size, self.hidden_layer_depth, dropout = dropout)
        else:
            raise NotImplementedError

    def forward(self, x):
        """Forward propagation of encoder. Given input, outputs the last hidden state of encoder

        :param x: input to the encoder, of shape (sequence_length, batch_size, number_of_features)
        :return: last hidden state of encoder, of shape (batch_size, hidden_size)
        """

        _, (h_end, c_end) = self.model(x)

        h_end = h_end[0, :, :]
        return h_end

<filename>rvagene/encoder.py
## citation : https://github.com/tejaslodaya/timeseries-clustering-vae

from torch import nn

class Encoder(nn.Module):
    """
    Encoder network containing enrolled LSTM
    :param number_of_features: number of input features
    :param hidden_size: hidden size of the RNN
    :param hidden_layer_depth: number of layers in RNN
    :param latent_length: latent vector length
    :param dropout: percentage of nodes to dropout
    """
    def __init__(self, number_of_features, hidden_size, hidden_layer_depth, latent_length, dropout, block = 'LSTM'):

        super(Encoder, self).__init__()

        self.number_of_features = number_of_features
        self.hidden_size = hidden_size
        self.hidden_layer_depth = hidden_layer_depth
        self.latent_length = latent_length

        if block == 'LSTM':
            self.model = nn.LSTM(self.number_of_features, self.hidden_size, self.hidden_layer_depth, dropout = dropout)
        else:
            raise NotImplementedError

    def forward(self, x):
        """Forward propagation of encoder. Given input, outputs the last hidden state of encoder

        :param x: input to the encoder, of shape (sequence_length, batch_size, number_of_features)
        :return: last hidden state of encoder, of shape (batch_size, hidden_size)
        """

        _, (h_end, c_end) = self.model(x)

        h_end = h_end[0, :, :]
        return h_end

## citation : https://github.com/tejaslodaya/timeseries-clustering-vae Encoder network containing enrolled LSTM     :param number_of_features: number of input features     :param hidden_size: hidden size of the RNN     :param hidden_layer_depth: number of layers in RNN     :param latent_length: latent vector length     :param dropout: percentage of nodes to dropout Forward propagation of encoder. Given input, outputs the last hidden state of encoder          :param x: input to the encoder, of shape (sequence_length, batch_size, number_of_features)         :return: last hidden state of encoder, of shape (batch_size, hidden_size)