timesead.models.generative.beatgan

Classes

ConvEncoder

Base class for all neural network modules.

ConvDecoder

Base class for all neural network modules.

BeatGANConvEncoder

Base class for all neural network modules.

BeatGANConvDecoder

Base class for all neural network modules.

BeatGANConvAE

BeatGANModel

Base class for all neural network modules.

BeatGANDiscriminatorLoss

BeatGANGeneratorLoss

Base class for all neural network modules.

BeatGANReconstructionAnomalyDetector

WrapAugmentTransform

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

Module Contents

class timesead.models.generative.beatgan.ConvEncoder(input_dim: int, filters: List[int], conv_parameters: List[Tuple[int, int, int, bool, bool]], block: Type[timesead.models.layers.ConvBlock] = ConvBlock, conv_layer=torch.nn.Conv1d, activation=torch.nn.Identity())

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:

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

layers
forward(x: torch.Tensor) Tuple[torch.Tensor, List[Tuple[int]]]
Parameters:

x (torch.Tensor)

Return type:

Tuple[torch.Tensor, List[Tuple[int]]]

class timesead.models.generative.beatgan.ConvDecoder(input_dim: int, filters: List[int], conv_parameters: List[Tuple[int, int, int, bool, bool]], block: Type[timesead.models.layers.ConvBlock] = ConvBlock, conv_layer=torch.nn.ConvTranspose1d, activation=torch.nn.Identity())

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:

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

layers
forward(inputs: Tuple[torch.Tensor, List[Tuple[int]]]) torch.Tensor
Parameters:

inputs (Tuple[torch.Tensor, List[Tuple[int]]])

Return type:

torch.Tensor

class timesead.models.generative.beatgan.BeatGANConvEncoder(input_dim: int, conv_filters: int = 32, latent_dim: int = 50, last_kernel_size: int = 10, return_features: bool = False)

Bases: ConvEncoder

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)

  • return_features (bool)

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

return_features = False
last_conv
forward(x: torch.Tensor) Tuple[torch.Tensor, List[Tuple[int]] | torch.Tensor]
Parameters:

x (torch.Tensor)

Return type:

Tuple[torch.Tensor, Union[List[Tuple[int]], torch.Tensor]]

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

Bases: ConvDecoder

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.

final_activation
forward(inputs: Tuple[torch.Tensor, List[Tuple[int]]]) torch.Tensor
Parameters:

inputs (Tuple[torch.Tensor, List[Tuple[int]]])

Return type:

torch.Tensor

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

Bases: timesead.models.common.AE

Parameters:
  • input_dim (int)

  • conv_filters (int)

  • latent_dim (int)

  • last_kernel_size (int)

class timesead.models.generative.beatgan.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.beatgan.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.beatgan.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.beatgan.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.beatgan.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