quantlab.model.ensemble#

The base class of every ensemble of models, shipped or user-written.

BaseEnsemble holds what does not depend on where an ensemble’s members come from: the Predictor members derived from the members (labels, label delays and scales, training and test windows), prediction by combining the members’ predictions, and the "ensemble" trained unit (quantlab.runs.trained_run) that train() writes and load and check_checkpoint read.

Each label is combined over the members that predict it (ADR 0013): the ensemble’s labels are the union of the members’ labels in first-appearance order, a label several members predict is standardised per bar and averaged, and a label only one member predicts is passed through unchanged. So seed ensembles, ensembles of different models and a return model paired with a volatility model are one rule. A label predicted by several members must have the same config in each. The training end is the latest member’s, the test window the intersection of the members’.

A concrete ensemble builds its members and implements get_config / from_config; nothing else is required, and the defaults work for members of different classes over different factors. Optional hooks:

  • _combine: how the members’ prediction panels become the ensemble’s; by default each label is averaged over its members with average_predictions (per-bar z-score, equal-weight mean) or passed through from its only member. Both predict_window and the ensemble-level evaluation files use it. An override should keep label_scales true, overriding it too when needed.

  • _collect, _member_predictions, _member_panel_predictions: how members collect their data and features, each member on its own by default; an ensemble whose members read the same data shares it. collect records what _collect reads, on the ensemble’s unit.

  • _member_seed: the seed recorded for each member in run.json.

Shipped ensembles are in quantlab/model/predefined (SeedEnsemble, ModelEnsemble).

The ensemble composes models and inherits none: each member is a complete model (a BaseModel) with its own checkpoint.

On disk train() writes an "ensemble" unit:

{model_save_dir}/{EnsembleClass}_trial_{timestamp}/
    member_0/            one member's ``"model"`` unit
    member_1/
    ...
    ic_series.csv        the first label's per-bar series, in the single-model layout
    test_predictions.zarr  the combined test-segment prediction
    run.json             members and seeds, windows, metrics; written last

train_cv writes a "walk_forward" unit whose folds are such units:

{model_save_dir}/{EnsembleClass}_trial_{timestamp}/
    fold_0/              an ensemble unit as above
    fold_1/
    ...
    run.json             the folds and the fold means ``cv_mean``

The record names each member’s directory and seed (null when the ensemble does not vary seeds) and nothing specific to one kind of ensemble; each member’s class is in its own config.json.

assemble and assemble_cv write the same units from members trained separately (their own train / train_cv runs), copied in without training again; only the test segment is scored, and run.json names the source runs in assembled_from.

Classes

BaseEnsemble

Base class of an ensemble that combines the predictions of several models.

Functions

average_predictions

Return the mean of the panels' per-bar cross-sectional z-scores.

member_correlation

Return the mean pairwise correlation of member predictions, overall and per bar.