Input: 100个连续Level-2快照 (batch, 100, 40)
↓ BilinearNorm (自适应归一化)
↓ Spatial CNN (十档价位间的空间模式)
↓ Temporal CNN (多尺度时间特征)
↓ Transformer Attention × 2 (时序依赖)
↓ 5-class Classification
1import torch, numpy as np
2from model import LOBAlgoNet
3
4model = LOBAlgoNet(num_classes=5, d_model=128, nhead=4, dropout=0.25)
5model.load_state_dict(torch.load("model.pt", weights_only=True))
6model.eval()
7
8stats = np.load("norm_stats.npz")
9# raw_lob: your (100, 40) LOB data, normalized with stats["means"] and stats["stds"]
10x = torch.from_numpy((raw_lob - stats["means"]) / stats["stds"]).unsqueeze(0).float()
11
12with torch.no_grad():
13 probs = torch.softmax(model(x), dim=1)
14 pred = probs.argmax(1).item()
15
16labels = ["TWAP(时间加权)", "VWAP(量加权)", "冰山订单", "护盘/支撑", "散户/正常"]
17print(f"识别结果: {labels[pred]} (置信度: {probs[0,pred]:.1%})")