timesead.models.generative.lstm_vae

Classes

RNNVAEGaussianEncoder

Base class for all neural network modules.

LSTMVAE

Base class for all neural network modules.

LSTMVAESoelch

Base class for all neural network modules.

LSTMVAEPark

Base class for all neural network modules.

VAEAnomalyDetectorSoelch

VAEAnomalyDetectorPark

Use sampled log likelihood of data + some thresholding mechanism

Module Contents

class timesead.models.generative.lstm_vae.RNNVAEGaussianEncoder(input_dim: int, rnn_type: str = 'lstm', rnn_hidden_dims: List[int] = [60], latent_dim: int = 10, bidirectional: bool = False, mode: str = 's2s', logvar_out: bool = True)

Bases: torch.nn.Module

Base class for all neural network modules.

Your models should also subclass this class.

Modules can also contain other Modules, allowing them to be nested in a tree structure. You can assign the submodules as regular attributes:

import torch.nn as nn
import torch.nn.functional as F

class Model(nn.Module):
    def __init__(self) -> None:
        super().__init__()
        self.conv1 = nn.Conv2d(1, 20, 5)
        self.conv2 = nn.Conv2d(20, 20, 5)

    def forward(self, x):
        x = F.relu(self.conv1(x))
        return F.relu(self.conv2(x))

Submodules assigned in this way will be registered, and will also have their parameters converted when you call to(), etc.

Note

As per the example above, an __init__() call to the parent class must be made before assignment on the child.

Variables:

training (bool) – Boolean represents whether this module is in training or evaluation mode.

Parameters:
  • input_dim (int)

  • rnn_type (str)

  • rnn_hidden_dims (List[int])

  • latent_dim (int)

  • bidirectional (bool)

  • mode (str)

  • logvar_out (bool)

Initialize internal Module state, shared by both nn.Module and ScriptModule.

logvar = True
rnn
linear
softplus
forward(x: torch.Tensor) Tuple[torch.Tensor, torch.Tensor]
Parameters:

x (torch.Tensor)

Return type:

Tuple[torch.Tensor, torch.Tensor]

class timesead.models.generative.lstm_vae.LSTMVAE(input_dim: int, lstm_hidden_dims: List[int] = [60], latent_dim: int = 20)

Bases: timesead.models.BaseModel

Base class for all neural network modules.

Your models should also subclass this class.

Modules can also contain other Modules, allowing them to be nested in a tree structure. You can assign the submodules as regular attributes:

import torch.nn as nn
import torch.nn.functional as F

class Model(nn.Module):
    def __init__(self) -> None:
        super().__init__()
        self.conv1 = nn.Conv2d(1, 20, 5)
        self.conv2 = nn.Conv2d(20, 20, 5)

    def forward(self, x):
        x = F.relu(self.conv1(x))
        return F.relu(self.conv2(x))

Submodules assigned in this way will be registered, and will also have their parameters converted when you call to(), etc.

Note

As per the example above, an __init__() call to the parent class must be made before assignment on the child.

Variables:

training (bool) – Boolean represents whether this module is in training or evaluation mode.

Parameters:
  • input_dim (int)

  • lstm_hidden_dims (List[int])

  • latent_dim (int)

Base LSTMVAE

Parameters:
  • input_dim (int)

  • lstm_hidden_dims (List[int])

  • latent_dim (int)

latent_dim = 20
vae
get_prior(batch_size: int, seq_len: int) Tuple[torch.Tensor | None, torch.Tensor | None]
Parameters:
  • batch_size (int)

  • seq_len (int)

Return type:

Tuple[Optional[torch.Tensor], Optional[torch.Tensor]]

forward(inputs: Tuple[torch.Tensor]) Tuple[torch.Tensor, Ellipsis]
Parameters:

inputs (Tuple[torch.Tensor])

Return type:

Tuple[torch.Tensor, Ellipsis]

class timesead.models.generative.lstm_vae.LSTMVAESoelch(input_dim: int, lstm_hidden_dims: List[int] = [60], latent_dim: int = 20, prior_hidden_dim: int = 40)

Bases: LSTMVAE

Base class for all neural network modules.

Your models should also subclass this class.

Modules can also contain other Modules, allowing them to be nested in a tree structure. You can assign the submodules as regular attributes:

import torch.nn as nn
import torch.nn.functional as F

class Model(nn.Module):
    def __init__(self) -> None:
        super().__init__()
        self.conv1 = nn.Conv2d(1, 20, 5)
        self.conv2 = nn.Conv2d(20, 20, 5)

    def forward(self, x):
        x = F.relu(self.conv1(x))
        return F.relu(self.conv2(x))

Submodules assigned in this way will be registered, and will also have their parameters converted when you call to(), etc.

Note

As per the example above, an __init__() call to the parent class must be made before assignment on the child.

