timesead.models.generative.tadgan ================================= .. py:module:: timesead.models.generative.tadgan Classes ------- .. autoapisummary:: timesead.models.generative.tadgan.TADGANEncoder timesead.models.generative.tadgan.TADGANGenerator timesead.models.generative.tadgan.TADGANDiscriminatorX timesead.models.generative.tadgan.TADGANDiscriminatorZ timesead.models.generative.tadgan.TADGAN timesead.models.generative.tadgan.TADGANGeneratorLoss timesead.models.generative.tadgan.TADGANTrainer timesead.models.generative.tadgan.TADGANAnomalyDetector Module Contents --------------- .. py:class:: TADGANEncoder(input_size: int, window_size: int, lstm_hidden_size: int = 100, latent_size: int = 20) 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:: lstm .. py:attribute:: linear .. py:method:: forward(x: torch.Tensor) -> torch.Tensor .. py:class:: TADGANGenerator(window_size: int, output_size: int, latent_size: int = 20, lstm_hidden_size: int = 64, dropout: float = 0.2) 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:: linear1 .. py:attribute:: lstm1 .. py:attribute:: upsample .. py:attribute:: lstm2 .. py:attribute:: linear2 .. py:attribute:: final_activation .. py:method:: forward(x: torch.Tensor) -> torch.Tensor .. py:class:: TADGANDiscriminatorX(input_size: int, window_size: int, conv_filters: int = 64, conv_kernel_size: int = 5, dropout: float = 0.25) 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:: conv1 .. py:attribute:: conv2 .. py:attribute:: conv3 .. py:attribute:: conv4 .. py:attribute:: dropout .. py:attribute:: leakyrelu .. py:attribute:: classification .. py:method:: forward(x: torch.Tensor) -> torch.Tensor .. py:class:: TADGANDiscriminatorZ(latent_size: int, hidden_size: int = 20, dropout: float = 0.2) 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:: linear1 .. py:attribute:: linear2 .. py:attribute:: dropout .. py:attribute:: leakyrelu .. py:attribute:: classification .. py:method:: forward(x: torch.Tensor) -> 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