File size: 1,597 Bytes
3621f16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
48
49
50
51
52
53
"""

GRU Baseline Model for Time Series Prediction.



A standard GRU baseline without advanced techniques.

"""
import torch
import torch.nn as nn


class GRUBaseline(nn.Module):
    """

    Simple GRU Baseline for time series forecasting.

    

    Uses standard configuration without advanced optimizations

    to serve as a fair baseline comparison.

    """
    def __init__(self, configs):
        super().__init__()
        self.pred_len = configs.pred_len
        self.c_in = configs.c_in
        
        # Standard GRU configuration (single layer, moderate hidden size)
        hidden_size = 64  # Conservative hidden size for baseline
        
        self.gru = nn.GRU(
            input_size=configs.c_in,
            hidden_size=hidden_size,
            num_layers=1,  # Single layer baseline
            batch_first=True,
            dropout=0.0  # No dropout for simple baseline
        )
        
        # Simple linear projection
        self.fc = nn.Linear(hidden_size, configs.pred_len * configs.c_in)
        
    def forward(self, x):
        """

        Args:

            x: [B, SeqLen, C] - Input time series (OHLCV)

            

        Returns:

            [B, PredLen, C] - Predicted time series

        """
        # GRU encoding
        _, h_n = self.gru(x)  # h_n: [1, B, hidden]
        h_n = h_n.squeeze(0)  # [B, hidden]
        
        # Project to prediction
        out = self.fc(h_n)  # [B, pred_len * c_in]
        out = out.view(-1, self.pred_len, self.c_in)  # [B, pred_len, c_in]
        
        return out