FinMM-Project-FinMM / src /models /model_gru.py
GoldenGrapeGentleman1's picture
Upload Project_FinMM before machine wipe
3621f16 verified
Raw History Blame Contribute Delete
1.6 kB
"""
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