quantlab.model.predefined.mlp.MLPNet#

class quantlab.model.predefined.mlp.MLPNet(num_features, num_labels, layers=(256,), act='LeakyReLU')[source]#

Bases: Module

Qlib’s Net: dropout, Linear + BatchNorm1d + LeakyReLU layers, dropout, Linear.

The input is each sample’s latest bar. Input and output dropout are 0.05, the activation is LeakyReLU(0.1) (or SiLU), and every linear weight starts Kaiming-normal. The parameter names are Qlib’s (dnn_layers), so a Qlib state dict loads into a one-label net.

Parameters:
num_featuresint

Features, F.

num_labelsint

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

layerstuple of int, default (256,)

Hidden widths.

act{“LeakyReLU”, “SiLU”}, default “LeakyReLU”

The activation.

Raises:
ValueError

If act is neither "LeakyReLU" nor "SiLU".

Examples

>>> net = MLPNet(num_features=4, num_labels=2, layers=(8,)).eval()
>>> net(torch.randn(5, 3, 4)).shape
torch.Size([5, 2])
forward(x)[source]#

Map the latest bar of [B, N, F] windows to [B, L] outputs.

Examples

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