File size: 1,661 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
54
55
"""
DMMV-A + DMMV-S + Kronos Fusion Predictor.

Combines advantages of adaptive decomposition, moving average, and symbolic tokenization.
"""
import torch
import torch.nn as nn
import sys

sys.path.insert(0, '/workspace/dmmv')
sys.path.insert(0, '/workspace/Kronos')

from model_dmmv_a import DMMV_A_Wrapper
from model_dmmv_s import DMMV_S_Fixed

class DMMV_AS_Kronos_Predictor(nn.Module):
    """DMMV-A + DMMV-S + Kronos Integrated Predictor."""
    def __init__(self, configs):
        super().__init__()
        
        # DMMV-A Branch: Adaptive Decomposition
        self.dmmv_a = DMMV_A_Wrapper(configs)
        
        # DMMV-S Branch: Moving Average Decomposition
        self.dmmv_s = DMMV_S_Fixed(configs)
        
        # Fusion layer (trainable)
        self.fusion = nn.Sequential(
            nn.Linear(configs.pred_len * 2, configs.pred_len),
            nn.Tanh()
        )
        
        # Learnable weights
        self.weights = nn.Parameter(torch.tensor([0.5, 0.5]))
    
    def forward(self, x):
        # Predictions from both DMMV branches
        pred_a = self.dmmv_a(x)[:, :, 3]  # [B, PredLen]
        pred_s = self.dmmv_s(x)[:, :, 3]  # [B, PredLen]
        
        # Concatenate and fuse
        combined = torch.cat([pred_a, pred_s], dim=-1)  # [B, 2*PredLen]
        fused = self.fusion(combined)  # [B, PredLen]
        
        # Weighted fusion
        w = torch.softmax(self.weights, dim=0)
        final = w[0] * pred_a + w[1] * pred_s
        
        # Expand dimensions to match output format
        output = x[:, -1:, :].repeat(1, pred_a.size(1), 1)
        output[:, :, 3] = final
        
        return output