timesead.models.generative.lstm_vae =================================== .. py:module:: timesead.models.generative.lstm_vae Classes ------- .. autoapisummary:: timesead.models.generative.lstm_vae.RNNVAEGaussianEncoder timesead.models.generative.lstm_vae.LSTMVAE timesead.models.generative.lstm_vae.LSTMVAESoelch timesead.models.generative.lstm_vae.LSTMVAEPark timesead.models.generative.lstm_vae.VAEAnomalyDetectorSoelch timesead.models.generative.lstm_vae.VAEAnomalyDetectorPark Module Contents --------------- .. py:class:: 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: :py:obj:`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 :meth:`to`, etc. .. note:: As per the example above, an ``__init__()`` call to the parent class must be made before assignment on the child. :ivar training: Boolean represents whether this module is in training or evaluation mode. :vartype training: bool Initialize internal Module state, shared by both nn.Module and ScriptModule. .. py:attribute:: logvar :value: True .. py:attribute:: rnn .. py:attribute:: linear .. py:attribute:: softplus .. py:method:: forward(x: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor] .. py:class:: LSTMVAE(input_dim: int, lstm_hidden_dims: List[int] = [60], latent_dim: int = 20) Bases: :py:obj:`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 :meth:`to`, etc. .. note:: As per the example above, an ``__init__()`` call to the parent class must be made before assignment on the child. :ivar training: Boolean represents whether this module is in training or evaluation mode. :vartype training: bool Base LSTMVAE :param input_dim: :param lstm_hidden_dims: :param latent_dim: .. py:attribute:: latent_dim :value: 20 .. py:attribute:: vae .. py:method:: get_prior(batch_size: int, seq_len: int) -> Tuple[Optional[torch.Tensor], Optional[torch.Tensor]] .. py:method:: forward(inputs: Tuple[torch.Tensor]) -> Tuple[torch.Tensor, Ellipsis] .. py:class:: LSTMVAESoelch(input_dim: int, lstm_hidden_dims: List[int] = [60], latent_dim: int = 20, prior_hidden_dim: int = 40) Bases: :py:obj:`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 :meth:`to`, etc. .. note:: As per the example above, an ``__init__()`` call to the parent class must be made before assignment on the child. :ivar training: Boolean represents whether this module is in training or evaluation mode. :vartype training: bool Sölch2016 :param input_dim: :param lstm_hidden_dims: :param latent_dim: :param prior_hidden_dim: .. py:attribute:: prior_hidden_dim :value: 40 .. py:attribute:: prior_rnn .. py:attribute:: prior_linear .. py:method:: get_prior(batch_size: int, seq_len: int) -> Tuple[Optional[torch.Tensor], Optional[torch.Tensor]] .. py:class:: LSTMVAEPark(input_dim: int, lstm_hidden_dims: List[int] = [60], latent_dim: int = 20, noise_std: float = 0.1) Bases: :py:obj:`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 :meth:`to`, etc. .. note:: As per the example above, an ``__init__()`` call to the parent class must be made before assignment on the child. :ivar training: Boolean represents whether this module is in training or evaluation mode. :vartype training: bool Park2018 :param input_dim: :param lstm_hidden_dims: :param latent_dim: :param noise_std: .. py:attribute:: noise_std :value: 0.1 .. py:attribute:: prior_means .. py:method:: get_prior(batch_size: int, seq_len: int) -> Tuple[Optional[torch.Tensor], Optional[torch.Tensor]] .. py:method:: forward(inputs: Tuple[torch.Tensor]) -> Tuple[torch.Tensor, Ellipsis] .. py:class:: VAEAnomalyDetectorSoelch(model: LSTMVAESoelch) Bases: :py:obj:`timesead.models.common.AnomalyDetector` .. py:attribute:: model .. py:attribute:: loss .. py:method:: compute_online_anomaly_score(inputs: Tuple[torch.Tensor, Ellipsis]) -> torch.Tensor .. py:method:: compute_offline_anomaly_score(inputs: Tuple[torch.Tensor, Ellipsis]) -> torch.Tensor .. py:method:: fit(dataset: torch.utils.data.DataLoader) -> None .. py:method:: format_online_targets(targets: Tuple[torch.Tensor, Ellipsis]) -> torch.Tensor .. py:class:: VAEAnomalyDetectorPark(model: LSTMVAEPark, num_mc_samples: int = 1) Bases: :py:obj:`timesead.models.common.AnomalyDetector` Use sampled log likelihood of data + some thresholding mechanism :param model: :param num_mc_samples: .. py:attribute:: model .. py:attribute:: num_mc_samples :value: 1 .. py:attribute:: svr .. py:method:: compute_threshold(z: torch.Tensor) .. py:method:: compute_online_anomaly_score(inputs: Tuple[torch.Tensor, Ellipsis]) -> torch.Tensor .. py:method:: compute_offline_anomaly_score(inputs: Tuple[torch.Tensor, Ellipsis]) -> torch.Tensor .. py:method:: fit(dataset: torch.utils.data.DataLoader) -> None .. py:method:: format_online_targets(targets: Tuple[torch.Tensor, Ellipsis]) -> torch.Tensor