timesead.models.generative.beatgan ================================== .. py:module:: timesead.models.generative.beatgan Classes ------- .. autoapisummary:: timesead.models.generative.beatgan.ConvEncoder timesead.models.generative.beatgan.ConvDecoder timesead.models.generative.beatgan.BeatGANConvEncoder timesead.models.generative.beatgan.BeatGANConvDecoder timesead.models.generative.beatgan.BeatGANConvAE timesead.models.generative.beatgan.BeatGANModel timesead.models.generative.beatgan.BeatGANDiscriminatorLoss timesead.models.generative.beatgan.BeatGANGeneratorLoss timesead.models.generative.beatgan.BeatGANReconstructionAnomalyDetector timesead.models.generative.beatgan.WrapAugmentTransform Module Contents --------------- .. py:class:: 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: :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:: layers .. py:method:: forward(x: torch.Tensor) -> Tuple[torch.Tensor, List[Tuple[int]]] .. py:class:: 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: :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:: layers .. py:method:: forward(inputs: Tuple[torch.Tensor, List[Tuple[int]]]) -> torch.Tensor .. py:class:: BeatGANConvEncoder(input_dim: int, conv_filters: int = 32, latent_dim: int = 50, last_kernel_size: int = 10, return_features: bool = False) Bases: :py:obj:`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 :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:: return_features :value: False .. py:attribute:: last_conv .. py:method:: forward(x: torch.Tensor) -> Tuple[torch.Tensor, Union[List[Tuple[int]], torch.Tensor]] .. py:class:: BeatGANConvDecoder(input_dim: int, conv_filters: int = 32, latent_dim: int = 50, last_kernel_size: int = 10) Bases: :py:obj:`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 :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:: final_activation .. py:method:: forward(inputs: Tuple[torch.Tensor, List[Tuple[int]]]) -> torch.Tensor .. py:class:: BeatGANConvAE(input_dim: int, conv_filters: int = 32, latent_dim: int = 50, last_kernel_size: int = 10) Bases: :py:obj:`timesead.models.common.AE` .. 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:: 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:: 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:: 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