timesead.models.generative

Submodules

Classes

BeatGANModel

Base class for all neural network modules.

BeatGANGeneratorLoss

Base class for all neural network modules.

BeatGANDiscriminatorLoss

BeatGANReconstructionAnomalyDetector

WrapAugmentTransform

Implements BeatGANs time-series distortion. This should be applied after windowing.

Donut

Base class for all neural network modules.

MaskedVAELoss

DonutAnomalyDetector

We decided not to include the reconstruction step from the paper here, since we don't have missing data.

GRUGMMVAE

Base class for all neural network modules.

GMMVAELoss

GMMVAEAnomalyDetector

Use sampled log likelihood of data

LSTMVAE

Base class for all neural network modules.

LSTMVAEPark

Base class for all neural network modules.

LSTMVAESoelch

Base class for all neural network modules.

VAEAnomalyDetectorPark

Use sampled log likelihood of data + some thresholding mechanism

VAEAnomalyDetectorSoelch

RNNVAEGaussianEncoder

Base class for all neural network modules.

LSTMVAEGAN

Base class for all neural network modules.

LSTMVAEGANTrainer

LSTMVAEGANAnomalyDetector

MADGAN

Base class for all neural network modules.

MADGANTrainer

MADGANAnomalyDetector

OmniAnomaly

Base class for all neural network modules.

OmniAnomalyLoss

Base class for all neural network modules.

OmniAnomalyDetector

We decided not to include the reconstruction step from the paper here, since we don't have missing data.

SISVAE

Base class for all neural network modules.

SISVAELossWithGeneratedPrior

SISVAEAnomalyDetector

We decided not to include the reconstruction step from the paper here, since we don't have missing data.

TADGAN

Base class for all neural network modules.

TADGANGeneratorLoss

TADGANTrainer

TADGANAnomalyDetector

Package Contents

class timesead.models.generative.BeatGANModel(input_dim: int, conv_filters: int = 32, latent_dim: int = 50, last_kernel_size: int = 10)

Bases: timesead.models.BaseModel, 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 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)

  • conv_filters (int)

  • latent_dim (int)

  • last_kernel_size (int)

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

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

inputs (Tuple[torch.Tensor, Ellipsis])

Return type:

Tuple[torch.Tensor, Ellipsis]

grouped_parameters() Tuple[Iterator[torch.nn.Parameter], Ellipsis]
Return type:

Tuple[Iterator[torch.nn.Parameter], Ellipsis]

class timesead.models.generative.BeatGANGeneratorLoss(adversarial_weight: float = 1.0)

Bases: 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 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:

adversarial_weight (float)

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

adversarial_weight = 1.0
mse_loss
forward(predictions: Tuple[torch.Tensor, Ellipsis], targets: Tuple[torch.Tensor, Ellipsis], *args, **kwargs) torch.Tensor
Parameters:
Return type:

torch.Tensor

class timesead.models.generative.BeatGANDiscriminatorLoss

Bases: timesead.models.common.GANDiscriminatorLoss

forward(predictions: Tuple[torch.Tensor, Ellipsis], targets: Tuple[torch.Tensor, Ellipsis], *args, **kwargs) torch.Tensor
Parameters:
Return type:

torch.Tensor

class timesead.models.generative.BeatGANReconstructionAnomalyDetector(model: BeatGANModel)

Bases: timesead.models.common.MSEReconstructionAnomalyDetector

Parameters:

model (BeatGANModel)

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

inputs (Tuple[torch.Tensor, Ellipsis])

Return type:

torch.Tensor

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

inputs (Tuple[torch.Tensor, Ellipsis])

Return type:

torch.Tensor

class timesead.models.generative.WrapAugmentTransform(parent: timesead.data.transforms.Transform, distort_fraction: float = 0.05, n_augmentations: int = 1)

Bases: timesead.data.transforms.Transform

Implements BeatGANs time-series distortion. This should be applied after windowing.

Parameters:
  • parent (timesead.data.transforms.Transform) – This transform’s parent.

  • distort_fraction (float) – 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

  • n_data_augmentations – For each original time-series in parent, this will produce n_data_augmentations additional augmented time series

  • n_augmentations (int)

distort_fraction = 0.05
n_augmentations = 1
aug_ts(x: torch.Tensor) torch.Tensor
Parameters:

x (torch.Tensor)

Return type:

torch.Tensor

__len__() int
Return type:

int

class timesead.models.generative.Donut(input_dim: int, hidden_dims: List[int] = [100, 100], latent_dim: int = 20, mask_prob: float = 0.01)

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)

  • hidden_dims (List[int])

  • latent_dim (int)

  • mask_prob (float)

Xu2018

Parameters:
  • input_dim (int) – Should be window_size * features

  • hidden_dims (List[int])

  • latent_dim (int)

  • mask_prob (float)

latent_dim = 20
mask_prob = 0.01
vae
forward(inputs: Tuple[torch.Tensor]) Tuple[torch.Tensor, Ellipsis]
Parameters:

