File size: 1,354 Bytes
13a7cc8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# SPDX-FileCopyrightText: 2025 Stanford University, ETH Zurich, and the project authors (see CONTRIBUTORS.md)
# SPDX-FileCopyrightText: 2025 This source file is part of the OpenTSLM open-source project.
#
# SPDX-License-Identifier: MIT

from abc import abstractmethod
import torch
import torch.nn as nn
from opentslm.model_config import TRANSFORMER_INPUT_DIM, PATCH_SIZE


class TimeSeriesDecoderBase(nn.Module):
    """
    Base class for time series decoders.
    
    Decoders map from latent representations back to time series space.
    """
    
    def __init__(
        self,
        input_dim: int = TRANSFORMER_INPUT_DIM,
        patch_size: int = PATCH_SIZE,
        dropout: float = 0.0,
    ):
        """
        Args:
            input_dim: Dimension of input latent representation
            patch_size: Size of time series patches to reconstruct
            dropout: Dropout probability
        """
        super().__init__()
        self.input_dim = input_dim
        self.patch_size = patch_size
        self.dropout = dropout

    @abstractmethod
    def forward(self, x: torch.Tensor) -> torch.Tensor:
        """
        Decode latent representation to time series.
        
        Args:
            x: Latent representation from encoder
            
        Returns:
            Reconstructed time series
        """
        pass