quantlab.model.predefined.tcn.TCNNet#

class quantlab.model.predefined.tcn.TCNNet(num_features, num_labels, n_chans=32, num_layers=5, kernel_size=7, dropout=0.5)[source]#

Bases: Module

Qlib’s TCNModel with an output of any width.

Each sample’s window [N, F] is read as F channels over N steps and goes through num_layers temporal blocks of n_chans channels, the dilation doubling at every block; Linear(n_chans, L) maps the channels at the last step to the output. The parameter names are Qlib’s (tcn.network, linear), so a Qlib state dict loads into a one-label net.

Parameters:
num_featuresint

Features per bar, F.

num_labelsint

Outputs per sample, L; Qlib’s model has one.

n_chansint, default 32

Channels of every block.

num_layersint, default 5

Temporal blocks.

kernel_sizeint, default 7

Convolution width.

dropoutfloat, default 0.5

Dropout after every convolution.

Examples

>>> net = TCNNet(num_features=4, num_labels=2, n_chans=8, num_layers=2, kernel_size=3)
>>> net(torch.randn(5, 6, 4)).shape
torch.Size([5, 2])
forward(x)[source]#

Map [B, N, F] windows to [B, L] outputs.

Examples

>>> net.forward(torch.randn(2, 6, 4)).shape
torch.Size([2, 2])