quantlab.model.predefined.master.MASTERNet#
- class quantlab.model.predefined.master.MASTERNet(num_features, num_labels, gate_columns, d_model=256, t_nhead=4, s_nhead=2, dropout=0.5, beta=5.0)[source]#
Bases:
ModuleThe MASTER network with its market gate columns anywhere among the features.
The input is one bar’s
[S_t, N, F]windows. The columnsgate_columnsare the market features: their values at the last step go throughGateto weights that rescale the otherF - Gcolumns at every step. The rescaled features then passLinear(F - G, D),PositionalEncoding, attention over time within each symbol (4 heads, unscaled), attention across symbols at every step (2 heads, scaled),TemporalAttentionandLinear(D, L). The submodule names and order are the official ones, so an officialMASTERstate dict loads into a one-label net whose gate columns are the trailing ones.- Parameters:
- num_featuresint
F, every column of the input, gate columns included.
- num_labelsint
L, outputs per symbol; the official network has one.
- gate_columnslist of int
Positions of the market features among the F columns.
- d_modelint, default 256
- t_nhead, s_nheadint, default 4 and 2
Heads of the attention over time and across symbols.
- dropoutfloat, default 0.5
Dropout of both attention blocks.
- betafloat, default 5.0
Gate temperature; a smaller beta selects features more sharply.
- Raises:
- ValueError
If
gate_columnsis empty, covers every column or repeats one, or a head count does not divided_model.
Examples
>>> net = MASTERNet(num_features=5, num_labels=2, gate_columns=[3, 4], ... d_model=8, t_nhead=2, s_nhead=2) >>> net(torch.randn(6, 4, 5)).shape torch.Size([6, 2])