inputs (Tuple[torch.Tensor])

Return type:

Tuple[torch.Tensor, Ellipsis]

class timesead.models.generative.MaskedVAELoss(size_average=None, reduce=None, reduction: str = 'mean')

Bases: timesead.models.common.VAELoss

Parameters:

reduction (str)

forward(predictions: Tuple[torch.Tensor, Ellipsis], targets: Tuple[torch.Tensor, Ellipsis], *args, **kwargs) torch.Tensor
Parameters:
Return type:

torch.Tensor

class timesead.models.generative.DonutAnomalyDetector(model: Donut, num_mc_samples: int = 1024)

Bases: timesead.models.common.AnomalyDetector

We decided not to include the reconstruction step from the paper here, since we don’t have missing data.

Parameters:
model
num_mc_samples = 1024
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.GRUGMMVAE(input_dim: int, gru_hidden_dims: List[int] = [60], latent_dim: int = 8, gmm_components: int = 2)

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)

  • gru_hidden_dims (List[int])

  • latent_dim (int)

  • gmm_components (int)

Guo2018 (more or less)

Parameters:
  • input_dim (int)

  • gru_hidden_dims (List[int])

  • latent_dim (int)

  • gmm_components (int)

latent_dim = 8
gmm_components = 2
encoder_rnn
encoder_component
vae
prior_means
prior_std
softplus
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.GMMVAELoss

Bases: timesead.models.common.VAELoss

forward(predictions: Tuple[torch.Tensor, Ellipsis], targets: Tuple[torch.Tensor, Ellipsis], *args, **kwargs) torch.Tensor
Parameters:
Return type:

torch.Tensor

class timesead.models.generative.GMMVAEAnomalyDetector(model: GRUGMMVAE, num_mc_samples: int = 1)

Bases: timesead.models.common.AnomalyDetector

Use sampled log likelihood of data

Parameters:
model
num_mc_samples = 1
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.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.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.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.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

class timesead.models.generative.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.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.LSTMVAEGAN(input_dim: int, lstm_hidden_dims: List[int] = [60], latent_dim: int = 10)

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)

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

latent_dim = 10
encoder
decoder
discriminator
classifier
vae
forward(inputs: Tuple[torch.Tensor, Ellipsis]) Tuple[torch.Tensor, Ellipsis]
Parameters:

inputs (Tuple[torch.Tensor, Ellipsis])

Return type:

Tuple[torch.Tensor, Ellipsis]

grouped_parameters() Tuple[Iterator[inspect.Parameter], Ellipsis]
Return type:

Tuple[Iterator[inspect.Parameter], Ellipsis]

class timesead.models.generative.LSTMVAEGANTrainer(*args, **kwargs)

Bases: timesead.optim.trainer.Trainer

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]
Parameters:
Return type:

Dict[str, float]

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]
Parameters:
Return type:

List[float]

class timesead.models.generative.LSTMVAEGANAnomalyDetector(model: LSTMVAEGAN, alpha: float = 0.5)

Bases: timesead.models.common.AnomalyDetector

Parameters:
model
alpha = 0.5
fit(dataset: torch.utils.data.DataLoader) None
Parameters:

dataset (torch.utils.data.DataLoader)

Return type:

None

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

inputs (Tuple[torch.Tensor, Ellipsis])

Return type:

torch.Tensor

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

inputs (Tuple[torch.Tensor, Ellipsis])

Return type:

torch.Tensor

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

targets (Tuple[torch.Tensor, Ellipsis])

Return type:

torch.Tensor

class timesead.models.generative.MADGAN(input_dim: int, latent_dim: int = 15, generator_hidden_dims: List[int] = [100, 100, 100], discriminator_hidden_dims: List[int] = [100])

Bases: timesead.models.common.GAN, 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)

  • latent_dim (int)

  • generator_hidden_dims (List[int])

  • discriminator_hidden_dims (List[int])

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

latent_dim = 15
grouped_parameters() Tuple[Iterator[torch.nn.Parameter], Ellipsis]
Return type:

Tuple[Iterator[torch.nn.Parameter], Ellipsis]

class timesead.models.generative.MADGANTrainer(*args, disc_iterations: int = 1, gen_iterations: int = 3, **kwargs)

Bases: timesead.optim.trainer.Trainer

Parameters:
  • disc_iterations (int)

  • gen_iterations (int)

disc_iterations = 1
gen_iterations = 3
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]
Parameters:
Return type:

Dict[str, float]

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]
Parameters:
Return type:

List[float]

class timesead.models.generative.MADGANAnomalyDetector(model: MADGAN, max_iter: int = 1000, lambder: float = 0.5, rec_error_tolerance: float = 0.1)

Bases: timesead.models.common.AnomalyDetector

