""" 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