quantlab.model.predefined.realmlp.RealMLPRegressor#

class quantlab.model.predefined.realmlp.RealMLPRegressor(config)[source]#

Bases: TabkitRegressor

Predict future returns with a pytabkit RealMLP (tuned defaults).

One RealMLP_TD_Regressor is fitted on the flattened rows. Each label is one output of a multi-output regression, and headline metrics are computed on the primary label, index 0. NaN imputation and the hyperparameter record are inherited from TabkitRegressor.

Hyperparameters are the constructor arguments of RealMLP_TD_Regressor (n_epochs, hidden_sizes, lr, device, n_threads, …). Without device the head trains on "cuda" when torch sees a CUDA device and on "cpu" otherwise; Apple MPS is used only when asked for (device="mps"). The device chosen is recorded in resolved_hyperparameters. The network stays on it for evaluation and prediction; the checkpoint is written from the CPU so it loads without CUDA, and a loaded model is moved to the default device by the same rule.

With hyperparameters["early_stopping"] set and validation rows, pytabkit’s early stopping watches the validation loss with early_stopping_additive_patience = hyperparameters["early_stopping_patience"] and a multiplicative patience of 1.0, so patience counts epochs without improvement. The fitted model is already rolled back to the best epoch, so the .joblib checkpoint is the best model. The stopping epoch is written to the run summary as stop_epoch. Without a usable validation segment a warning is logged and all n_epochs are trained. Every tracking run also gets a per-epoch curve: the mean training loss (train-loss) and the validation error pytabkit stops on (val-rmse), at step=epoch, plus best_val_rmse and epochs_trained in the summary, through a Lightning callback injected into pytabkit’s trainer (see quantlab.model.predefined._support.tabkit.active_callbacks).

train_cv (rolling walk-forward cross-validation) is inherited. Each fold does its own early stopping and writes its own .joblib. The folds train one after another.

Parameters:
configModelConfig

Factors, labels, date ranges, early-stopping settings and hyperparameters. See ModelConfig.

Examples

>>> config = ModelConfig(
...     factors=[alpha],            # factor objects
...     labels=[fwd_return],        # label objects
...     model_save_dir="checkpoints",
...     factor_data_strategy="read",
...     label_data_strategy="read",
...     train_start="2024-01-01", train_end="2024-02-09",
...     test_start="2024-02-10", test_end="2024-02-29",
...     hyperparameters={
...         "early_stopping": True, "early_stopping_patience": 5,
...         "n_epochs": 50, "n_threads": 4,
...     },
... )
>>> model = RealMLPRegressor(config)
>>> checkpoint = model.collect().train()
>>> checkpoint.name
'RealMLPRegressor_total.joblib'
>>> model.predict(np.zeros((5, 2, 3), dtype="float32")).shape
(5, 2, 1)
>>> model.train_cv(train_periods=500)
DEFAULT_PARAMS = {'val_fraction': 0.0, 'verbosity': 0}#

Estimator constructor arguments applied before the config seed, the early-stopping keys and the user’s hyperparameters.