quantlab.model.predefined.gats.GATsNet#
- class quantlab.model.predefined.gats.GATsNet(num_features, num_labels, hidden_size=64, num_layers=2, dropout=0.0, base_model='LSTM')[source]#
Bases:
ModuleQlib’s
GATModelwith an output of any width.Each symbol’s window
[N, F]goes through an LSTM or GRU, and the hidden state of the last barh([S_t, H]) is kept. Withx = W h + b(transformation), the attention score of symbolion symboljisLeakyReLU(a[:H]·x_j + a[H:]·x_i)with slope 0.01, normalised by a softmax over everyjof the bar, self included. The output isfc_out(LeakyReLU(fc(h + A h))): the untransformedhis aggregated, as in Qlib. The parameter names are Qlib’s, so a QlibGATModelstate dict loads into a one-label net.The scores are computed as a sum of two
[S_t, 1]projections rather than Qlib’s[S_t, S_t, 2H]concatenation, which is the same value without the memory that grows with the square of the cross-section.- Parameters:
- num_featuresint
Features per bar,
F.- num_labelsint
Outputs per symbol,
L; Qlib’s model has one.- hidden_sizeint, default 64
H, the encoder’s hidden size.- num_layersint, default 2
Encoder layers.
- dropoutfloat, default 0.0
Dropout between encoder layers.
- base_model{“LSTM”, “GRU”}, default “LSTM”
The encoder.
- Raises:
- ValueError
If
base_modelis neither"LSTM"nor"GRU".
Examples
>>> net = GATsNet(num_features=4, num_labels=2, hidden_size=8) >>> net(torch.randn(5, 3, 4)).shape torch.Size([5, 2])