timesead.models.generative ========================== .. py:module:: timesead.models.generative Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/timesead/models/generative/beatgan/index /autoapi/timesead/models/generative/donut/index /autoapi/timesead/models/generative/gru_gmm_vae/index /autoapi/timesead/models/generative/lstm_vae/index /autoapi/timesead/models/generative/lstm_vae_gan/index /autoapi/timesead/models/generative/madgan/index /autoapi/timesead/models/generative/omni_anomaly/index /autoapi/timesead/models/generative/sis_vae/index /autoapi/timesead/models/generative/tadgan/index Classes ------- .. autoapisummary:: timesead.models.generative.BeatGANModel timesead.models.generative.BeatGANGeneratorLoss timesead.models.generative.BeatGANDiscriminatorLoss timesead.models.generative.BeatGANReconstructionAnomalyDetector timesead.models.generative.WrapAugmentTransform timesead.models.generative.Donut timesead.models.generative.MaskedVAELoss timesead.models.generative.DonutAnomalyDetector timesead.models.generative.GRUGMMVAE timesead.models.generative.GMMVAELoss timesead.models.generative.GMMVAEAnomalyDetector timesead.models.generative.LSTMVAE timesead.models.generative.LSTMVAEPark timesead.models.generative.LSTMVAESoelch timesead.models.generative.VAEAnomalyDetectorPark timesead.models.generative.VAEAnomalyDetectorSoelch timesead.models.generative.RNNVAEGaussianEncoder timesead.models.generative.LSTMVAEGAN timesead.models.generative.LSTMVAEGANTrainer timesead.models.generative.LSTMVAEGANAnomalyDetector timesead.models.generative.MADGAN timesead.models.generative.MADGANTrainer timesead.models.generative.MADGANAnomalyDetector timesead.models.generative.OmniAnomaly timesead.models.generative.OmniAnomalyLoss timesead.models.generative.OmniAnomalyDetector timesead.models.generative.SISVAE timesead.models.generative.SISVAELossWithGeneratedPrior timesead.models.generative.SISVAEAnomalyDetector timesead.models.generative.TADGAN timesead.models.generative.TADGANGeneratorLoss timesead.models.generative.TADGANTrainer timesead.models.generative.TADGANAnomalyDetector Package Contents ---------------- .. py:class:: BeatGANModel(input_dim: int, conv_filters: int = 32, latent_dim: int = 50, last_kernel_size: int = 10) Bases: :py:obj:`timesead.models.BaseModel`, :py:obj:`timesead.models.common.GAN` 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:method:: forward(inputs: Tuple[torch.Tensor, Ellipsis]) -> Tuple[torch.Tensor, Ellipsis] .. py:method:: grouped_parameters() -> Tuple[Iterator[torch.nn.Parameter], Ellipsis] .. py:class:: BeatGANGeneratorLoss(adversarial_weight: float = 1.0) Bases: :py:obj:`timesead.optim.loss.Loss` 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:: adversarial_weight :value: 1.0 .. py:attribute:: mse_loss .. py:method:: forward(predictions: Tuple[torch.Tensor, Ellipsis], targets: Tuple[torch.Tensor, Ellipsis], *args, **kwargs) -> torch.Tensor .. py:class:: BeatGANDiscriminatorLoss Bases: :py:obj:`timesead.models.common.GANDiscriminatorLoss` .. py:method:: forward(predictions: Tuple[torch.Tensor, Ellipsis], targets: Tuple[torch.Tensor, Ellipsis], *args, **kwargs) -> torch.Tensor .. py:class:: BeatGANReconstructionAnomalyDetector(model: BeatGANModel) Bases: :py:obj:`timesead.models.common.MSEReconstructionAnomalyDetector` .. 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 :abstractmethod: .. py:class:: WrapAugmentTransform(parent: timesead.data.transforms.Transform, distort_fraction: float = 0.05, n_augmentations: int = 1) Bases: :py:obj:`timesead.data.transforms.Transform` Implements BeatGANs time-series distortion. This should be applied after windowing. :param parent: This transform's parent. :param distort_fraction: Fraction of time points that should be distorted. Note that 2 distortions are applied, so in the end distor_fraction*2 data points will be distorted :param n_data_augmentations: For each original time-series in parent, this will produce n_data_augmentations additional augmented time series .. py:attribute:: distort_fraction :value: 0.05 .. py:attribute:: n_augmentations :value: 1 .. py:method:: aug_ts(x: torch.Tensor) -> torch.Tensor .. py:method:: __len__() -> int .. py:class:: Donut(input_dim: int, hidden_dims: List[int] = [100, 100], latent_dim: int = 20, mask_prob: float = 0.01) 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 Xu2018 :param input_dim: Should be window_size * features :param hidden_dims: :param latent_dim: .. py:attribute:: latent_dim :value: 20 .. py:attribute:: mask_prob :value: 0.01 .. py:attribute:: vae .. py:method:: forward(inputs: Tuple[torch.Tensor]) -> Tuple[torch.Tensor, Ellipsis] .. py:class:: MaskedVAELoss(size_average=None, reduce=None, reduction: str = 'mean') Bases: :py:obj:`timesead.models.common.VAELoss` .. py:method:: forward(predictions: Tuple[torch.Tensor, Ellipsis], targets: Tuple[torch.Tensor, Ellipsis], *args, **kwargs) -> torch.Tensor .. py:class:: DonutAnomalyDetector(model: Donut, num_mc_samples: int = 1024) Bases: :py:obj:`timesead.models.common.AnomalyDetector` We decided not to include the reconstruction step from the paper here, since we don't have missing data. :param model: :param num_mc_samples: .. py:attribute:: model .. py:attribute:: num_mc_samples :value: 1024 .. 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:: GRUGMMVAE(input_dim: int, gru_hidden_dims: List[int] = [60], latent_dim: int = 8, gmm_components: int = 2) 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 Guo2018 (more or less) :param input_dim: :param gru_hidden_dims: :param latent_dim: .. py:attribute:: latent_dim :value: 8 .. py:attribute:: gmm_components :value: 2 .. py:attribute:: encoder_rnn .. py:attribute:: encoder_component .. py:attribute:: vae .. py:attribute:: prior_means .. py:attribute:: prior_std .. py:attribute:: softplus .. 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:: GMMVAELoss Bases: :py:obj:`timesead.models.common.VAELoss` .. py:method:: forward(predictions: Tuple[torch.Tensor, Ellipsis], targets: Tuple[torch.Tensor, Ellipsis], *args, **kwargs) -> torch.Tensor .. py:class:: GMMVAEAnomalyDetector(model: GRUGMMVAE, num_mc_samples: int = 1) Bases: :py:obj:`timesead.models.common.AnomalyDetector` Use sampled log likelihood of data :param model: :param num_mc_samples: .. py:attribute:: model .. py:attribute:: num_mc_samples :value: 1 .. 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:: 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:: 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:: 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:: 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 .. 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:: 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:: LSTMVAEGAN(input_dim: int, lstm_hidden_dims: List[int] = [60], latent_dim: int = 10) 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 Initialize internal Module state, shared by both nn.Module and ScriptModule. .. py:attribute:: latent_dim :value: 10 .. py:attribute:: encoder .. py:attribute:: decoder .. py:attribute:: discriminator .. py:attribute:: classifier .. py:attribute:: vae .. py:method:: forward(inputs: Tuple[torch.Tensor, Ellipsis]) -> Tuple[torch.Tensor, Ellipsis] .. py:method:: grouped_parameters() -> Tuple[Iterator[inspect.Parameter], Ellipsis] .. py:class:: LSTMVAEGANTrainer(*args, **kwargs) Bases: :py:obj:`timesead.optim.trainer.Trainer` .. py:method:: validate_batch(network: LSTMVAEGAN, val_metrics: Dict[str, Callable], b_inputs: Tuple[torch.Tensor, Ellipsis], b_targets: Tuple[torch.Tensor, Ellipsis], *args, **kwargs) -> Dict[str, float] .. py:method:: train_batch(network: LSTMVAEGAN, losses: List[timesead.optim.loss.Loss], optimizers: List[torch.optim.Optimizer], epoch: int, num_epochs: int, b_inputs: Tuple[torch.Tensor, Ellipsis], b_targets: Tuple[torch.Tensor, Ellipsis]) -> List[float] .. py:class:: LSTMVAEGANAnomalyDetector(model: LSTMVAEGAN, alpha: float = 0.5) Bases: :py:obj:`timesead.models.common.AnomalyDetector` .. py:attribute:: model .. py:attribute:: alpha :value: 0.5 .. py:method:: fit(dataset: torch.utils.data.DataLoader) -> None .. 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 :abstractmethod: .. py:method:: format_online_targets(targets: Tuple[torch.Tensor, Ellipsis]) -> torch.Tensor .. py:class:: MADGAN(input_dim: int, latent_dim: int = 15, generator_hidden_dims: List[int] = [100, 100, 100], discriminator_hidden_dims: List[int] = [100]) Bases: :py:obj:`timesead.models.common.GAN`, :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 Initialize internal Module state, shared by both nn.Module and ScriptModule. .. py:attribute:: latent_dim :value: 15 .. py:method:: grouped_parameters() -> Tuple[Iterator[torch.nn.Parameter], Ellipsis] .. py:class:: MADGANTrainer(*args, disc_iterations: int = 1, gen_iterations: int = 3, **kwargs) Bases: :py:obj:`timesead.optim.trainer.Trainer` .. py:attribute:: disc_iterations :value: 1 .. py:attribute:: gen_iterations :value: 3 .. py:method:: validate_batch(network: MADGAN, val_metrics: Dict[str, Callable], b_inputs: Tuple[torch.Tensor, Ellipsis], b_targets: Tuple[torch.Tensor, Ellipsis], *args, **kwargs) -> Dict[str, float] .. py:method:: train_batch(network: MADGAN, losses: List[timesead.optim.loss.Loss], optimizers: List[torch.optim.Optimizer], epoch: int, num_epochs: int, b_inputs: Tuple[torch.Tensor, Ellipsis], b_targets: Tuple[torch.Tensor, Ellipsis]) -> List[float] .. py:class:: MADGANAnomalyDetector(model: MADGAN, max_iter: int = 1000, lambder: float = 0.5, rec_error_tolerance: float = 0.1) Bases: :py:obj:`timesead.models.common.AnomalyDetector` .. py:attribute:: model .. py:attribute:: max_iter :value: 1000 .. py:attribute:: lambder :value: 0.5 .. py:attribute:: rec_error_tolerance :value: 0.1 .. py:attribute:: rbf_kernel .. 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:: OmniAnomaly(input_dim: int, latent_dim: int = 3, rnn_hidden_dims: Sequence[int] = (500, ), dense_hidden_dims: Sequence[int] = (500, 500), nf_layers: 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 Initialize internal Module state, shared by both nn.Module and ScriptModule. .. py:attribute:: latent_dim :value: 3 .. py:attribute:: prior .. py:attribute:: enc_rnn .. py:attribute:: encoder_vae .. py:attribute:: latent_nf .. py:attribute:: decoder_rnn .. py:attribute:: decoder_vae .. py:method:: forward(inputs: Tuple[torch.Tensor], num_samples: int = 1) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor, torch.nn.Module, torch.Tensor, torch.Tensor] .. py:class:: OmniAnomalyLoss Bases: :py:obj:`timesead.optim.loss.Loss` 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:method:: forward(predictions: Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor, torch.nn.Module, torch.Tensor, torch.Tensor], targets: Tuple[torch.Tensor, Ellipsis], *args, **kwargs) -> torch.Tensor .. py:class:: OmniAnomalyDetector(model: OmniAnomaly, num_mc_samples: int = 1024) Bases: :py:obj:`timesead.models.common.AnomalyDetector` We decided not to include the reconstruction step from the paper here, since we don't have missing data. :param model: :param num_mc_samples: .. py:attribute:: model .. py:attribute:: num_mc_samples :value: 1024 .. 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:: SISVAE(input_dim: int, rnn_hidden_dim: int = 200, latent_dim: int = 40, x_hidden_dims: List[int] = [100], z_hidden_dims: List[int] = [100], enc_hidden_dims: List[int] = [100], dec_hidden_dims: List[int] = [100], prior_hidden_dims: List[int] = [100]) 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 Li2021, ist aber im Prinzip nur Chung2015 mit einem extra loss term :param input_dim: :param lstm_hidden_dims: :param latent_dim: .. py:attribute:: latent_dim :value: 40 .. py:attribute:: rnn_hidden_dim :value: 200 .. py:attribute:: x_embed .. py:attribute:: z_embed .. py:attribute:: encoder .. py:attribute:: decoder .. py:attribute:: prior_decoder .. py:attribute:: rnn_cell .. py:attribute:: softplus .. py:method:: forward(inputs: Tuple[torch.Tensor]) -> Tuple[torch.Tensor, Ellipsis] .. py:class:: SISVAELossWithGeneratedPrior(smooth_weight: float = 0.5) Bases: :py:obj:`timesead.models.common.VAELoss` .. py:attribute:: smooth_weight :value: 0.5 .. py:method:: forward(predictions: Tuple[torch.Tensor, Ellipsis], targets: Tuple[torch.Tensor, Ellipsis], *args, **kwargs) -> torch.Tensor .. py:class:: SISVAEAnomalyDetector(model: SISVAE, num_mc_samples: int = 128) Bases: :py:obj:`timesead.models.common.AnomalyDetector` We decided not to include the reconstruction step from the paper here, since we don't have missing data. :param model: :param num_mc_samples: .. py:attribute:: model .. py:attribute:: num_mc_samples :value: 128 .. 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:: TADGAN(input_size: int, window_size: int, latent_size: int = 20, enc_lstm_hidden_size: int = 100, gen_lstm_hidden_size: int = 64, disc_conv_filters: int = 64, disc_conv_kernel_size: int = 5, disc_z_hidden_size: int = 20, gen_dropout: float = 0.2, disc_dropout: float = 0.25, disc_z_dropout: float = 0.2) 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 Initialize internal Module state, shared by both nn.Module and ScriptModule. .. py:attribute:: encoder .. py:attribute:: generator .. py:attribute:: discriminatorx .. py:attribute:: discriminatorz .. py:attribute:: gan .. py:attribute:: inverse_gan .. py:attribute:: latent_size :value: 20 .. py:method:: grouped_parameters() -> Tuple[Iterator[torch.nn.Parameter], Ellipsis] .. py:method:: forward(inputs: Tuple[torch.Tensor, Ellipsis]) -> Tuple[torch.Tensor, Ellipsis] .. py:class:: TADGANGeneratorLoss(reconstruction_coeff: float = 10) Bases: :py:obj:`timesead.models.common.WassersteinGeneratorLoss` .. py:attribute:: rec_coeff :value: 10 .. py:attribute:: rec_loss .. py:method:: forward(predictions: Tuple[torch.Tensor, Ellipsis], targets: Tuple[torch.Tensor, Ellipsis], *args, **kwargs) -> torch.Tensor .. py:class:: TADGANTrainer(*args, disc_iterations: int = 5, **kwargs) Bases: :py:obj:`timesead.optim.trainer.Trainer` .. py:attribute:: disc_iterations :value: 5 .. py:method:: validate_batch(network: TADGAN, val_metrics: Dict[str, Callable], b_inputs: Tuple[torch.Tensor, Ellipsis], b_targets: Tuple[torch.Tensor, Ellipsis], *args, **kwargs) -> Dict[str, float] .. py:method:: train_batch(network: TADGAN, losses: List[timesead.optim.loss.Loss], optimizers: List[torch.optim.Optimizer], epoch: int, num_epochs: int, b_inputs: Tuple[torch.Tensor, Ellipsis], b_targets: Tuple[torch.Tensor, Ellipsis]) -> List[float] .. py:class:: TADGANAnomalyDetector(model: TADGAN, alpha: float = 0.5) Bases: :py:obj:`timesead.models.common.AnomalyDetector` .. py:attribute:: model .. py:attribute:: alpha :value: 0.5 .. py:method:: fit(dataset: torch.utils.data.DataLoader) -> None .. 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 :abstractmethod: .. py:method:: format_online_targets(targets: Tuple[torch.Tensor, Ellipsis]) -> torch.Tensor