Parameters:
model
max_iter = 1000
lambder = 0.5
rec_error_tolerance = 0.1
rbf_kernel
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.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: 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)

  • latent_dim (int)

  • rnn_hidden_dims (Sequence[int])

  • dense_hidden_dims (Sequence[int])

  • nf_layers (int)

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

latent_dim = 3
prior
enc_rnn
encoder_vae
latent_nf
decoder_rnn
decoder_vae
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]
Parameters:
Return type:

Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor, torch.nn.Module, torch.Tensor, torch.Tensor]

class timesead.models.generative.OmniAnomalyLoss

Bases: 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 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.

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

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
Parameters:
Return type:

torch.Tensor

class timesead.models.generative.OmniAnomalyDetector(model: OmniAnomaly, num_mc_samples: int = 1024)

Bases: timesead.models.common.AnomalyDetector

We decided not to include the reconstruction step from the paper here, since we don’t have missing data.

Parameters:
model
num_mc_samples = 1024
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.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: 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)

  • rnn_hidden_dim (int)

  • latent_dim (int)

  • x_hidden_dims (List[int])

  • z_hidden_dims (List[int])

  • enc_hidden_dims (List[int])

  • dec_hidden_dims (List[int])

  • prior_hidden_dims (List[int])

Li2021, ist aber im Prinzip nur Chung2015 mit einem extra loss term

Parameters:
  • input_dim (int)

  • lstm_hidden_dims

  • latent_dim (int)

  • rnn_hidden_dim (int)

  • x_hidden_dims (List[int])

  • z_hidden_dims (List[int])

  • enc_hidden_dims (List[int])

  • dec_hidden_dims (List[int])

  • prior_hidden_dims (List[int])

latent_dim = 40
rnn_hidden_dim = 200
x_embed
z_embed
encoder
decoder
prior_decoder
rnn_cell
softplus
forward(inputs: Tuple[torch.Tensor]) Tuple[torch.Tensor, Ellipsis]
Parameters:

inputs (Tuple[torch.Tensor])

Return type:

Tuple[torch.Tensor, Ellipsis]

class timesead.models.generative.SISVAELossWithGeneratedPrior(smooth_weight: float = 0.5)

Bases: timesead.models.common.VAELoss

Parameters:

smooth_weight (float)

smooth_weight = 0.5
forward(predictions: Tuple[torch.Tensor, Ellipsis], targets: Tuple[torch.Tensor, Ellipsis], *args, **kwargs) torch.Tensor
Parameters:
Return type:

torch.Tensor

class timesead.models.generative.SISVAEAnomalyDetector(model: SISVAE, num_mc_samples: int = 128)

Bases: timesead.models.common.AnomalyDetector

We decided not to include the reconstruction step from the paper here, since we don’t have missing data.

Parameters:
model
num_mc_samples = 128
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.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: 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_size (int)

  • window_size (int)

  • latent_size (int)

  • enc_lstm_hidden_size (int)

  • gen_lstm_hidden_size (int)

  • disc_conv_filters (int)

  • disc_conv_kernel_size (int)

  • disc_z_hidden_size (int)

  • gen_dropout (float)

  • disc_dropout (float)

  • disc_z_dropout (float)

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

encoder
generator
discriminatorx
discriminatorz
gan
inverse_gan
latent_size = 20
grouped_parameters() Tuple[Iterator[torch.nn.Parameter], Ellipsis]
Return type:

Tuple[Iterator[torch.nn.Parameter], Ellipsis]

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

inputs (Tuple[torch.Tensor, Ellipsis])

Return type:

Tuple[torch.Tensor, Ellipsis]

class timesead.models.generative.TADGANGeneratorLoss(reconstruction_coeff: float = 10)

Bases: timesead.models.common.WassersteinGeneratorLoss

Parameters:

reconstruction_coeff (float)

rec_coeff = 10
rec_loss
forward(predictions: Tuple[torch.Tensor, Ellipsis], targets: Tuple[torch.Tensor, Ellipsis], *args, **kwargs) torch.Tensor
Parameters:
Return type:

torch.Tensor

class timesead.models.generative.TADGANTrainer(*args, disc_iterations: int = 5, **kwargs)

Bases: timesead.optim.trainer.Trainer

Parameters:

disc_iterations (int)

disc_iterations = 5
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]
Parameters:
Return type:

Dict[str, float]

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]
Parameters:
Return type:

List[float]

class timesead.models.generative.TADGANAnomalyDetector(model: TADGAN, alpha: float = 0.5)

Bases: timesead.models.common.AnomalyDetector

Parameters:
model
alpha = 0.5
fit(dataset: torch.utils.data.DataLoader) None
Parameters:

dataset (torch.utils.data.DataLoader)

Return type:

None

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

inputs (Tuple[torch.Tensor, Ellipsis])

Return type:

torch.Tensor

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

inputs (Tuple[torch.Tensor, Ellipsis])

Return type:

torch.Tensor

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

targets (Tuple[torch.Tensor, Ellipsis])

Return type:

torch.Tensor