Variables:

training (bool) – Boolean represents whether this module is in training or evaluation mode.

Parameters:
  • input_dim (int)

  • lstm_hidden_dims (List[int])

  • latent_dim (int)

  • prior_hidden_dim (int)

Sölch2016

Parameters:
  • input_dim (int)

  • lstm_hidden_dims (List[int])

  • latent_dim (int)

  • prior_hidden_dim (int)

prior_hidden_dim = 40
prior_rnn
prior_linear
get_prior(batch_size: int, seq_len: int) Tuple[torch.Tensor | None, torch.Tensor | None]
Parameters:
  • batch_size (int)

  • seq_len (int)

Return type:

Tuple[Optional[torch.Tensor], Optional[torch.Tensor]]

class timesead.models.generative.lstm_vae.LSTMVAEPark(input_dim: int, lstm_hidden_dims: List[int] = [60], latent_dim: int = 20, noise_std: float = 0.1)

Bases: LSTMVAE

Base class for all neural network modules.

Your models should also subclass this class.

Modules can also contain other Modules, allowing them to be nested in a tree structure. You can assign the submodules as regular attributes:

import torch.nn as nn
import torch.nn.functional as F

class Model(nn.Module):
    def __init__(self) -> None:
        super().__init__()
        self.conv1 = nn.Conv2d(1, 20, 5)
        self.conv2 = nn.Conv2d(20, 20, 5)

    def forward(self, x):
        x = F.relu(self.conv1(x))
        return F.relu(self.conv2(x))

Submodules assigned in this way will be registered, and will also have their parameters converted when you call to(), etc.

Note

As per the example above, an __init__() call to the parent class must be made before assignment on the child.

Variables:

training (bool) – Boolean represents whether this module is in training or evaluation mode.

Parameters:
  • input_dim (int)

  • lstm_hidden_dims (List[int])

  • latent_dim (int)

  • noise_std (float)

Park2018

Parameters:
  • input_dim (int)

  • lstm_hidden_dims (List[int])

  • latent_dim (int)

  • noise_std (float)

noise_std = 0.1
prior_means
get_prior(batch_size: int, seq_len: int) Tuple[torch.Tensor | None, torch.Tensor | None]
Parameters:
  • batch_size (int)

  • seq_len (int)

Return type:

Tuple[Optional[torch.Tensor], Optional[torch.Tensor]]

forward(inputs: Tuple[torch.Tensor]) Tuple[torch.Tensor, Ellipsis]
Parameters:

inputs (Tuple[torch.Tensor])

Return type:

Tuple[torch.Tensor, Ellipsis]

class timesead.models.generative.lstm_vae.VAEAnomalyDetectorSoelch(model: LSTMVAESoelch)

Bases: timesead.models.common.AnomalyDetector

Parameters:

model (LSTMVAESoelch)

model
loss
compute_online_anomaly_score(inputs: Tuple[torch.Tensor, Ellipsis]) torch.Tensor
Parameters:

inputs (Tuple[torch.Tensor, Ellipsis])

Return type:

torch.Tensor

compute_offline_anomaly_score(inputs: Tuple[torch.Tensor, Ellipsis]) torch.Tensor
Parameters:

inputs (Tuple[torch.Tensor, Ellipsis])

Return type:

torch.Tensor

fit(dataset: torch.utils.data.DataLoader) None
Parameters:

dataset (torch.utils.data.DataLoader)

Return type:

None

format_online_targets(targets: Tuple[torch.Tensor, Ellipsis]) torch.Tensor
Parameters:

targets (Tuple[torch.Tensor, Ellipsis])

Return type:

torch.Tensor

class timesead.models.generative.lstm_vae.VAEAnomalyDetectorPark(model: LSTMVAEPark, num_mc_samples: int = 1)

Bases: timesead.models.common.AnomalyDetector

Use sampled log likelihood of data + some thresholding mechanism

Parameters:
model
num_mc_samples = 1
svr
compute_threshold(z: torch.Tensor)
Parameters:

z (torch.Tensor)

compute_online_anomaly_score(inputs: Tuple[torch.Tensor, Ellipsis]) torch.Tensor
Parameters:

inputs (Tuple[torch.Tensor, Ellipsis])

Return type:

torch.Tensor

compute_offline_anomaly_score(inputs: Tuple[torch.Tensor, Ellipsis]) torch.Tensor
Parameters:

inputs (Tuple[torch.Tensor, Ellipsis])

Return type:

torch.Tensor

fit(dataset: torch.utils.data.DataLoader) None
Parameters:

dataset (torch.utils.data.DataLoader)

Return type:

None

format_online_targets(targets: Tuple[torch.Tensor, Ellipsis]) torch.Tensor
Parameters:

targets (Tuple[torch.Tensor, Ellipsis])

Return type:

torch.Tensor