File size: 1,426 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
import os
import sys
import torch
import torch.nn as nn

PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, os.path.join(PROJECT_ROOT, 'dmmv'))
sys.path.insert(0, os.path.join(PROJECT_ROOT, 'Kronos'))

from model_dmmv_s import DMMV_S_Fixed
from model.kronos import KronosTokenizer

class DMMV_S_Kronos(nn.Module):
    """
    DMMV-S + Kronos Fusion (exploring new combination).
    """
    def __init__(self, dmmv_configs, kronos_configs):
        super().__init__()
        self.dmmv_s = DMMV_S_Fixed(dmmv_configs)
        self.kronos = KronosTokenizer(**kronos_configs)
        
        bits = kronos_configs['s1_bits'] + kronos_configs['s2_bits']
        
        self.pattern_proj = nn.Sequential(
            nn.Linear(bits, 128),
            nn.ReLU(),
            nn.Linear(128, dmmv_configs.pred_len)
        )
        
        self.fusion_weight = nn.Parameter(torch.tensor([0.8, 0.2]))
    
    def forward(self, x):
        # DMMV-S prediction
        dmmv_out = self.dmmv_s(x)
        
        # Kronos features
        _, _, quantized, _ = self.kronos(x)
        kronos_feat = quantized.mean(dim=1)
        correction = self.pattern_proj(kronos_feat)
        
        # Fusion
        weights = torch.softmax(self.fusion_weight, dim=0)
        output = dmmv_out.clone()
        output[:, :, 3] = (weights[0] * dmmv_out[:, :, 3] + weights[1] * correction)
        
        return output