Referência da API¶
Nota
Os docstrings abaixo estão em inglês: são a fonte única, escrita no código. As mensagens de erro e os avisos da biblioteca estão em português.
Experimento¶
- class autohybts.AutoHybridExperiment(fh=14, session_id=42, fold='auto', fold_strategy='expanding', window_size=None, seasonal_period=None, test_size=None, profile='standard', variant='A', budget='small', max_trials=None, max_wall_time_s=None, base_models=None, correctors=None, residual_windows=None, alphas=None, residual_sources=None, base_params=None, corrector_params=None, max_stages=2, decomposition_methods=None, combination_weights=('equal', 'inverse_mse'), ensemble_methods=('equal', 'median', 'inverse_mse', 'nnls'), stage_params='shared', significance_alpha=None, differencing=None, differencing_test='kpss', seasonality_test='friedman', transform=None, outliers=None, missing='reject', exog_future=(), exog_lags=None, exog_selection=None, progress=False, metrics=('MASE', 'MAE', 'RMSE', 'sMAPE'), n_jobs=1, registry=None, median_gain_threshold=0.05, win_rate_threshold=0.6, variability_threshold=None, min_coverage=1.0, epsilon=1e-12)[código-fonte]¶
Base:
ParametrizedAutomated comparison of standalone and residual hybrid forecasters.
- Parâmetros:
fh (int) – forecast horizon (steps per origin, and default horizon of predictions).
session_id (int) – seed of the whole experiment.
fold (int | str) – origins in each validation layer (
V_searchandV_select)."auto"(default) uses 7 when the history allows and otherwise the largest number that fits, with a warning: the acceptance rule is calibrated for 7 units on one series; with fewer it accepts spurious structures more often. An integer is used as given.fold_strategy (str) –
"expanding"or"rolling"(needswindow_size).window_size (int | None) – training window length of each origin with
fold_strategy="rolling".seasonal_period (int | str | None) –
Noneinfers it from the frequency (daily: 7, monthly: 12 …)."auto"keeps that period for the metrics but tests the seasonality on the training vector of the earliest validation origin (data every origin has seen): when that vector has at least 6 cycles and shows no evidence of one, the search uses period 1, so seasonal models and the STL are skipped; with fewer cycles the period stays.seasonality_holds the test.test_size (int | None) – points sealed at the end of the series;
Nonemeansfh,0disables the sealed test (operational forecasting).profile (Profile) –
"quickstart"(variability criterion off by default),"standard","research_strict"or"exploratory".variant (ProtocolVariant) – forecasting protocol.
"A"(default): each origin forecastsfhsteps at once, and a corrector’s window is fed with its own predicted residuals."B": rolling one-step forecasts with frozen parameters; each observation is revealed only after its forecast and its residual then enters the corrector window. Bases that cannot take new observations without refitting are skipped in B;"dynamic"selection exists only in B.budget (BudgetPreset) – search preset (
"smoke","small","medium","large").max_trials (int | None) – overrides the preset’s total number of candidates.
max_wall_time_s (float | None) – optional search deadline in seconds (
None: none, the default). Cooperative: no candidate starts after it, a running one finishes; candidates kept out areSTOPPEDin the ledger. With a deadline the searched set can change between machines; budgets by count are the reproducible ones.base_models (Sequence[str] | None) – search space (
Nonekeeps the default search space).correctors (Sequence[str] | None) – search space (
Nonekeeps the default search space).residual_windows (Sequence[int] | None) – search space (
Nonekeeps the default search space).alphas (Sequence[float] | None) – search space (
Nonekeeps the default search space).residual_sources (Sequence[str] | None) – search space (
Nonekeeps the default search space).base_params (Mapping[str, Sequence[Mapping[str, Any]]] | None) – grid of each base in stage S0, by model name: a list of parameter dicts, one candidate each (e.g.
{"knn": [{"lags": 7}, {"lags": 14}]}). A base without a grid uses its search defaults.corrector_params (Mapping[str, Sequence[Mapping[str, Any]]] | None) – alternative settings of each corrector, tried in stage S3 (refinement) around the best residual structures; S2 uses each corrector’s defaults.
max_stages (int) – most correction stages tried when
compare_modelsincludes"multistage"(2 or 3).decomposition_methods (Sequence[str] | None) – decompositions tried when
compare_modelsincludes"decomposition";Nonemeans("ma", "stl")in variant A and("ma",)in variant B.combination_weights (Sequence[str]) – weightings tried when
compare_modelsincludes"combination".ensemble_methods (Sequence[str]) – aggregations tried when
compare_modelsincludes"ensemble"("equal","median","trimmed_mean","inverse_mse","nnls"): ensembles of the best base of each family, of the two best residual structures and residual corrections of the equal-weight ensemble. Off the defaultinclude: see the calibration gate.stage_params (str) –
"shared"(extra stages reuse window, alpha and source) or"per_stage"(the search also varies the extra stage’s window and alpha).significance_alpha (float | None) – optional extra acceptance predicate: a one-sided paired Wilcoxon test on
V_selectmust givep < significance_alpha(off by default). It needs at least 5 paired units with different errors, all series together, for0.05: with 3 origins on one series it can never pass. It controls each comparison, not the whole chain (seeSelectionPolicy).differencing (str | None) –
"auto"makes every built-in lag model of the search choose its differences on each origin’s training vector: one seasonal difference when the seasonality test finds a strong cycle (periodsearch_period_), thendup to 2 bydifferencing_test.None(default) keeps each model’s own setting (no differencing), so candidate IDs do not change.differencing_test (str) –
"kpss"(KPSS does not reject stationarity, asauto.arima) or"adf"(ADF rejects a unit root, as the replication project).seasonality_test (str) – rule of
seasonal_period="auto":"friedman"(test by position in the cycle, at least 6 cycles to drop the period) or"strength"(the replication project: a series that ADF finds stationary has no seasonality; otherwise STL strength on the Box-Cox series above 0.5).transform (str | None) –
"boxcox"or"log"makes every built-in lag model of the search fit the transform on each origin’s training data and invert its forecasts;None(default) leaves the target as observed (ADR-0009).outliers (str | None) –
"winsorize"or"interpolate"treats points with robust z > 4 (against a rolling median) in each origin’s training data only; forecast contexts and metric targets stay as observed.None(default) keeps them.missing (str) –
"reject"(default) refuses a series with missing values;"ffill"fills each gap with the last observed value (causal: only the past is used) and drops leading gaps. Filled points are scored as observed.exog_future (Sequence[str]) – exogenous columns of
Xknown in advance (calendar, holidays, planned prices): used at the forecast date itself. Every other column ispastand enters lagged by at least the steps forecast from one origin (max(fh, test_size)in variant A, 1 in variant B), so no value unknown at the origin reaches a forecast (ADR-0011). Declaring an observed value, such as the day’s temperature, asfuturemakes the evaluation an oracle.exog_lags (Mapping[str, Sequence[int]] | None) – extra lags per exogenous column, e.g.
{"temperature": [7, 14]}(pastcolumns need lags >= the minimum above).exog_selection (str | Sequence[str] | None) – how the exogenous features are chosen.
None(default): every column at its smallest causal lag. A method ofautohybts.data.exog_selection("ccf","granger","lasso","stepwise_bic","mutual_info","vote") or a list of them: each chosen set is a candidate feature set."auto": every method and the set with all columns; the search tries them and the selection decides, under the acceptance rule, whether any covariate enters. Methods run on the data before the firstV_selectorigin, as tuning does onV_search;V_selectand the sealed test never reach them (exog_report()).progress (bool) –
Trueshows tqdm progress bars for each search stage, the finalists onV_select, the choice of exogenous features and the outer folds of the nested cross-validation (extraprogress). Reporting only: nothing evaluated changes. Events also go to thelogginglogger"autohybts"either way.metrics (Sequence[str]) – evaluation metrics; the first one ranks and selects.
n_jobs (int) – threads used to evaluate candidates in parallel.
registry (ModelRegistry | None) – custom model registry (built-ins by default).
median_gain_threshold (float) – minimum paired median gain, finite and nonnegative (default 0.05). A protocol threshold, not a significance level.
win_rate_threshold (float) – minimum share of strict wins, in [0, 1] (default 0.60).
variability_threshold (float | None) – finite nonnegative correction variability threshold.
Noneinherits the profile: 0.05, or disabled inquickstart. An explicit number enables the criterion, including inquickstart.min_coverage (float) – required valid-unit coverage in (0, 1];
research_strictrequires 1.0. Lower coverage can change which units are compared.epsilon (float) – finite positive floor in the relative-gain denominator (default 1e-12).
- fit(y, X=None, *, series_col=None, date_col=None, target=None)[código-fonte]¶
Validate
y, seal the test segment and freeze the temporal plan.yis one series (pd.SeriesorSeriesFrame) or a panel: aPanelFrame, a mappingseries_id -> pd.Seriesor a longDataFramewithseries_col,date_colandtargetnamed explicitly. In a panel every series keeps its own sealed test, origins and MASE scale; candidates are compared on all of them.X(optional) holds exogenous covariates indexed by date: every date ofy(sealed test included) and, forfuturecolumns, later dates to forecast beyond the data. In a panel,Xis a mappingseries_id -> DataFrameor a longDataFramewith the sameseries_colanddate_colasy; every series needs the same columns. Their kinds and lags followexog_futureandexog_lags.
- models()[código-fonte]¶
Catalog of base models and correctors, with families and capabilities.
- Tipo de retorno:
- register_model(name, factory, *, kind='base', family='deep', requires=None, version='1', capabilities=None, description='', default_params=None, tuning_space=None, replace=False)[código-fonte]¶
Add a model built outside AutoHybTS (PyTorch, TensorFlow, any library).
factoryreceives a parameter mapping and returns a fresh, unfitted model:torch_model(...)/keras_model(...)fromautohybts.models, or any callable returning aBaseForecaster(kind="base") or aResidualCorrector(kind="corrector"). A model instance is also accepted and cloned for every trial. Afterwards the name works everywhere:create_model,base_models/correctorsof the search, hybrids,tune_model.requires(e.g.{"torch": ">=2.2"}) is checked when the model is built; a missing or older library makes the trialSKIPPED.versionnames the registration and enters every trial key: change it when the model code changes. Can be called before or afterfit; returns the experiment for chaining.- Parâmetros:
- Tipo de retorno:
- create_model(name, exog=False, **params)[código-fonte]¶
Evaluate one standalone model on every origin of both layers.
exog=Truegives the model the experiment’s exogenous features (needsXinfitand a model that accepts covariates).- Parâmetros:
- Tipo de retorno:
- create_ensemble(models, method='equal', **options)[código-fonte]¶
Evaluate one ensemble of complete forecasters on every origin.
modelsare names (default parameters of this experiment), specs orModelResult— standalone models, hybrids or other ensembles.methodis"equal","median","trimmed_mean"(trim=),"inverse_mse"or"nnls"(shrinkage=towards equal weights); learned weights come from out-of-fold forecasts inside each origin’s training vector.- Parâmetros:
models (Sequence[str | CandidateSpec | ModelResult])
method (str)
options (Any)
- Tipo de retorno:
- create_hybrid(base, corrector, window=7, alpha=1.0, residual_source='historical_oof_1step', base_params=None, corrector_params=None, extra_stages=(), stage_params=None, combine_correctors=(), combination_weights='inverse_mse')[código-fonte]¶
Evaluate one residual hybrid
base + alpha * correctoron every origin.extra_stagesnames correctors of further stages: each one corrects the residuals of the model before it (residual_multistage). By default the extra stages sharewindow,alphaandresidual_source;stage_paramsgives one dict per extra stage to change them (e.g.[{"window_size": 28}]).combine_correctorsinstead averagescorrectorand these correctors with fixedcombination_weights("equal"or"inverse_mse") as one correction.basemay also be a composed candidate (e.g.create_ensemble(...)): the corrector then learns the out-of-fold residuals of that composition (residual_composite); stages and corrector combinations are for named bases.- Parâmetros:
base (str | CandidateSpec | ModelResult)
corrector (str)
window (int)
alpha (float)
residual_source (str)
combination_weights (str)
- Tipo de retorno:
- create_decomposition(base, corrector, method='ma', window=7, ma_window=None, base_params=None, corrector_params=None)[código-fonte]¶
Evaluate
baseon the smooth part pluscorrectoron the volatile part.method="ma"is a causal moving average (window by kurtosis on each training vector whenma_windowisNone);"stl"is variant A only.
- create_combination(models, weights='inverse_mse')[código-fonte]¶
Evaluate a fixed combination of base models (weights from the training only).
- Parâmetros:
- Tipo de retorno:
- tune_model(model: str | CandidateSpec | ModelResult, n_trials: int = 20, search_space: Mapping[str, Distribution | Sequence[Any]] | None = None, sampler: str = 'auto', return_tuner: Literal[False] = False) ModelResult[código-fonte]¶
- tune_model(model: str | CandidateSpec | ModelResult, n_trials: int = 20, search_space: Mapping[str, Distribution | Sequence[Any]] | None = None, sampler: str = 'auto', *, return_tuner: Literal[True]) tuple[ModelResult, TuningResult]
Tune the parameters of the model’s base on
V_searchonly.search_spacemaps parameter names (dotted for nested ones, e.g."estimator_params.C") to aDistribution, a(low, high)pair (integers give an integer range) or a list of choices;Noneuses the built-in space of the base.sampleris"auto"(Optuna if installed, else seeded random search),"optuna"or"random". The tuned candidate is then evaluated on both layers likecreate_model: itsV_selectscore was never seen by the tuner.return_tuner=Truealso returns every trial.- Parâmetros:
model (str | CandidateSpec | ModelResult)
n_trials (int)
search_space (Mapping[str, Distribution | Sequence[Any]] | None)
sampler (str)
return_tuner (bool)
- Tipo de retorno:
- compare_models(include=None, sort=None)[código-fonte]¶
Budgeted search on
V_search, then incremental selection onV_select.includepicks the families:"standalone"(required: the initial champion is a single model),"residual","multistage"(extra correction stages on the best residual structures; needs"residual"),"decomposition"and"combination","ensemble"(ensembles of bases, of residual structures and corrected ensembles;ensemble_methods) and, in variant B,"dynamic"(dynamic selection of the corrector,drefandlocal)."exogenous"(models with the covariates ofX, and their residual corrections) challenges the univariate champion under the same acceptance rule.Nonemeans("standalone", "residual"), plus"exogenous"whenfitgotX.- Parâmetros:
- Tipo de retorno:
- get_standalone_reference(rule='initial_champion')[código-fonte]¶
Return a standalone reference from the last comparison, without accessing test data.
- Parâmetros:
rule (str) –
initial_championreturns the chain’s initial standalone, ranked on search with sufficient selection coverage.lowest_select_errorchooses the non-exogenous standalone finalist with the lowest finite selection error and sufficient coverage; candidate ID breaks ties.- Tipo de retorno:
The returned candidate can be finalized. In a panel its per-series configurations are preserved, as for the final champion.
- finalize_model(candidate)[código-fonte]¶
Refit the frozen candidate on the history before the sealed test.
In a panel each series is refitted with the configuration the selection chose for it for a selected finalist, including a standalone reference, and a
PanelForecasteris returned.- Parâmetros:
candidate (CandidateSpec | ModelResult)
- Tipo de retorno:
- predict_model(model, fh=None, X_future=None)[código-fonte]¶
Forecast from the end of the model’s training history; never refits.
A model with exogenous
futurecolumns takes their values for the horizon fromX_futureor, when omitted, from theXgiven tofit.- Parâmetros:
model (FinalizedForecaster | PanelForecaster)
fh (int | None)
X_future (DataFrame | None)
- Tipo de retorno:
- evaluate_external(model, y_test=None)[código-fonte]¶
Terminal evaluation, once per finalized model; the result never reaches the search.
Without
y_testthe sealed test of this experiment is used. An explicity_test(e.g. an official benchmark test) must start right after the model’s training cutoff.- Parâmetros:
model (FinalizedForecaster | PanelForecaster)
y_test (Series | SeriesFrame | None)
- Tipo de retorno:
- data_profile()[código-fonte]¶
Data quality report of the development history (the sealed test is excluded).
One column per series in a panel.
- Tipo de retorno:
- outlier_report(series_id=None, *, types=('AO', 'LS', 'TC'), threshold=4.0, decay=0.7, max_events=10)[código-fonte]¶
Optional exploratory AO/LS/TC screening, excluding the sealed test.
Returns candidate events and recommendations for review. Calling this method never modifies data or enables treatment in model search. Scores use OLS trend/seasonal controls, not ARIMA-adjusted significance tests. For model selection, detection and any chosen treatment must be fitted per training fold.
- seasonality_report(series_id=None, periods=None)[código-fonte]¶
Seasonality evidence on the development history (never the sealed test).
One row per candidate period (default: the experiment’s period): number of cycles, strength
F_sof the classical decomposition, autocorrelation of the detrended series at the period, Kruskal-Wallis p-value by position in the cycle, the rule’s decision and the suggested number of seasonal differences. Exploratory: the search decides inside the training data (seeseasonal_period="auto").
- characterize(series_id=None, periods=None)[código-fonte]¶
The replication project’s characterization of the development history.
Per series: ADF and KPSS at
d = 0, 1, 2, the stationarity decision andd(ADF:p <= 0.05and statistic below the 5 % critical value), and, for non-stationary series, the strength of a robust STL on the Box-Cox series for each period inperiods(default: the experiment’s period), the dominant period and the category (stationary,nonseasonal,seasonalwhen the strength exceeds 0.5). Exploratory: never reads the sealed test.
- stationarity_report(series_id=None, max_d=2)[código-fonte]¶
ADF and KPSS at
d = 0..max_don the development history, with their consensus.One row per series and order: statistics, p-values, each rule’s decision and
consensus(both say stationary). The smallest passing order of each rule is in the table’sattrs(d_adf,d_kpss,d_consensus) for one series, and in the columns of the same name for a panel. Exploratory: never reads the sealed test.
- decompose(method='stl', series_id=None, period=None)[código-fonte]¶
Trend, seasonal and remainder of the development history, indexed by date.
method="stl"is a robust STL (statsmodels);"classical"the centred moving average with mean seasonal indices (numpy; the trend isNaNat the edges). Exploratory: thedecompositionstrategy recomputes its own decomposition on each origin’s training data.
- residual_diagnostics(base, series_id=None, lags=None, **params)[código-fonte]¶
Ljung-Box test of a base model’s one-step out-of-sample residuals.
The base is fitted on the first part of the development history and forecasts the rest one step at a time with frozen parameters, as the
historical_oof_1stepresiduals that correctors learn from. Autocorrelation left in these residuals (small p-values) is room for a residual corrector. Default lags:min(10, n/5)and twice the seasonal period. Never reads the sealed test.
- plot_characterization(periods=None)[código-fonte]¶
ADF statistic against seasonal strength for every series (see
characterize).- Parâmetros:
- Tipo de retorno:
- plot_data(plot='series', series_id=None)[código-fonte]¶
A plot of the development history (never the sealed test).
series,acf,seasonality(mean by position),distribution,stationarity(the series at d = 0, 1, 2 with ADF/KPSS p-values and the ADF choice),acf_pacf(at that order) ordecomposition(robust STL of the Box-Cox series at the experiment’s period).- Parâmetros:
- Tipo de retorno:
- plot_model(candidate, plot='cv_forecasts', series_id=None)[código-fonte]¶
Validation diagnostics of a candidate; never uses the sealed test.
In a panel the forecast plots show one series (
series_id, default the first).- Parâmetros:
candidate (CandidateSpec | ModelResult)
plot (str)
series_id (str | None)
- Tipo de retorno:
- get_metrics(candidate=None)[código-fonte]¶
Per-origin metrics of
candidate, or a per-layer summary of everything evaluated.- Parâmetros:
candidate (CandidateSpec | ModelResult | None)
- Tipo de retorno:
- export_evidence(path, plots=(), *, external=(), nested=None, figure_formats=('png',), include_predictions=False)[código-fonte]¶
Tables, decisions, splits and manifest of the last
compare_models.externalandnestedare caller-supplied, already computed results; exporting never evaluates or refits a model. External predictions and actuals requireinclude_predictions=True.figure_formatsaccepts png/pdf/svg.- Parâmetros:
external (Sequence[ExternalResult])
nested (NestedCVResult | None)
include_predictions (bool)
- Tipo de retorno:
EvidenceBundle
- cross_validate(models=None, folds=5, fold_strategy=None, step=None, window_size=None, horizon=None, reference=0)[código-fonte]¶
Rolling-origin temporal cross-validation of several models on the same folds.
Runs on the development history only (never the sealed test) with its own folds, independent of
V_search/V_select.modelsaccepts names (default parameters of this experiment), specs orModelResult; by default the finalists ofcompare_models(champion first) or every configured base model. Use the result for reporting; selection keeps its own protocol.- Parâmetros:
- Tipo de retorno:
- compare_external(models=None, reference=0)[código-fonte]¶
Terminal comparison on the sealed test, at most one evaluation per model.
Each model is finalized (refit on the pre-test history) and evaluated once; a model already evaluated reuses its result. Report it; do not go back and change the configuration because of it, or the test becomes validation.
- Parâmetros:
models (Sequence[str | CandidateSpec | ModelResult] | None)
- Tipo de retorno:
- nested_cross_validate(outer_folds=3, baselines=('naive', 'seasonal_naive'), budget=None, include=None, standalone_reference='initial_champion')[código-fonte]¶
Estimate how the whole automated procedure generalizes.
For each outer origin (the last
outer_foldsblocks offhpoints of the development history), a fresh experiment with these parameters searches and selects using only the history before that origin; its champion is refitted there and scored on the next block, side by side with fixedbaselinesand withbest_standalone: an inner standalone reference chosen without the outer block.standalone_reference="initial_champion"keeps the chain’s initial champion (the compatible default);"lowest_select_error"chooses the non-exogenous standalone finalist with the lowest valid inner selection error. The folds table recordsstandalone_reference_ruleand candidate IDs.Variant A forecasts the outer block at once. Variant B reveals each observation only after its one-step forecast; all fitted parameters stay frozen. The same information protocol applies to the champion, standalone reference and baselines.
includeare the families of the innercompare_models;Nonerepeats the ones of this experiment’s lastcompare_models(the procedure being estimated), or its default when it has not run.result.costhas the work done per outer fold (candidates, units, seconds), so the procedure’s cost can be reconstructed.In a panel every series is cut at its own outer origin, the inner experiment runs on the whole truncated panel and the folds table has one row per fold and series; the summary averages over all of them. Each finalist’s per-series configuration is preserved when refitting the inner standalone reference.
- classmethod from_snapshot(snapshot)[código-fonte]¶
Rebuild an experiment with the parameters recorded in a
CompareResultsnapshot.- Parâmetros:
- Tipo de retorno:
- exog_report()[código-fonte]¶
How the exogenous features were chosen: one row per method and candidate feature.
Columns:
method,column,lag,feature,score,p_value(when the method has one) andselected. Computed infiton the training vector before the firstV_selectorigin.- Tipo de retorno:
- compare_exog()[código-fonte]¶
Best finalist with covariates against the best without, on the same
V_selectunits.Reporting only (Wilcoxon and Diebold-Mariano in
.tests(), Holm-adjusted); the decision is the acceptance rule’s, incompare_models().decisions. For the sealed test, finalize both and usecompare_external.- Tipo de retorno:
- class autohybts.AutoHybridForecaster(**params)[código-fonte]¶
Base:
ParametrizedExperiment, selection and finalization in one call, for operational forecasting.
- Parâmetros:
**params (Any) – any parameter of
AutoHybridExperiment(fh,budget,variant…);test_sizedefaults to 0 here, so the whole series is used and nothing is sealed. The fitted experiment, the comparison and the finalized model stay inexperiment_,compare_andmodel_.
- get_params()[código-fonte]¶
- fit(y)[código-fonte]¶
- Parâmetros:
y (Series | SeriesFrame | PanelFrame | Mapping[str, Series])
- Tipo de retorno:
- predict(fh=None)[código-fonte]¶
- leaderboard()[código-fonte]¶
- Tipo de retorno:
- get_best_model()[código-fonte]¶
- Tipo de retorno:
Dados¶
- class autohybts.PanelFrame(series)[código-fonte]¶
Base:
objectOrdered collection of
SeriesFramewith unique ids and one frequency.- classmethod single(frame)[código-fonte]¶
- Parâmetros:
frame (SeriesFrame)
- Tipo de retorno:
- classmethod from_dict(data, frequency=None)[código-fonte]¶
One
pd.Series(indexed by date) per series id.- Parâmetros:
- Tipo de retorno:
- classmethod from_long(data, *, series_col, date_col, target, frequency=None)[código-fonte]¶
Long table with one row per (series, date); columns are named explicitly.
- to_long()[código-fonte]¶
- Tipo de retorno:
- autohybts.datasets.get_data(name, **kwargs)[código-fonte]¶
A named series as
pd.Serieswith a regularDatetimeIndex.Offline examples:
"synthetic_daily","white_noise_daily","intermittent_daily","commodity_price_daily"; keyword arguments go to the generator (n,seed…).Benchmark series:
"m4:D1"or"m3:N1402"— downloaded once to the cache (keywordsoffline,cache_dir). The official test is at the end; seal it withtest_sizeequal to the benchmark horizon.Well-known Rdatasets series by short name (
"ozone","air_passengers"…, seeNAMED_SERIES; case is ignored), downloaded the same way.
- autohybts.datasets.list_datasets(provider=None, *, subset=None, search=None, offline=False, cache_dir=None, cache=None)[código-fonte]¶
Catalogue of a provider (
m4,m3,rdatasets), or of providers ifNone.Without a provider nothing is downloaded.
subsetfilters M3/M4 by frequency;searchfilters Rdatasets by package, name and title.
- autohybts.datasets.load_benchmark(name, subset, *, split='official', series_id=None, offline=False, cache_dir=None, cache=None)[código-fonte]¶
M4 or M3 with the official split; one
BenchmarkSerieswhenseries_idis given.The official test stays apart (
.test); seal it withAutoHybridExperiment(test_size=len(series.test)).fit(series.full())so it never reaches the search or the selection.- Parâmetros:
- Tipo de retorno:
- autohybts.datasets.load_dataset(provider, *, package=None, name=None, target=None, time_col=None, frequency=None, offline=False, cache_dir=None, cache=None, **options)[código-fonte]¶
One dataset of any provider; Rdatasets needs
target,time_colandfrequency.- Parâmetros:
- Tipo de retorno:
- autohybts.datasets.raw_dataset(provider, *, package, name, offline=False, cache_dir=None, cache=None)[código-fonte]¶
A Rdatasets table exactly as published, to choose its columns.
- autohybts.datasets.describe_dataset(provider, subset=None, *, offline=False, cache_dir=None, cache=None)[código-fonte]¶
Descriptor of a benchmark subset (downloads only the catalogue files).
- Parâmetros:
- Tipo de retorno:
- autohybts.datasets.list_exog_datasets()[código-fonte]¶
The series with covariates: target, columns, frequency and which columns are
future.- Tipo de retorno:
- autohybts.datasets.load_exog_dataset(name, **kwargs)[código-fonte]¶
(y, X)of a series with covariates; downloaded once to the cache.Keywords go to the download (
offline,cache_dir,cache). Use the dataset’sfuturecolumns (list_exog_datasets()) asexog_future.
- class autohybts.data.exog.ExogFrame(timestamps, values, columns, kinds)[código-fonte]¶
Base:
objectValidated covariates of one series, with the kind of each column.
Build it with
ExogFrame.from_frame(X, future=[...]). The index may extend past the series (values offuturecolumns for the forecast horizon).- Parâmetros:
timestamps (DatetimeIndex)
values (NDArray[float64])
- timestamps: DatetimeIndex¶
- values: NDArray[float64]¶
- classmethod from_frame(frame, future=())[código-fonte]¶
Covariates from a
DataFrameindexed by date;futurenames known columns.
- kind(column)[código-fonte]¶
- default_features(step, columns=None)[código-fonte]¶
Each column at its smallest causal lag: 0 for
future,stepforpast.
- check(features, step)[código-fonte]¶
Refuse a
pastfeature lagged by less thanstep(it would leak).
- design(features, timeline, step)[código-fonte]¶
Feature matrix on
timeline(the series dates, optionally extended).- Parâmetros:
features (Sequence[ExogFeature])
timeline (DatetimeIndex)
step (int)
- Tipo de retorno:
ExogDesign
- to_frame()[código-fonte]¶
The covariates as a
DataFrameindexed by date (a copy).- Tipo de retorno:
- describe()[código-fonte]¶
- autohybts.data.exog_selection.select_exog(y, covariates, kinds, step, method, *, max_lag=None, seed=0)[código-fonte]¶
Features of
covariateschosen bymethodon the training valuesy.covariateshas one row per value ofy(same dates).pastlags go fromsteptomax_lag(defaultstep + 6).
- class autohybts.datasets.BenchmarkSeries(train, test, descriptor)[código-fonte]¶
Base:
objectOne series with its official split:
trainfor the search,testsealed.full()gives train and test back to back, soAutoHybridExperiment(fh=h, test_size=len(test)).fit(series.full())seals exactly the official test.- Parâmetros:
train (Series)
test (Series | None)
descriptor (DatasetDescriptor)
- descriptor: DatasetDescriptor¶
- full()[código-fonte]¶
- Tipo de retorno:
- class autohybts.datasets.BenchmarkDataset(train, test, metadata, descriptor)[código-fonte]¶
Base:
objectMany series in long format (
series_id,timestamp,value).- Parâmetros:
train (DataFrame)
test (DataFrame | None)
metadata (DataFrame | None)
descriptor (DatasetDescriptor)
- descriptor: DatasetDescriptor¶
- series(series_id)[código-fonte]¶
- Parâmetros:
series_id (str)
- Tipo de retorno:
- panel(series_ids=None, *, with_test=True)[código-fonte]¶
Series as a panel;
with_testappends each official test (to be sealed).- Parâmetros:
- Tipo de retorno:
- class autohybts.datasets.DatasetDescriptor(provider, dataset_id, source_url, version, license, frequency, horizon, target_name, time_col, series_id_col, split_kind, extra=<factory>)[código-fonte]¶
Base:
objectWhere a dataset came from and how it is split; kept in manifests.
- Parâmetros:
- to_dict()[código-fonte]¶
- class autohybts.datasets.CacheManager(root=None, *, offline=False, timeout=60.0, retries=2, opener=None)[código-fonte]¶
Base:
object- Parâmetros:
- path(provider, filename)[código-fonte]¶
- manifest_path(provider, filename)[código-fonte]¶
- read_manifest(provider, filename)[código-fonte]¶
- fetch(provider, remote, *, allowed_domains, license=None, version=None, refresh=False)[código-fonte]¶
Path of
remotein the cache, downloading it first if needed and allowed.
- verify(provider, remote)[código-fonte]¶
Refuse a cached file whose bytes differ from its manifest or pinned checksum.
- Parâmetros:
provider (str)
remote (RemoteFile)
- Tipo de retorno:
None
Modelos finalizados e persistência¶
- class autohybts.FinalizedForecaster(spec, model, history, seed, manifest=<factory>, n_trained=None, exog=None)[código-fonte]¶
Base:
objectStructure and hyper-parameters frozen at selection; coefficients refitted on
history.Holds the history it was fitted on because forecasting needs it (lags, filter state, residual windows). Forecasts start right after
training_cutoff.With exogenous features (ADR-0011)
exogkeeps the covariates up to the last observation;predicttakes the values offuturecolumns for the horizon (X_future) andupdate_statethe covariates of the new dates (X_new).- Parâmetros:
- spec: CandidateSpec¶
- model: BaseForecaster¶
- history: SeriesFrame¶
- property last_observation: Timestamp¶
Last observation known to the model (fit or later updates); forecasts start after it.
- update_state(observations, *, refit=False, X_new=None)[código-fonte]¶
Same fitted model, longer history: new observations change the state, not the fit.
Returns a new object;
refit=Trueis refused because re-estimating parameters is a separate, explicit operation (finalize_modelon the longer series). A model with exogenous features takes the covariates of the new dates inX_new.- Parâmetros:
- Tipo de retorno:
- stream()[código-fonte]¶
Rolling one-step forecasting with observations arriving one at a time (variant B).
- Tipo de retorno:
- context(horizon=0, X_future=None)[código-fonte]¶
What the model sees at its last observation; with exogenous features, their rows up to
horizondates ahead (futurecolumns fromX_future).
- predict(fh, X_future=None)[código-fonte]¶
fhsteps after the last observation, indexed by date; no refit happens here.A model with exogenous
futurecolumns needs their values for thefhdates inX_future;pastcolumns come from the history.
- class autohybts.PanelForecaster(models, spec, manifest=<factory>)[código-fonte]¶
Base:
objectOne finalized model per series; each series keeps its own configuration and cutoff.
- Parâmetros:
models (Mapping[str, FinalizedForecaster])
spec (CandidateSpec)
- models: Mapping[str, FinalizedForecaster]¶
- spec: CandidateSpec¶
- class autohybts.forecasting.finalized.ForecastStream(model)[código-fonte]¶
Base:
objectpredict_nextthenobserve, in strict alternation; parameters stay frozen.- Parâmetros:
model (FinalizedForecaster)
- property model: FinalizedForecaster¶
The forecaster with every observation received so far.
- predict_next(exog=None)[código-fonte]¶
Forecast the next step;
observemust reveal its value before the next call.exogholds the covariates of the date being forecast (a mapping orSeriesby column, or a one-rowDataFrame), needed forfuturecolumns.- Parâmetros:
exog (Any)
- Tipo de retorno:
- observe(value, exog=None)[código-fonte]¶
Reveal the value forecast by the pending ticket; the model is not refitted.
exogadds covariates observed with the value (pastcolumns of that date).
- log()[código-fonte]¶
Every ticket with the value that was later observed.
- Tipo de retorno:
- class autohybts.forecasting.finalized.ForecastTicket(origin, timestamp, prediction, base_prediction, correction)[código-fonte]¶
Base:
objectA one-step forecast issued before the value it forecasts is observed.
- Variáveis:
origin (pandas.Timestamp) – last observation the forecast used.
timestamp (pandas.Timestamp) – date being forecast.
prediction (float) – the forecast (
base_prediction + correction).base_prediction (float) – the base model’s part.
correction (float) – the residual corrector’s part (0 without a corrector).
- Parâmetros:
- autohybts.save_model(model, path, *, signing_key=None)[código-fonte]¶
Write
modelto the directorypath(created if needed); returns the directory.With
signing_key(a secret kept outside the artifact), the manifest also records an HMAC-SHA256 of the payload thatload_model(..., signing_key=...)requires.- Parâmetros:
model (FinalizedForecaster | PanelForecaster)
signing_key (bytes | None)
- Tipo de retorno:
- autohybts.load_model(path, *, trusted=False, sha256=None, signing_key=None)[código-fonte]¶
Load a finalized model; requires
trusted=Truebecause unpickling runs code.sha256pins the payload hash andsigning_keyrequires the HMAC written bysave_model; both are checked before anything is unpickled.- Parâmetros:
- Tipo de retorno:
- autohybts.read_manifest(path)[código-fonte]¶
Inspect an artifact without executing anything.
- class autohybts.ExperimentStore(path)[código-fonte]¶
Base:
objectExperiments, evaluations and finalized models in one SQLite file.
The file and its tables are created on the first write.
logrecords an experiment as a run;queryruns SQL on a read-only connection and returns aDataFrame.- Parâmetros:
path (str | Path) – SQLite file (created if needed on the first
log).
- log(experiment, *, name='run', tags=None, models=(), values=False)[código-fonte]¶
Record
experimentas a run and return itsrun_id.Everything the experiment has computed so far is written: series identity (no values), splits, evaluated candidates with per-layer and per-origin metrics and, after
compare_models, the search ledger, the selection decisions and the champion.modelsadds finalized models; external evaluations already made are written as metrics and, withvalues=True, as predictions with observations.The
run_iddepends on the experiment’s settings, data, temporal plan andname: logging the same experiment again replaces its rows (for instance afterevaluate_external) instead of duplicating them.- Parâmetros:
experiment (AutoHybridExperiment)
name (str)
tags (Mapping[str, Any] | None)
models (Sequence[FinalizedForecaster | PanelForecaster])
values (bool)
- Tipo de retorno:
- delete_run(run_id)[código-fonte]¶
Remove every row of
run_id.- Parâmetros:
run_id (str)
- Tipo de retorno:
None
- query(sql, params=())[código-fonte]¶
Run
sqlon a read-only connection and return the result as aDataFrame.Pass values through
params(?or:nameplaceholders), never by formatting them into the SQL text.
- runs()[código-fonte]¶
One row per run, newest first, without the JSON columns.
- Tipo de retorno:
- tables()[código-fonte]¶
Names of the tables of the store’s schema.
- register_model(model, path, *, name, run_id=None, reference_mae=None)[código-fonte]¶
Register a model saved with
save_modelundername, as acandidate.The registry keeps the artifact’s path and the payload SHA-256 read from its manifest, never the model itself.
reference_maeis the error the model is expected to keep in production (for instance the MAE ofevaluate_external);monitorcompares the live error with it. Registering again keeps the stage.
- promote(model_id, stage='production', reason='')[código-fonte]¶
Move a registered model to
stage; a new production model archives the old one.Every change is kept in
stage_historywith itsreason.
- registry(name=None)[código-fonte]¶
Registered models (all, or those of
name), newest first.
- load(name, stage='production', *, trusted=False, signing_key=None)[código-fonte]¶
Load the model of
nameinstagewithload_model.The payload must match the SHA-256 recorded at registration. Like that hash, the database sits next to the artifacts, so it catches corruption, not tampering: pass
signing_keyfor artifacts saved with one.- Parâmetros:
- Tipo de retorno:
- log_forecasts(model_id, forecasts)[código-fonte]¶
Record forecasts of a registered model made in production; returns the row count.
forecastshasy_predand atimestampcolumn or index;origin,horizon(default 1) andseries_id(default: the model’s series) are optional, as in the tables ofpredict_modelandForecastStream.log().
- log_actuals(series_id, actuals)[código-fonte]¶
Record observed values of
series_id(indexed by timestamp); returns the count.A value logged again for the same timestamp replaces the previous one.
- log_covariates(series_id, covariates)[código-fonte]¶
Record exogenous values of
series_idby date and column; returns the count.covariatesis indexed by date with one column per covariate (missing cells are skipped). A value logged again for the same date and column replaces the previous one, e.g. a weather forecast later replaced by the observed value.
- covariates(series_id, start=None, end=None)[código-fonte]¶
Recorded covariates of
series_idas aDataFrame(dates × columns).startandendbound the dates (inclusive); the result is ready forupdate_state(..., X_new=...)orpredict(..., X_future=...).
- monitor(model_id, *, window=30, threshold=1.5, horizon=1)[código-fonte]¶
Live error of a registered model: rolling MAE against its
reference_mae.One row per forecast (of
horizon) whose observation has arrived, with the absolute error, the MAE over the lastwindowsuch forecasts, the ratio to the reference andalert: a full window whose MAE exceedsthresholdtimes the reference. Without a reference,ratiois empty andalertis false.
Resultados¶
- class autohybts.results.CompareResult(best, leaderboard, selection_leaderboard, decisions, audit, search, selection, snapshot, comparison=None, events=<factory>)[código-fonte]¶
Base:
objectSearch on
V_searchand incremental selection onV_select.- Variáveis:
best (autohybts.domain.specs.CandidateSpec) – the champion (a
CandidateSpec), ready forfinalize_model.leaderboard (pandas.DataFrame) – one row per evaluated candidate of the search (
V_search), sorted by the first metric, withmean_rank, metric means,coverage,n_units, failures and fit/predict seconds;is_championmarks the champion.selection_leaderboard (pandas.DataFrame) – the same columns for the finalists on
V_select.decisions (pandas.DataFrame) – one row per challenge of the incremental chain:
family,champion_before,challenger,accepted,reason_codes,median_gain,win_rate,variability_status,variability_valueandp_value(withsignificance_alpha).audit (autohybts.selection.incremental.SelectionAudit) – how adaptive the selection was (
SelectionAudit).search (autohybts.search.ledger.SearchResult) – everything the search tried (
SearchResult;ledger_frame()).selection (autohybts.selection.incremental.SelectionResult) – the selection itself (
SelectionResult;decision_units_frame()and, in a panel,champion_per_seriesandfinalist_per_series).snapshot (dict[str, Any]) – what must stay fixed to reproduce the selection (settings, splits, space, budget, policy, protocol hash, champion).
comparison (autohybts.reporting.comparison.ComparisonResult | None) – statistical comparison of the finalists on
V_select(ComparisonResult), orNone.events (tuple[autohybts.results.Event, ...]) – timed log of the experiment verbs.
- Parâmetros:
best (CandidateSpec)
leaderboard (DataFrame)
selection_leaderboard (DataFrame)
decisions (DataFrame)
audit (SelectionAudit)
search (SearchResult)
selection (SelectionResult)
comparison (ComparisonResult | None)
events (tuple[Event, ...])
- best: CandidateSpec¶
- audit: SelectionAudit¶
- search: SearchResult¶
- selection: SelectionResult¶
- comparison: ComparisonResult | None = None¶
- strategy_table()[código-fonte]¶
Every candidate of the search: score on
V_search, cost, complexity, Pareto.- Tipo de retorno:
- property strategies: DataFrame¶
best and median score, cost.
- Type:
Per strategy (standalone, residual, multistage …)
- plot(kind='pareto', x='cost')[código-fonte]¶
pareto(error × cost, or × complexity withx="complexity") andstrategiesover every searched candidate; the comparison plots (leaderboard,boxplot,win_rate…) over the finalists onV_select.- Parâmetros:
- Tipo de retorno:
- class autohybts.results.ModelResult(candidate, evaluation)[código-fonte]¶
Base:
objectOne candidate evaluated on every origin (search and select layers).
- Parâmetros:
candidate (CandidateSpec)
evaluation (EvaluationResult)
- candidate: CandidateSpec¶
- evaluation: EvaluationResult¶
- class autohybts.results.ExternalResult(metrics, predictions, model_label)[código-fonte]¶
Base:
objectTerminal evaluation on the sealed (or an external) test; never fed back to the search.
- Variáveis:
metrics (pandas.DataFrame) – one row per model (and per series, plus the mean, in a panel).
predictions (pandas.DataFrame) –
y_predandy_trueover the test, indexed by date.model_label (str) – label of the evaluated structure.
- Parâmetros:
- class autohybts.results.PredictResult(predictions, model_label)[código-fonte]¶
Base:
objectForecasts of a finalized model.
- Variáveis:
predictions (pandas.DataFrame) –
y_predindexed by date (stacked by series in a panel).model_label (str) – label of the forecasting structure.
- Parâmetros:
- class autohybts.results.ExternalComparison(table, steps, tests, reference)[código-fonte]¶
Base:
objectTerminal comparison on the sealed test: reporting only, never fed back.
testscompares each model with the reference on per-step absolute errors of the single test block (Diebold-Mariano withfh - 1Newey-West lags, Holm-adjusted).
- class autohybts.results.NestedCVResult(folds, summary, metric, include=(), cost=<factory>, snapshots=())[código-fonte]¶
Base:
objectOuter rolling-origin evaluation of the whole automated procedure.
In each outer fold the search and the selection ran again on the history before the outer origin only; the outer block was never seen by them.
includeare the families of the inner searches;costhas one row per outer fold with the work done there: candidates and units (origin x series) of the inner search and selection, configured budget, stop reason and seconds (search, selection, refit, total).snapshotsrecords the resolved inner comparison configuration by fold.- Parâmetros:
- class autohybts.search.ledger.SearchResult(metric, plan_fingerprint, ledger, results, retained, residual_structures, stop_reason, protocol, elapsed_s=0.0)[código-fonte]¶
Base:
objectEverything the search tried and what it found, on
V_searchonly.- Variáveis:
metric (str) – metric that ranked the candidates.
plan_fingerprint (str) – fingerprint of the temporal plan the search used.
ledger (tuple[autohybts.search.ledger.LedgerEntry, ...]) – every proposal, evaluated or not, with stage, status (
EVALUATED,PRUNED_BUDGET,SKIPPED_CAPABILITY,DUPLICATE,STOPPED) and reason;ledger_frame()gives it as a table.results (tuple[autohybts.domain.results.EvaluationResult, ...]) – evaluation of every evaluated candidate.
retained (tuple[str, ...]) – bases retained for the hybrids (stage S1).
residual_structures (tuple[str, ...]) – residual structures carried to refinement.
stop_reason (str) –
"completed", a budget limit or"max_wall_time".protocol (dict[str, object]) – pre-registered settings of the search and their hash.
elapsed_s (float) – wall time of the search.
- Parâmetros:
- property cached_count: int¶
Evaluated candidates whose result came from the trial cache (nothing refitted).
- property unit_count: int¶
Units (origin x series) actually evaluated, cache hits excluded.
Each unit is one fresh model trained at one origin; how many model fits a unit needs depends on the strategy, see
fit_count.
- property fit_count: int¶
Leaf model fits behind the evaluated candidates, cache hits excluded.
A residual hybrid at one origin counts its base, the extra base fit that produces the out-of-fold residuals and its corrector (
domain.fit_count).
- counts()[código-fonte]¶
- result(candidate_id)[código-fonte]¶
- Parâmetros:
candidate_id (str)
- Tipo de retorno:
EvaluationResult
- ledger_frame()[código-fonte]¶
- Tipo de retorno:
- class autohybts.selection.incremental.SelectionResult(champion, champion_result, finalists, decisions, audit, champion_per_series=<factory>, finalist_per_series=<factory>)[código-fonte]¶
Base:
objectOutcome of the incremental selection on
V_select.championis the final champion andchampion_resultits evaluation;finalistsholds the best structure of each family, evaluated onV_select;decisionsrecords every challenge, accepted or not, with per-unit errors and gains (decisions_frame()anddecision_units_frame()give them as tables);auditis theSelectionAudit; in a panel,champion_per_seriesholds the configuration chosen for each series.finalist_per_seriespreserves these configurations for every finalist, keyed by its representative candidate ID.- Parâmetros:
champion (CandidateSpec)
champion_result (EvaluationResult)
finalists (tuple[EvaluationResult, ...])
decisions (tuple[SelectionDecision, ...])
audit (SelectionAudit)
champion_per_series (Mapping[str, CandidateSpec])
finalist_per_series (Mapping[str, Mapping[str, CandidateSpec]])
- champion: CandidateSpec¶
- champion_result: EvaluationResult¶
- audit: SelectionAudit¶
- champion_per_series: Mapping[str, CandidateSpec]¶
- decisions_frame()[código-fonte]¶
One row per decision; models by short name, full label and ids at the end.
- Tipo de retorno:
- decision_units_frame()[código-fonte]¶
One row per decision and compared unit: both errors, the gain and the win.
Everything a decision used is here, so median gain and win rate can be recomputed (and resampled by unit or series) outside the library.
- Tipo de retorno:
- class autohybts.selection.incremental.SelectionAudit(protocol_hash, search_protocol_hash, total_trials, tried_by_family, pruned_trials, failed_trials, finalist_ids, winner_id, comparison_origin_ids, decision_reasons, exploratory, search_best_score, winner_search_score, winner_select_score)[código-fonte]¶
Base:
objectEvidence of how adaptive the selection was: trials, pruning, finalists, reasons.
selection_gap()compares the winner’s score onV_searchwith its score onV_select: a large gap signals optimism from choosing where it was searched.
- class autohybts.reporting.plots.PlotArtifact(kind, figure, source_split, candidate_id=None, origin_range=None, provenance=<factory>, backend='matplotlib')[código-fonte]¶
Base:
objectA matplotlib figure plus where its numbers come from.
figureis thematplotlib.figure.Figure(Jupyter displays it;savewrites it).kindis the plot requested,source_splitthe data it used ("development","validation"…, never the sealed test),candidate_idthe candidate drawn,origin_rangethe first and last date covered andprovenancethe counts and settings behind the figure.- Parâmetros:
- save(path)[código-fonte]¶
Write the figure (format from the extension, e.g.
.pngor.svg).
- class autohybts.reporting.comparison.ComparisonResult(results, metric, history, source, reference=0, max_lag=0, splits=None)[código-fonte]¶
Base:
objectSeveral models scored on the same units, with tables, tests and plots.
- Parâmetros:
- history: SeriesFrame¶
- tests(reference=None)[código-fonte]¶
- kruskal()[código-fonte]¶
Kruskal-Wallis and Dunn (Holm); they ignore the pairing, prefer
friedman.
- plot(kind='leaderboard')[código-fonte]¶
Especificações¶
- class autohybts.domain.specs.CandidateSpec(family, strategy, base, corrector=None, window_size=None, alpha=None, residual_source=None, variant='A', members=(), options_json='{}', components=(), exog=())[código-fonte]¶
Base:
objectOne configuration to evaluate: strategy, base, optional corrector, variant.
Strategies and the fields they use:
standalone:baseonly.residual_additive:base + alpha * correctoron residual windows.residual_multistage: as above, then each corrector inmemberscorrects the residuals of the previous stage; at mostMAX_STAGESstages. Extra stages share window, alpha and source unlessoptions["stages"]gives, per extra stage, a dict with any ofwindow_size,alphaandresidual_source.decomposition:baseforecasts the smooth part andcorrectorthe volatile part on windows ofwindow_size;optionsholdsmethod("ma"or"stl", the latter only in variant A),ma_window(None: chosen by kurtosis on the training vector) andperiod(seasonal period, required by STL).fixed_combination:baseandmemberscombined with fixed weights;options["weights"]is"equal"or"inverse_mse"(estimated on the training vector only).residual_combination:base + alpha * Σ w_j r̂_j, the corrector and the correctors inmemberscombined with fixed weights (options["weights"]).ensemble:components(2 toMAX_COMPONENTScandidates of any strategy, including other compositions) combined byoptions["method"]inENSEMBLE_METHODS;trim(trimmed_mean) andshrinkage(nnls, towards equal weights) are filled with their defaults. The order of components is canonical (bycandidate_id): the combination is commutative.baseisCOMPOSITE_BASE.residual_composite:component + alpha * correctoron the residual windows of one composed candidate (componentsholds it), e.g. a residual correction of an ensemble; residual fields as inresidual_additive.baseisCOMPOSITE_BASE.
members,optionsandcomponentsentercandidate_idonly when non-empty, so identities of the other strategies do not change. Compositions nest up toMAX_DEPTHlevels.exog(ADR-0011) lists the exogenous features the base receives; it applies tostandalone,residual_additiveandresidual_multistageand, like the fields above, enterscandidate_idonly when non-empty.- Parâmetros:
- components: tuple[CandidateSpec, ...]¶
- property depth: int¶
0 for a single structure (a base, a hybrid …), 1 + the deepest component for an ensemble or a residual composition.
- Type:
Levels of composition
- model_names()[código-fonte]¶
Every registered model this candidate uses, as
(kind, name), in order.
- classmethod ensemble(components, *, method='equal', family='ensemble', **options)[código-fonte]¶
Ensemble of
components(variant taken from them; they must agree).- Parâmetros:
components (Sequence[CandidateSpec])
method (str)
family (str)
options (Any)
- Tipo de retorno:
- classmethod corrected(component, corrector, window_size, alpha, residual_source, *, family='ensemble')[código-fonte]¶
Residual correction of a composed
component(e.g. of an ensemble).- Parâmetros:
- Tipo de retorno:
- classmethod standalone(name, params=None, *, family, variant='A')[código-fonte]¶
- describe()[código-fonte]¶
Canonical content of the spec; the source of
candidate_id.
- class autohybts.domain.specs.ModelSpec(name, params_json='{}')[código-fonte]¶
Base:
objectA registered model name plus its parameters, stored in canonical form.
Parameters are kept as canonical JSON, so the spec is deeply immutable and two specs with equal parameters (in any key order, tuples or lists) are equal.
- classmethod of(name, params=None)[código-fonte]¶
- describe()[código-fonte]¶
Busca, seleção e ajuste¶
- class autohybts.search.spaces.SearchSpace(base_models=('naive', 'seasonal_naive', 'linear', 'knn', 'svm', 'tree', 'random_forest', 'arima', 'mlp'), base_params=<factory>, correctors=('linear', 'knn', 'mlp'), corrector_params=<factory>, residual_windows=(7, 28), alphas=(0.5, 1.0), residual_sources=('historical_oof_1step', ), refine_sources=('historical_oof_multistep', 'in_sample'), seasonal_period=1, variant='A', max_stages=1, decomposition_methods=(), combination_weights=(), dynamic_methods=(), stage_params='shared', ensemble_methods=(), differencing=None, differencing_test='kpss', transform=None, outliers=None, exog_sets=())[código-fonte]¶
Base:
objectWhat the search may try; the default search space by default.
base_paramsandcorrector_paramsmap a model name to a grid (sequence of parameter dicts); a missing entry means the model’s defaults.refine_sourcesare the residual sources tried in S3 around the best residual structures.Advanced families are off by default:
max_stages > 1adds correction stages in S3;decomposition_methods,combination_weightsandensemble_methodsopen stage S4.exog_sets(ADR-0011) are sets of exogenous features; each one is tried in stage SX with every base that accepts covariates and then with residual correctors on the best of them, all in theexogenousfamily.- Parâmetros:
- describe()[código-fonte]¶
- base_proposals(registry)[código-fonte]¶
S0: every configured base, in the configured order.
- Parâmetros:
registry (ModelRegistry)
- Tipo de retorno:
list[Proposal]
- exog_proposals(registry)[código-fonte]¶
SX: every base that accepts covariates, with each exogenous feature set.
- Parâmetros:
registry (ModelRegistry)
- Tipo de retorno:
list[Proposal]
- exog_residual_proposals(bases, registry)[código-fonte]¶
SX: residual correctors on the best bases with covariates (one-step residuals).
Multi-step residual sources would read
pastfeatures further ahead than their lag inside the training vector, so onlyhistorical_oof_1stepis proposed.- Parâmetros:
bases (Sequence[CandidateSpec])
registry (ModelRegistry)
- Tipo de retorno:
list[Proposal]
- residual_proposals(bases, registry)[código-fonte]¶
S2: residual grid, breadth-first over the retained bases.
Each (source, corrector, window, alpha) combination is proposed for every retained base (best first) before the next combination, so a budget cut keeps the bases diverse instead of exhausting the grid of the first one.
- Parâmetros:
bases (Sequence[CandidateSpec])
registry (ModelRegistry)
- Tipo de retorno:
list[Proposal]
- refinement_proposals(structures, registry, max_refinements)[código-fonte]¶
S3: around each best residual structure, change one axis at a time.
Axes: residual source, corrector hyper-parameters and, when
max_stages > 1, extra correction stages. At mostmax_refinementsvariants per axis and structure.- Parâmetros:
structures (Sequence[CandidateSpec])
registry (ModelRegistry)
max_refinements (int)
- Tipo de retorno:
list[Proposal]
- advanced_proposals(bases, registry)[código-fonte]¶
S4: decompositions over the retained bases and fixed combinations of the best.
Decompositions go breadth-first over the bases, like the residual grid. A combination joins the two best retained bases of different families. The two lists are interleaved, so a budget cut keeps both families represented.
- Parâmetros:
bases (Sequence[CandidateSpec])
registry (ModelRegistry)
- Tipo de retorno:
list[Proposal]
- dynamic_proposals(structures, registry)[código-fonte]¶
S4 (variant B): dynamic selection around the best residual structures.
drefchooses, at each step, among the structure’s corrector, the other configured correctors and no correction;localcombines the base and the structure’s corrector locally. Grid of the legacy project (Silva et al., 2020): neighbourskinDYNAMIC_NEIGHBORS, lag size inDYNAMIC_LAGSand, forlocal, the kernel ridgealphainLOCAL_ALPHAS. The first value of each axis is the default; defaults of every method come first, so a budget cut keeps them.- Parâmetros:
structures (Sequence[CandidateSpec])
registry (ModelRegistry)
- Tipo de retorno:
list[Proposal]
- corrector_combination_proposals(structures, registry)[código-fonte]¶
S4: around each best residual structure, its corrector combined with the others.
- Parâmetros:
structures (Sequence[CandidateSpec])
registry (ModelRegistry)
- Tipo de retorno:
list[Proposal]
- ensemble_proposals(bases, structures, registry)[código-fonte]¶
S4: ensembles (family
ensemble), all from candidates already searched.Ensembles of bases: the best retained base of each family, up to
ENSEMBLE_SIZE(diversity of families before more members), with every configured method;medianneeds 3 members andtrimmed_meanis left to explicit use (with 3 members it equals the median).Ensemble of hybrids: the two best residual structures, weighted methods only.
Corrected ensemble: the equal-weight ensemble of bases corrected by each configured corrector (first window, alpha and source of the space).
The equal-weight version of each kind comes first, so a budget cut keeps the simplest control of every kind.
- Parâmetros:
bases (Sequence[CandidateSpec])
structures (Sequence[CandidateSpec])
registry (ModelRegistry)
- Tipo de retorno:
list[Proposal]
- class autohybts.search.budgets.SearchGuardConfig(mode: 'GuardMode' = 'standard', max_trials_total: 'int' = 200, max_trials_per_family: 'int' = 40, max_candidates_per_stage: 'int' = 60, max_refinements: 'int' = 2, max_wall_time_s: 'float | None' = None, top_k_per_family: 'int' = 2, top_k_residual_structures: 'int' = 2, require_full_pairing: 'bool' = True, prefer_simpler_on_tie: 'bool' = True, allow_test_feedback_to_search: 'bool' = False)[código-fonte]¶
Base:
object- Parâmetros:
mode (Literal['research_strict', 'standard', 'exploratory'])
max_trials_total (int)
max_trials_per_family (int)
max_candidates_per_stage (int)
max_refinements (int)
max_wall_time_s (float | None)
top_k_per_family (int)
top_k_residual_structures (int)
require_full_pairing (bool)
prefer_simpler_on_tie (bool)
allow_test_feedback_to_search (bool)
- classmethod preset(name, **overrides)[código-fonte]¶
- Parâmetros:
- Tipo de retorno:
- describe()[código-fonte]¶
- class autohybts.selection.policy.SelectionPolicy(profile='standard', median_gain_threshold=0.05, win_rate_threshold=0.6, variability=<factory>, min_coverage=1.0, epsilon=1e-12, family_order=('statistical', 'linear', 'kernel', 'tree', 'neural', 'residual', 'decomposition', 'combination', 'dynamic'), significance_alpha=None)[código-fonte]¶
Base:
objectProfile and thresholds of the incremental guarded selection.
Profiles:
quickstart: variability off by default, declared in every decision.standard: protocol thresholds with the variability criterion on.research_strict: likestandard; refuses to run without a variability criterion or withmin_coverage < 1.exploratory: decisions are flagged as exploratory, never as unbiased.
significance_alpha(off by default) adds a statistical predicate: the challenger must also beat the champion in a one-sided paired Wilcoxon signed-rank test on the same units,p < significance_alpha. The protocol rule alone is not error control. The test bounds the false acceptance of one comparison atalpha, under its assumptions (independent, symmetric paired differences); it does not control the whole chain, where several families challenge a champion that changes with the earlier decisions, nor the dependence between overlapping origins. Measure the chain’s behaviour withautohybts.benchmarks.calibration.Units with equal errors are dropped before the test, so
nis the number of non-zero paired differences (all series of a panel together). With the exact null distribution the smallest one-sided p-value is1 / 2**n: at least 5 such units foralpha = 0.05; withfold=3on one series the predicate can never pass. The p-value comes from SciPy’s default method, which depends on the SciPy version (exact for smallnin recent versions, a normal approximation in some cases), so it can move slightly between environments.- Parâmetros:
- classmethod quickstart(**overrides)[código-fonte]¶
- Parâmetros:
overrides (object)
- Tipo de retorno:
- describe()[código-fonte]¶
- class autohybts.search.tuning.Distribution(kind, low=0.0, high=0.0, choices=())[código-fonte]¶
Base:
objectOne tunable parameter. Dotted names (
estimator_params.C) set nested keys.- Parâmetros:
- sample(rng)[código-fonte]¶
- Parâmetros:
rng (Generator)
- Tipo de retorno:
- suggest(trial, name)[código-fonte]¶
- class autohybts.search.tuning.TuningResult(original, best, trials, sampler, metric)[código-fonte]¶
Base:
objectEvery trial of a tuning run, the best candidate and how it was searched.
- Parâmetros:
original (CandidateSpec)
best (CandidateSpec)
trials (DataFrame)
sampler (str)
metric (str)
- original: CandidateSpec¶
- best: CandidateSpec¶
Estratégias¶
Decomposition hybrid: one model for the smooth part, another for the volatile part.
y = s + v. The base forecasts s; a corrector forecasts v from windows of its
past values, recursively in variant A (only its own predictions enter the window). The
forecast is the sum of the two paths.
ma: causal moving average,s[t]usesyup totonly (the window expands at the start). A centred average would use future values and is not offered. The window comes from the training vector alone: the one whose volatile part has kurtosis closest to 3 (Babu and Reddy, 2014, as in the legacy project). Being causal, it is recomputed on any context, so new observations reach the frozen models (variant B).stl: robust STL fitted on the training vector only. It is not recomputed on later observations, so it serves variant A only (forecasting from the end of the training).
- class autohybts.strategies.decomposition.DecompositionForecaster(smooth, volatile, window_size=7, method='ma', ma_window=None, max_window=365, period=7, min_corrector_rows=10)[código-fonte]¶
Base:
ForecasterBase- Parâmetros:
- diagnostics()[código-fonte]¶
Numbers about the last fit that selection may use (empty by default).
- parts(history)[código-fonte]¶
Smooth and volatile parts of
historyas known at its last observation.- Parâmetros:
history (NDArray[float64])
- Tipo de retorno:
tuple[NDArray[float64], NDArray[float64]]
- predict_components(horizon, history)[código-fonte]¶
Paths of the smooth and the volatile part; the forecast is their sum.
- autohybts.strategies.decomposition.causal_moving_average(y, window)[código-fonte]¶
out[t] = mean(y[max(0, t - window + 1) : t + 1]): no value aftertis used.- Parâmetros:
y (NDArray[float64])
window (int)
- Tipo de retorno:
NDArray[float64]
- autohybts.strategies.decomposition.kurtosis_window(y, max_window)[código-fonte]¶
Window in
2..min(max_window, len(y) // 2)whosey - mahas kurtosis closest to 3.
- autohybts.strategies.decomposition.stl_smooth(y, period)[código-fonte]¶
Trend plus seasonal part of a robust STL fitted on
yonly.- Parâmetros:
y (NDArray[float64])
period (int)
- Tipo de retorno:
NDArray[float64]
Fixed combinations: of base forecasters, and of residual correctors.
ŷ = Σ w_i · b_i with weights fixed at fit time:
equal:w_i = 1 / k.inverse_mse:w_i ∝ 1 / MSE_i, whereMSE_iis the mean squared one-step out-of-fold error of memberion the tail of the training vector (a separate fit on the prefix, as inhistorical_oof_1step). Weights never see data after the origin.
Every member is then fitted on the whole training vector and forecasts from the same context, so a frozen combination takes new observations like any base (variant B).
- class autohybts.strategies.combination.CorrectorCombination(members, weights='equal', holdout=0.3)[código-fonte]¶
Base:
ParametrizedSeveral residual correctors averaged with fixed weights; itself a
ResidualCorrector.Used inside a residual hybrid,
ŷ = b + α · Σ w_j · r̂_j, so it inherits every causality rule of the residual pipeline.inverse_mseweights come from the lastholdoutshare of the corrector’s own training rows (in time order): each member is fitted on the rows before them and scored on them; then every member is refitted on all rows.- fit(windows, targets)[código-fonte]¶
- Parâmetros:
windows (ArrayLike)
targets (ArrayLike)
- Tipo de retorno:
- predict_next(window)[código-fonte]¶
- Parâmetros:
window (ArrayLike)
- Tipo de retorno:
- class autohybts.strategies.combination.FixedCombinationForecaster(members, weights='equal', settings=None)[código-fonte]¶
Base:
ForecasterBase- Parâmetros:
members (Sequence[BaseForecaster])
weights (str)
settings (ResidualSettings | None)
- diagnostics()[código-fonte]¶
Numbers about the last fit that selection may use (empty by default).
Ensembles of complete forecasters.
ŷ = agg(ŷ_1, ..., ŷ_K) over components that may themselves be hybrids or other
compositions:
equal: mean, weights1/K.median: per-step median of the component forecasts.trimmed_mean: per step, drop themax(1, round(trim · K))lowest and highest forecasts and average the rest.inverse_mse:w_k ∝ 1 / MSE_kof one-step out-of-fold errors.nnls: non-negative least squares of the target on the out-of-fold forecasts, normalized to sum 1 and shrunk towards equal weights,w = (1 − shrinkage) · w_nnls + shrinkage / K(few out-of-fold rows make free weights unstable: the forecast combination puzzle).
Out-of-fold forecasts come from historical_oof_1step inside the training vector: each
component is refitted on the prefix before the tail and forecasts the tail one step at a
time, so the weights never see data after the origin. Every component is then fitted on
the whole training vector; a frozen ensemble takes new observations like any base
(variant B).
- class autohybts.strategies.ensemble.EnsembleForecaster(components, method='equal', trim=0.2, shrinkage=0.5, settings=None)[código-fonte]¶
Base:
ForecasterBase- Parâmetros:
- diagnostics()[código-fonte]¶
Numbers about the last fit that selection may use (empty by default).
- class autohybts.registry.capabilities.Capabilities(multi_step=True, online_state_update=True, in_sample_fitted=False, deterministic=True, requires_extra=None, training_scope='local', output_type='point', horizon_strategy='recursive', max_horizon=None, target_mode='univariate', accepts_exog=False)[código-fonte]¶
Base:
objectDeclared capabilities of a registered model.
- Variáveis:
multi_step (bool) – forecasts several steps from one origin (needed by variant A).
online_state_update (bool) – forecasts from a later context with frozen parameters, i.e. new observations update its state without refitting (needed by variant B and by out-of-fold residuals).
in_sample_fitted (bool) – exposes
fitted_values()(allows thein_sampleresidual source).deterministic (bool) – same data and parameters give the same forecast whatever the seed;
Falsemeans the output depends onrandom_state.requires_extra (str | None) – optional dependency group needed to fit, e.g.
"stats".training_scope (str) –
"local"(one series),"global"(trained on a panel; not evaluated by the univariate search) or"pretrained"(a foundation model used as is on each series).output_type (str) –
"point";"quantile","samples"and"distribution"need a probabilistic contract and are skipped by the search.horizon_strategy (str) – how multi-step forecasts are produced:
"recursive","direct","mimo","dirrec"or"fixed"(a network trained for one horizon). It describes the model, not the A/B protocol.max_horizon (int | None) – longest horizon the model forecasts from one origin (
None: any); longer requests are skipped, not truncated.target_mode (str) –
"univariate"(one series from its own history),"multivariate"(several targets forecast jointly) or"exogenous"(needs covariates, past or known in advance). The search is univariate: the other two are skipped until they get their own contract.accepts_exog (bool) – takes exogenous features when the experiment has them (ADR-0011); it still forecasts without them.
- Parâmetros:
Count model fits per trial (cost accounting of the search).
A fit is the training of one leaf model: a base forecaster that is not a composition (naive, ARIMA, a lag regressor, a user model), a residual corrector or a fitted decomposition. Compositions (hybrids, combinations, ensembles) do not count themselves: their members do, so a residual hybrid at one origin counts the base, the extra fit of the base that produces its out-of-fold residuals and the corrector.
The counter lives in a context variable: each trial opens its own (count_fits), so
parallel trials in threads never mix their counts. Outside a counting context
record_fit does nothing. A user corrector that does not inherit from the library’s
classes can call record_fit() in its fit to be counted.
- class autohybts.domain.fit_count.FitCounter(total: 'int' = 0)[código-fonte]¶
Base:
object- Parâmetros:
total (int)
- autohybts.domain.fit_count.count_fits()[código-fonte]¶
Count the fits made inside the block (nested blocks count only their own).
- Tipo de retorno:
- autohybts.domain.fit_count.record_fit(n=1)[código-fonte]¶
Add
nfits to the current counter, if any.- Parâmetros:
n (int)
- Tipo de retorno:
None
Residual multistage: corrections of corrections, up to MAX_STAGES.
Formal targets. Stage 0 is the base b. For k >= 1 the stage-k model is
ŷ_k = ŷ_{k-1} + α · r̂_k and its corrector learns e_k(t) = y(t) - ŷ_{k-1}(t),
the error of the whole stage k - 1 model, produced inside the training vector by
the configured residual source (out-of-fold by default). Because a residual hybrid is
itself a base forecaster, stage k is a residual hybrid whose base is stage k - 1:
every stage inherits the provenance rules of the residual pipeline (available_at equal
to the target, windows ending at the origin, variant A recursion fed only with predicted
residuals), so no observation error acts as a feature before it exists.
- autohybts.strategies.multistage.stack_stages(base, correctors, *, window_size, alpha, residual_source, settings=None, stage_params=None)[código-fonte]¶
Nest one residual hybrid per corrector, the first corrector closest to the base.
stage_paramsoverrideswindow_size,alphaorresidual_sourceof the stages after the first (one mapping per extra stage); missing keys are shared.
How the strategies of building a forecaster compare: error against cost (Pareto).
Every candidate the search evaluated is a point: error on V_search against fit
time or structural complexity. A point is on the Pareto front when no other point is
at least as good on both axes and better on one. The front shows what each extra unit
of complexity bought; it is a report, never an input of the selection rule.
- autohybts.reporting.strategies.complexity(candidate)[código-fonte]¶
Number of fitted models in the structure (a base is 1, each corrector adds 1).
- Parâmetros:
candidate (CandidateSpec)
- Tipo de retorno:
- autohybts.reporting.strategies.pareto_front(x, y)[código-fonte]¶
Mask of points not dominated when both
xandyare minimized.- Parâmetros:
x (ArrayLike)
y (ArrayLike)
- Tipo de retorno:
NDArray[bool]
- autohybts.reporting.strategies.strategy_plot(kind, table, metric, x='cost', source='V_search')[código-fonte]¶
pareto(error vs cost or complexity, front highlighted) orstrategies.
- autohybts.reporting.strategies.strategy_table(results, metric)[código-fonte]¶
One row per evaluated candidate: score, coverage, cost, complexity, Pareto flags.
Modelos próprios¶
AutoHybridExperiment.register_model (acima) registra o modelo no experimento.
- autohybts.models.torch_model(module, kind='base', requires=None, **defaults)[código-fonte]¶
Registry factory: wrapper settings go to the wrapper, everything else to
module.exp.register_model("lstm", torch_model(LSTMNet, hidden=32, lags=28))makeshiddena module argument andlagsa wrapper argument; both can be changed per candidate (create_model("lstm", hidden=64)) and tuned.
- class autohybts.models.TorchForecaster(module, module_params=None, lags=14, differencing=0, scale=True, epochs=100, batch_size=32, learning_rate=0.001, validation_fraction=0.2, patience=10, random_state=0, device='cpu', requires=None, seasonal_differencing=0, season_length=1, differencing_test='kpss', transform=None, outliers=None)[código-fonte]¶
Base:
_TorchState,LaggedModelForecasterBase forecaster from a PyTorch module (see the module docstring for the contract).
- class autohybts.models.TorchCorrector(module, module_params=None, epochs=100, batch_size=32, learning_rate=0.001, validation_fraction=0.2, patience=10, random_state=0, device='cpu', requires=None)[código-fonte]¶
Base:
_TorchState,WindowCorrectorResidual corrector from a PyTorch module (input: residual window, oldest first).
- autohybts.models.keras_model(builder, kind='base', requires=None, **defaults)[código-fonte]¶
Registry factory: wrapper settings go to the wrapper, everything else to
builder.
- class autohybts.models.KerasForecaster(builder, builder_params=None, lags=14, differencing=0, scale=True, epochs=100, batch_size=32, learning_rate=0.001, validation_fraction=0.2, patience=10, random_state=0, requires=None, seasonal_differencing=0, season_length=1, differencing_test='kpss', transform=None, outliers=None)[código-fonte]¶
Base:
_KerasState,LaggedModelForecasterBase forecaster from a Keras model builder (see the module docstring).
- class autohybts.models.KerasCorrector(builder, builder_params=None, epochs=100, batch_size=32, learning_rate=0.001, validation_fraction=0.2, patience=10, random_state=0, requires=None)[código-fonte]¶
Base:
_KerasState,WindowCorrectorResidual corrector from a Keras model builder (input: residual window, oldest first).
- class autohybts.models.CustomForecaster(fit_fn, predict_fn, params=None, min_train_size=2, min_history=1, requires=None)[código-fonte]¶
Base:
ForecasterBase- Parâmetros:
- class autohybts.models.RegressorForecaster(estimator, lags=14, differencing=0, scale=True, requires=None, seasonal_differencing=0, season_length=1, differencing_test='kpss', transform=None, outliers=None)[código-fonte]¶
Base:
LaggedModelForecasterAny regressor with
fit(X, y)/predict(X)on lag windows (oldest lag first).
- autohybts.models.require(requirements)[código-fonte]¶
Raise
UnsupportedCapabilityErrorunless every requirement is installed.
- autohybts.models.check_specifier(version, specifier)[código-fonte]¶
Trueif the installedversionsatisfies a PEP 440 specifier like">=2.2,<3".An invalid specifier raises
ConfigurationError; a version that does not follow PEP 440 raisesUnsupportedCapabilityError(it cannot be checked, so the model is skipped with the reason).
- autohybts.models.validate_requirements(requirements)[código-fonte]¶
Refuse malformed requirements at registration (
ConfigurationError).Without
packaginginstalled the syntax cannot be checked here;requirewill then skip the model with the installation hint.
Ablação¶
Ablation of the selection procedure.
Four procedures, the same search budget and the same external origins (each series’ sealed test):
lowest_error: the finalist with the lowest mean error onV_select;incremental: the guarded incremental chain with the protocol thresholds, all families;incremental_simple: as above, only structures with at most two fitted models (standalone and additive residual hybrids);guarded_nested: asincremental, but if nested cross-validation on the development history says the procedure (all families, as inincremental) does not beat the procedure “best standalone model of the inner selection”, the best standalone model ofV_selectis kept. Both sides of that comparison are chosen inside each outer fold, without its block.
Each row (series x seed x procedure) records the external score of the chosen model,
those of the best standalone model of V_select and of the naive and
seasonal_naive references, and the full cost of the procedure: candidates and units
(origin x series) of every search, selection and nested inner search, the configured
budget, the stop reason, the proposals cut by each budget limit and the seconds of each
phase. lowest_error,
incremental and guarded_nested share one search (column search): their search
cost is the same work, not three measurements. Budgets limit by count only (no wall
clock), so a run is reproducible on another machine. Refitting the chosen model on the
pre-test history (seconds_refit) and reading the external test
(seconds_external) are reporting, not part of the procedure’s cost.
ablation_report gives, per procedure: median gain against the best standalone model
on the test, wins/ties/losses against it, share of hybrids and mean complexity,
validation–test gap, mean rank, spread of the median gain across seeds, coverage and
cost. The external test only reports: never pick the “winning” procedure on it.
From Python:
from autohybts.benchmarks import ablation_report, run_ablation, synthetic_cases
table = run_ablation(synthetic_cases(12), seeds=(0, 1, 2))
ablation_report(table)
From the command line (--out also writes the resolved protocol next to the CSV):
python -m autohybts.benchmarks.ablation --dataset synthetic --series 12 --seeds 0 1 2
python -m autohybts.benchmarks.ablation --dataset m4-daily --series 20 --out ablation.csv
- class autohybts.benchmarks.ablation.AblationCase(series_id, values, horizon, test_size, seasonal_period=None, stratum='', source=<factory>)[código-fonte]¶
Base:
objectOne series: development history with the external test at the end.
- Parâmetros:
- autohybts.benchmarks.ablation.ablation_protocol(cases, seeds, budget='smoke', space=None, outer_folds=2)[código-fonte]¶
Configured settings of a run, to save next to its table.
Metrics, initial selection policy and budget overrides follow the experiment’s configuration. Per-series resolved folds and family order remain in the comparison snapshots; this metadata does not perform a search or read the external test.
Local changes not committed cannot be detected without running
git; record them by hand when the working tree is not clean.
- autohybts.benchmarks.ablation.ablation_report(table, by=None)[código-fonte]¶
Per procedure: gain vs best base, wins/ties/losses, hybrids, gap, rank, seed spread, cost.
Gain statistics use finite paired gains only.
n_rowscounts supplied case/seed rows, not the study’s planned cases;n_pairedandpaired_coverageidentify the denominator of wins, ties and losses. Without valid gains their shares are NaN.by(e.g."stratum") adds an outer level: one block per group.
- autohybts.benchmarks.ablation.ablation_uncertainty(table, n_boot=2000, seed=0, level=0.95)[código-fonte]¶
Median gain vs the best base per procedure, with a series-level bootstrap interval.
Seeds of one series are not independent: each series’ gain is first summarized (median over its seeds), then series are resampled with replacement. Also reports the share of series where the procedure is better/worse than the base. Non-finite gains are excluded before aggregation; series without any finite gain remain in
n_seriesbut not inn_paired_seriesor the bootstrap. Their absence is reported explicitly.
- autohybts.benchmarks.ablation.benchmark_cases(name, subset, n_series, seed=0, *, series_ids=None, development_only=False, development_tail=None)[código-fonte]¶
A random sample of an official benchmark (downloads on first use).
The sample is reproducible:
seeddrawsn_seriesids without replacement from the benchmark’s id list; the official test of each series is its sealed test.
- autohybts.benchmarks.ablation.run_ablation(cases, seeds=(0,), budget='smoke', space=None, progress=None, outer_folds=2, *, checkpoint=None, resume=False, retry_failed=False, on_error='raise', configuration=None)[código-fonte]¶
Run a fixed case/seed plan, optionally checkpointing complete cases atomically.
resumerequires the same protocol, data hashes, environment and source code. Successful cases are never rerun. Interrupted cases resume automatically; failed or skipped cases requireretry_failed=True.on_error="record"continues after case failures, but configuration and temporal leakage errors always stop. The returned table’s attrs containprotocol,casesand studycoverage.
- autohybts.benchmarks.ablation.run_case(case, seed, budget='smoke', space=None, outer_folds=2, *, snapshot_callback=None)[código-fonte]¶
The four procedures on one series and seed; one row per procedure.
- autohybts.benchmarks.ablation.synthetic_cases(n_series, n=400, horizon=14)[código-fonte]¶
Daily series whose residual predictability cycles through AR(0), AR(0.5), AR(0.8).
- Parâmetros:
- Tipo de retorno:
Calibração da regra de aceite¶
Calibration of the acceptance rule on controls with a known answer.
Two controls, both daily, with the sealed test held out and never read:
white_noise(negative control): level plus white noise. Nothing beyond the mean is predictable, so a hybrid champion is a false acceptance of complexity.ar_residual(positive control): trend, weekly seasonality and AR(0.8) noise, with bases that cannot model the AR part (naive,seasonal_naive) and a linear corrector. The residuals are predictable at short horizons, so a standalone champion is a rejected useful gain.
For each series and each number of select origins (fold), one experiment runs the
search and the selection once; every policy is then applied to the same finalists with
the pure run_chain, so policies differ only in the decision rule. Rates are reported
per chain (the final champion: what a user gets) and per comparison (each hybrid
challenger), with percentile bootstrap intervals that resample series, the
independent units (origins of one series are not independent). Calibration and
confirmation sets use disjoint seeds: tune a policy on the first, check it once on the
second.
From Python:
from autohybts.benchmarks.calibration import (
calibration_report, control_cases, run_calibration,
)
table = run_calibration(control_cases(20), folds=(2, 3, 5))
calibration_report(table)
From the command line (--out also writes the resolved protocol):
python -m autohybts.benchmarks.calibration --series 20 --folds 2 3 5 --out cal.csv
- class autohybts.benchmarks.calibration.ControlCase(series_id: 'str', control: 'str', values: 'pd.Series')[código-fonte]¶
Base:
object
- autohybts.benchmarks.calibration.calibration_protocol(n_series, split, folds, policies={'rule': {}, 'rule+wilcoxon_0.05': {'significance_alpha': 0.05}}, fh=7, budget='smoke', seed=0, include=('standalone', 'residual'))[código-fonte]¶
Resolved settings of a calibration run, to save next to its table.
- autohybts.benchmarks.calibration.calibration_report(table, n_boot=2000, seed=0)[código-fonte]¶
Per control, number of select origins and policy: rates with 95 % intervals.
hybrid_champion_rateis the share of series whose final champion is a hybrid: on the negative control the false acceptance per chain, on the positive control one minus the rejected-gain rate (rejected_gain_rate).comparison_accept_rateis the share of hybrid challengers accepted. Intervals resample series.
- autohybts.benchmarks.calibration.control_cases(n_series, split='calibration', n=300)[código-fonte]¶
n_seriesseries of each control;splitpicks disjoint seeds.- Parâmetros:
- Tipo de retorno:
- autohybts.benchmarks.calibration.run_calibration(cases, folds=(2, 3, 5), policies={'rule': {}, 'rule+wilcoxon_0.05': {'significance_alpha': 0.05}}, fh=7, budget='smoke', seed=0, progress=None, include=('standalone', 'residual'))[código-fonte]¶
One row per series, number of select origins and policy (see the module docstring).
includeare the families of the search; with"ensemble"the rates measure the calibration gate of the composed families: any champion that is not a single model counts as a composed champion.
Exceções¶
Exception hierarchy.
Configuration errors stop a run. Errors raised while fitting or predicting a single
candidate are caught by the search and recorded as auditable FAILED trials.
- exception autohybts.exceptions.ArtifactCompatibilityError[código-fonte]¶
Base:
AutoHybTSErrorA persisted artifact is incompatible, corrupted or untrusted.
- exception autohybts.exceptions.AutoHybTSError[código-fonte]¶
Base:
ExceptionBase class for every error raised by autohybts.
- exception autohybts.exceptions.CandidateFitError[código-fonte]¶
Base:
AutoHybTSErrorA single candidate failed to fit or predict.
- exception autohybts.exceptions.ConfigurationError[código-fonte]¶
Base:
AutoHybTSError,ValueErrorInvalid or inconsistent configuration; stops the run.
- exception autohybts.exceptions.CoverageError[código-fonte]¶
Base:
AutoHybTSErrorA candidate lacks valid forecasts for some required evaluation unit.
- exception autohybts.exceptions.DataValidationError[código-fonte]¶
Base:
ConfigurationErrorInput series is invalid (unordered, duplicated, irregular, non-numeric or missing values).
Never fixed silently: the library does not reorder, resample, deduplicate or impute.
- exception autohybts.exceptions.DatasetIntegrityError[código-fonte]¶
Base:
AutoHybTSErrorA dataset failed a safety check: checksum, unapproved URL or unsafe archive.
Base:
AutoHybTSErrorA dataset is not in the local cache and cannot be downloaded (offline or network).
- exception autohybts.exceptions.InsufficientHistoryError[código-fonte]¶
Base:
AutoHybTSError,ValueErrorNot enough observations for the requested split, window or horizon.
- exception autohybts.exceptions.ProtocolConfigurationError[código-fonte]¶
Base:
ConfigurationErrorConfiguration cannot honour the declared scientific protocol.
Example: the
research_strictprofile without an explicitly defined variability criterion (open question A01).
- exception autohybts.exceptions.SealedTestAccessError[código-fonte]¶
Base:
TemporalLeakageErrorSearch, selection or tuning tried to read the sealed test segment.
- exception autohybts.exceptions.TemporalLeakageError[código-fonte]¶
Base:
AutoHybTSErrorInformation not available at the forecast origin would be used.
- exception autohybts.exceptions.UnsupportedCapabilityError[código-fonte]¶
Base:
AutoHybTSError,NotImplementedErrorModel, strategy or API path not supported by this adapter or version.