Skip to main content
In hierarchical forecasting, we aim to create forecasts for many time series concurrently, whilst adhering to pre-specified hierarchical relationships that exist between the time series. We can enforce this coherence by performing a post-processing reconciliation step on the forecasts. The HierarchicalForecast package provides the most comprehensive collection of Python implementations of hierarchical forecasting algorithms that follow classic hierarchical reconciliation. All the methods have a reconcile function capable of reconciling base forecasts using numpy arrays.

Cross-sectional hierarchies

Traditionally, hierarchical forecasting methods reconcile cross-sectional aggregations. For example, we may have forecasts for individual product demand, but also for the overall product group, department and store, and we are interested in making sure these forecasts are coherent with each other. This can be formalized as: Y~=SPY^  ,\tilde{\textbf{Y}} = SP\hat{\textbf{Y}} \;, where Y^Rm×p\hat{\textbf{Y}} \in \mathbb{R}^{m \times p} denotes the matrix of forecasts for all mm time series for all pp time steps in the hierarchy, S{0,1}m×nS \in \lbrace 0, 1 \rbrace^{m \times n} is a matrix that defines the hierarchical relationship between the nn bottom-level time series and the m=mnm^* = m - n aggregations, PRn×mP \in \mathbb{R}^{n \times m} is a matrix that encapsulates the contribution of each forecast to the final estimate, and Y~Rm×p\tilde{\textbf{Y}} \in \mathbb{R}^{m \times p} is the matrix of reconciled forecasts. We can use the matrix PP to define various forecast contribution scenarios. Cross-sectional reconciliation methods aim to find the optimal PP matrix.

Temporal hierarchies

We can also perform temporal reconciliation. For example, we may have forecasts for daily demand, weekly, and monthly, and we are interested in making sure these forecasts are coherent with each other. We formalize the temporal hierarchical forecasting problem as: Y~=(StePteY^)  ,\tilde{\textbf{Y}} = \left( S_{te} P_{te} \hat{\textbf{Y}}^{\intercal} \right)^{\intercal} \;, where Ste{0,1}p×kS_{te} \in \lbrace 0, 1 \rbrace^{p \times k} is a matrix that defines the hierarchical relationship between the kk bottom-level time steps and the p=pkp^* = p - k aggregations and PteRk×pP_{te} \in \mathbb{R}^{k \times p} is a matrix that encapsulates the contribution of each forecast to the final estimate. We can use the matrix PteP_{te} to define various forecast contribution scenarios. Temporal reconciliation methods aim to find the optimal PteP_{te} matrix.

Cross-temporal reconciliation

We can combine cross-sectional and temporal hierarchical forecasting by performing cross-sectional reconciliation and temporal reconciliation in a two-step procedure.

References

-Hyndman, Rob. Notation for forecast reconciliation.

1. Bottom-Up


BottomUp

Bases: HReconciler Bottom Up Reconciliation Class. The most basic hierarchical reconciliation is performed using an Bottom-Up strategy. It was proposed for the first time by Orcutt in 1968. The corresponding hierarchical “projection” matrix is defined as: PtextBU=[0[b],[a]    I[b][b]]\mathbf{P}_{\\text{BU}} = [\mathbf{0}_{\mathrm{[b],[a]}}\;|\;\mathbf{I}_{\mathrm{[b][b]}}] References:

BottomUp.fit

fit(
    S,
    y_hat,
    idx_bottom,
    y_insample=None,
    y_hat_insample=None,
    sigmah=None,
    intervals_method=None,
    num_samples=None,
    seed=None,
    tags=None,
)
Bottom Up Fit Method. Parameters:
NameTypeDescriptionDefault
SndarraySumming matrix of size (base, bottom).required
y_hatndarrayForecast values of size (base, horizon).required
idx_bottomndarrayIndices corresponding to the bottom level of S, size (bottom).required
y_insampleOptional[ndarray]In-sample values of size (base, horizon). Default is None.None
y_hat_insampleOptional[ndarray]In-sample forecast values of size (base, horizon). Default is None.None
sigmahOptional[ndarray]Estimated standard deviation of the conditional marginal distribution. Default is None.None
intervals_methodOptional[str]Sampler for prediction intervals, one of normality, bootstrap, permbu. Default is None.None
num_samplesOptional[int]Number of samples for probabilistic coherent distribution. Default is None.None
seedOptional[int]Seed for reproducibility. Default is None.None
tagsOptional[dict[str, ndarray]]Tags for hierarchical structure. Default is None.None
Returns:
NameTypeDescription
BottomUpobjectfitted reconciler.

BottomUp.predict

predict(S, y_hat, level=None)
Predict using reconciler. Predict using fitted mean and probabilistic reconcilers. Parameters:
NameTypeDescriptionDefault
SndarraySumming matrix of size (base, bottom).required
y_hatndarrayForecast values of size (base, horizon).required
levelOptional[list[int]]float list 0-100, confidence levels for prediction intervals. Default is None.None
Returns:
NameTypeDescription
y_tildedictReconciliated predictions.

BottomUp.fit_predict

fit_predict(
    S,
    y_hat,
    idx_bottom,
    y_insample=None,
    y_hat_insample=None,
    sigmah=None,
    level=None,
    intervals_method=None,
    num_samples=None,
    seed=None,
    tags=None,
)
BottomUp Reconciliation Method. Parameters:
NameTypeDescriptionDefault
SndarraySumming matrix of size (base, bottom).required
y_hatndarrayForecast values of size (base, horizon).required
idx_bottomndarrayIndices corresponding to the bottom level of S, size (bottom).required
y_insampleOptional[ndarray]In-sample values of size (base, insample_size). Default is None.None
y_hat_insampleOptional[ndarray]In-sample forecast values of size (base, insample_size). Default is None.None
sigmahOptional[ndarray]Estimated standard deviation of the conditional marginal distribution. Default is None.None
levelOptional[list[int]]float list 0-100, confidence levels for prediction intervals. Default is None.None
intervals_methodOptional[str]Sampler for prediction intervals, one of normality, bootstrap, permbu. Default is None.None
num_samplesOptional[int]Number of samples for probabilistic coherent distribution. Default is None.None
seedOptional[int]Seed for reproducibility. Default is None.None
tagsOptional[dict[str, ndarray]]Tags for hierarchical structure. Default is None.None
Returns:
NameTypeDescription
y_tildedictReconciliated y_hat using the Bottom Up approach.

BottomUp.sample

sample(num_samples)
Sample probabilistic coherent distribution. Generates n samples from a probabilistic coherent distribution. The method uses fitted mean and probabilistic reconcilers, defined by the intervals_method selected during the reconciler’s instantiation. Currently available: normality, bootstrap, permbu. Parameters:
NameTypeDescriptionDefault
num_samplesintnumber of samples generated from coherent distribution.required
Returns:
NameTypeDescription
samplesndarrayCoherent samples of size (num_series, horizon, num_samples).

BottomUpSparse

Bases: BottomUp BottomUpSparse Reconciliation Class. This is the implementation of a Bottom Up reconciliation using the sparse matrix approach. It works much more efficient on datasets with many time series. [makoren: At least I hope so, I only checked up until ~20k time series, and there’s no real improvement, it would be great to check for smth like 1M time series, where the dense S matrix really stops fitting in memory] See the parent class for more details.

BottomUpSparse.fit

fit(
    S,
    y_hat,
    idx_bottom,
    y_insample=None,
    y_hat_insample=None,
    sigmah=None,
    intervals_method=None,
    num_samples=None,
    seed=None,
    tags=None,
)
Bottom Up Fit Method. Parameters:
NameTypeDescriptionDefault
SndarraySumming matrix of size (base, bottom).required
y_hatndarrayForecast values of size (base, horizon).required
idx_bottomndarrayIndices corresponding to the bottom level of S, size (bottom).required
y_insampleOptional[ndarray]In-sample values of size (base, horizon). Default is None.None
y_hat_insampleOptional[ndarray]In-sample forecast values of size (base, horizon). Default is None.None
sigmahOptional[ndarray]Estimated standard deviation of the conditional marginal distribution. Default is None.None
intervals_methodOptional[str]Sampler for prediction intervals, one of normality, bootstrap, permbu. Default is None.None
num_samplesOptional[int]Number of samples for probabilistic coherent distribution. Default is None.None
seedOptional[int]Seed for reproducibility. Default is None.None
tagsOptional[dict[str, ndarray]]Tags for hierarchical structure. Default is None.None
Returns:
NameTypeDescription
BottomUpobjectfitted reconciler.

BottomUpSparse.predict

predict(S, y_hat, level=None)
Predict using reconciler. Predict using fitted mean and probabilistic reconcilers. Parameters:
NameTypeDescriptionDefault
SndarraySumming matrix of size (base, bottom).required
y_hatndarrayForecast values of size (base, horizon).required
levelOptional[list[int]]float list 0-100, confidence levels for prediction intervals. Default is None.None
Returns:
NameTypeDescription
y_tildedictReconciliated predictions.

BottomUpSparse.fit_predict

fit_predict(
    S,
    y_hat,
    idx_bottom,
    y_insample=None,
    y_hat_insample=None,
    sigmah=None,
    level=None,
    intervals_method=None,
    num_samples=None,
    seed=None,
    tags=None,
)
BottomUp Reconciliation Method. Parameters:
NameTypeDescriptionDefault
SndarraySumming matrix of size (base, bottom).required
y_hatndarrayForecast values of size (base, horizon).required
idx_bottomndarrayIndices corresponding to the bottom level of S, size (bottom).required
y_insampleOptional[ndarray]In-sample values of size (base, insample_size). Default is None.None
y_hat_insampleOptional[ndarray]In-sample forecast values of size (base, insample_size). Default is None.None
sigmahOptional[ndarray]Estimated standard deviation of the conditional marginal distribution. Default is None.None
levelOptional[list[int]]float list 0-100, confidence levels for prediction intervals. Default is None.None
intervals_methodOptional[str]Sampler for prediction intervals, one of normality, bootstrap, permbu. Default is None.None
num_samplesOptional[int]Number of samples for probabilistic coherent distribution. Default is None.None
seedOptional[int]Seed for reproducibility. Default is None.None
tagsOptional[dict[str, ndarray]]Tags for hierarchical structure. Default is None.None
Returns:
NameTypeDescription
y_tildedictReconciliated y_hat using the Bottom Up approach.

BottomUpSparse.sample

sample(num_samples)
Sample probabilistic coherent distribution. Generates n samples from a probabilistic coherent distribution. The method uses fitted mean and probabilistic reconcilers, defined by the intervals_method selected during the reconciler’s instantiation. Currently available: normality, bootstrap, permbu. Parameters:
NameTypeDescriptionDefault
num_samplesintnumber of samples generated from coherent distribution.required
Returns:
NameTypeDescription
samplesndarrayCoherent samples of size (num_series, horizon, num_samples).

2. Top-Down

TopDown

TopDown(method)
Bases: HReconciler Top Down Reconciliation Class. The Top Down hierarchical reconciliation method, distributes the total aggregate predictions and decomposes it down the hierarchy using proportions mathbfp_mathrm[b]\\mathbf{p}\_{\\mathrm{[b]}} that can be actual historical values or estimated. P=[p[b]    0[b][a,b  1]]\mathbf{P}=[\mathbf{p}_{\mathrm{[b]}}\;|\;\mathbf{0}_{\mathrm{[b][a,b\;-1]}}] Parameters:
NameTypeDescriptionDefault
methodstrOne of forecast_proportions, average_proportions and proportion_averages.required
References:

TopDown.fit

fit(
    S,
    y_hat,
    y_insample,
    y_hat_insample=None,
    sigmah=None,
    intervals_method=None,
    num_samples=None,
    seed=None,
    tags=None,
    idx_bottom=None,
)
TopDown Fit Method. Parameters:
NameTypeDescriptionDefault
SndarraySumming matrix of size (base, bottom).required
y_hatndarrayForecast values of size (base, horizon).required
y_insamplendarrayInsample values of size (base, insample_size). Optional for forecast_proportions method.required
y_hat_insamplendarrayInsample forecast values of size (base, insample_size). Optional for forecast_proportions method.None
sigmahndarrayEstimated standard deviation of the conditional marginal distribution.None
interval_methodstrSampler for prediction intervals, one of normality, bootstrap, permbu.required
num_samplesintNumber of samples for probabilistic coherent distribution.None
seedintSeed for reproducibility.None
tagsdict[str, ndarray]Each key is a level and each value its S indices.None
idx_bottomndarrayIndices corresponding to the bottom level of S, size (bottom).None
Returns:
NameTypeDescription
TopDownobjectfitted reconciler.

TopDown.predict

predict(S, y_hat, level=None)
Predict using reconciler. Predict using fitted mean and probabilistic reconcilers. Parameters:
NameTypeDescriptionDefault
SndarraySumming matrix of size (base, bottom).required
y_hatndarrayForecast values of size (base, horizon).required
levelOptional[list[int]]float list 0-100, confidence levels for prediction intervals. Default is None.None
Returns:
NameTypeDescription
y_tildedictReconciliated predictions.

TopDown.fit_predict

fit_predict(
    S,
    y_hat,
    tags,
    idx_bottom=None,
    y_insample=None,
    y_hat_insample=None,
    sigmah=None,
    level=None,
    intervals_method=None,
    num_samples=None,
    seed=None,
)
Top Down Reconciliation Method. Parameters:
NameTypeDescriptionDefault
SndarraySumming matrix of size (base, bottom).required
y_hatndarrayForecast values of size (base, horizon).required
tagsdict[str, ndarray]Each key is a level and each value its S indices.required
idx_bottomndarrayIndices corresponding to the bottom level of S, size (bottom). Default is None.None
y_insamplendarrayInsample values of size (base, insample_size). Optional for forecast_proportions method. Default is None.None
y_hat_insamplendarrayInsample forecast values of size (base, insample_size). Optional for forecast_proportions method. Default is None.None
sigmahndarrayEstimated standard deviation of the conditional marginal distribution. Default is None.None
levellist[int]float list 0-100, confidence levels for prediction intervals. Default is None.None
intervals_methodstrSampler for prediction intervals, one of normality, bootstrap, permbu. Default is None.None
num_samplesintNumber of samples for probabilistic coherent distribution. Default is None.None
seedintSeed for reproducibility.None
Returns:
NameTypeDescription
y_tildendarrayReconciliated y_hat using the Top Down approach.

TopDown.sample

sample(num_samples)
Sample probabilistic coherent distribution. Generates n samples from a probabilistic coherent distribution. The method uses fitted mean and probabilistic reconcilers, defined by the intervals_method selected during the reconciler’s instantiation. Currently available: normality, bootstrap, permbu. Parameters:
NameTypeDescriptionDefault
num_samplesintnumber of samples generated from coherent distribution.required
Returns:
NameTypeDescription
samplesndarrayCoherent samples of size (num_series, horizon, num_samples).

TopDownSparse

Bases: TopDown TopDownSparse Reconciliation Class. This is an implementation of top-down reconciliation using the sparse matrix approach. It works much more efficiently on data sets with many time series. See the parent class for more details.

TopDownSparse.fit

fit(
    S,
    y_hat,
    y_insample,
    y_hat_insample=None,
    sigmah=None,
    intervals_method=None,
    num_samples=None,
    seed=None,
    tags=None,
    idx_bottom=None,
)
TopDown Fit Method. Parameters:
NameTypeDescriptionDefault
SndarraySumming matrix of size (base, bottom).required
y_hatndarrayForecast values of size (base, horizon).required
y_insamplendarrayInsample values of size (base, insample_size). Optional for forecast_proportions method.required
y_hat_insamplendarrayInsample forecast values of size (base, insample_size). Optional for forecast_proportions method.None
sigmahndarrayEstimated standard deviation of the conditional marginal distribution.None
interval_methodstrSampler for prediction intervals, one of normality, bootstrap, permbu.required
num_samplesintNumber of samples for probabilistic coherent distribution.None
seedintSeed for reproducibility.None
tagsdict[str, ndarray]Each key is a level and each value its S indices.None
idx_bottomndarrayIndices corresponding to the bottom level of S, size (bottom).None
Returns:
NameTypeDescription
TopDownobjectfitted reconciler.

TopDownSparse.predict

predict(S, y_hat, level=None)
Predict using reconciler. Predict using fitted mean and probabilistic reconcilers. Parameters:
NameTypeDescriptionDefault
SndarraySumming matrix of size (base, bottom).required
y_hatndarrayForecast values of size (base, horizon).required
levelOptional[list[int]]float list 0-100, confidence levels for prediction intervals. Default is None.None
Returns:
NameTypeDescription
y_tildedictReconciliated predictions.

TopDownSparse.fit_predict

fit_predict(
    S,
    y_hat,
    tags,
    idx_bottom=None,
    y_insample=None,
    y_hat_insample=None,
    sigmah=None,
    level=None,
    intervals_method=None,
    num_samples=None,
    seed=None,
)

TopDownSparse.sample

sample(num_samples)
Sample probabilistic coherent distribution. Generates n samples from a probabilistic coherent distribution. The method uses fitted mean and probabilistic reconcilers, defined by the intervals_method selected during the reconciler’s instantiation. Currently available: normality, bootstrap, permbu. Parameters:
NameTypeDescriptionDefault
num_samplesintnumber of samples generated from coherent distribution.required
Returns:
NameTypeDescription
samplesndarrayCoherent samples of size (num_series, horizon, num_samples).
cls_top_down(
                S=S, y_hat=S @ y_hat_bottom, y_insample=S @ y_bottom, tags=tags
            )["mean"]
cls_top_down = TopDownSparse(method="average_proportions")
test_fail(
    cls_top_down,
    contains="Top-down reconciliation requires strictly hierarchical structures.",
    args=(sparse.csr_matrix(S_non_hier), None, tags_non_hier),
)

3. Middle-Out

MiddleOut

MiddleOut(middle_level, top_down_method)
Bases: HReconciler Middle Out Reconciliation Class. This method is only available for strictly hierarchical structures. It anchors the base predictions in a middle level. The levels above the base predictions use the Bottom-Up approach, while the levels below use a Top-Down. Parameters:
NameTypeDescriptionDefault
middle_levelstrMiddle level.required
top_down_methodstrOne of forecast_proportions, average_proportions and proportion_averages.required
References:

MiddleOut.fit

fit(**kwargs)

MiddleOut.predict

predict(**kwargs)

MiddleOut.fit_predict

fit_predict(
    S,
    y_hat,
    tags,
    y_insample=None,
    y_hat_insample=None,
    sigmah=None,
    level=None,
    intervals_method=None,
    num_samples=None,
    seed=None,
)
Middle Out Reconciliation Method. Parameters:
NameTypeDescriptionDefault
SndarraySumming matrix of size (base, bottom).required
y_hatndarrayForecast values of size (base, horizon).required
tagsdict[str, ndarray]Each key is a level and each value its S indices.required
y_insamplendarrayInsample values of size (base, insample_size). Only used for forecast_proportions. Default is None.None
y_hat_insamplendarrayIn-sample forecast values of size (base, insample_size). Only used for forecast_proportions. Default is None.None
sigmahndarrayEstimated standard deviation of the conditional marginal distribution. Default is None.None
levellist[int]Confidence levels for prediction intervals. Default is None.None
intervals_methodstrSampler for prediction intervals, one of normality, bootstrap, permbu. Default is None.None
num_samplesintNumber of samples for probabilistic coherent distribution. Default is None.None
seedintSeed for reproducibility. Default is None.None
Returns:
NameTypeDescription
y_tildeReconciliated y_hat using the Middle Out approach.

MiddleOut.sample

sample(num_samples)
Sample probabilistic coherent distribution. Generates n samples from a probabilistic coherent distribution. The method uses fitted mean and probabilistic reconcilers, defined by the intervals_method selected during the reconciler’s instantiation. Currently available: normality, bootstrap, permbu. Parameters:
NameTypeDescriptionDefault
num_samplesintnumber of samples generated from coherent distribution.required
Returns:
NameTypeDescription
samplesndarrayCoherent samples of size (num_series, horizon, num_samples).

MiddleOutSparse

Bases: MiddleOut MiddleOutSparse Reconciliation Class. This is an implementation of middle-out reconciliation using the sparse matrix approach. It works much more efficiently on data sets with many time series. See the parent class for more details.

MiddleOutSparse.fit

fit(**kwargs)

MiddleOutSparse.predict

predict(**kwargs)

MiddleOutSparse.fit_predict

fit_predict(
    S,
    y_hat,
    tags,
    y_insample=None,
    y_hat_insample=None,
    sigmah=None,
    level=None,
    intervals_method=None,
    num_samples=None,
    seed=None,
)

MiddleOutSparse.sample

sample(num_samples)
Sample probabilistic coherent distribution. Generates n samples from a probabilistic coherent distribution. The method uses fitted mean and probabilistic reconcilers, defined by the intervals_method selected during the reconciler’s instantiation. Currently available: normality, bootstrap, permbu. Parameters:
NameTypeDescriptionDefault
num_samplesintnumber of samples generated from coherent distribution.required
Returns:
NameTypeDescription
samplesndarrayCoherent samples of size (num_series, horizon, num_samples).

4. Min-Trace

MinTrace

MinTrace(method, nonnegative=False, mint_shr_ridge=2e-08, num_threads=1)
Bases: HReconciler MinTrace Reconciliation Class. This reconciliation algorithm proposed by Wickramasuriya et al. depends on a generalized least squares estimator and an estimator of the covariance matrix of the coherency errors mathbfW_h\\mathbf{W}\_{h}. The Min Trace algorithm minimizes the squared errors for the coherent forecasts under an unbiasedness assumption; the solution has a closed form. PMinT=(SWhS)1SWh1\mathbf{P}_{\text{MinT}}=\left(\mathbf{S}^{\intercal}\mathbf{W}_{h}\mathbf{S}\right)^{-1}\mathbf{S}^{\intercal}\mathbf{W}^{-1}_{h} Parameters:
NameTypeDescriptionDefault
methodstrOne of ols, wls_struct, wls_var, mint_shrink, mint_cov.required
nonnegativeboolReconciled forecasts should be nonnegative?False
mint_shr_ridgefloatRidge numeric protection to MinTrace-shr covariance estimator.2e-08
num_threadsintNumber of threads to use for solving the optimization problems (when nonnegative=True).1
References:

MinTrace.fit

fit(
    S,
    y_hat,
    y_insample=None,
    y_hat_insample=None,
    sigmah=None,
    intervals_method=None,
    num_samples=None,
    seed=None,
    tags=None,
    idx_bottom=None,
)
MinTrace Fit Method. Parameters:
NameTypeDescriptionDefault
SSumming matrix of size (base, bottom).required
y_hatForecast values of size (base, horizon).required
y_insampleOptional[ndarray]Insample values of size (base, insample_size). Only used with “wls_var”, “mint_cov”, “mint_shrink”.None
y_hat_insampleOptional[ndarray]Insample forecast values of size (base, insample_size). Only used with “wls_var”, “mint_cov”, “mint_shrink”None
sigmahOptional[ndarray]Estimated standard deviation of the conditional marginal distribution.None
intervals_methodOptional[str]Sampler for prediction intervals, one of normality, bootstrap, permbu.None
num_samplesOptional[int]Number of samples for probabilistic coherent distribution.None
seedOptional[int]Seed for reproducibility.None
tagsOptional[dict[str, ndarray]]Each key is a level and each value its S indices.None
idx_bottomOptional[ndarray]Indices corresponding to the bottom level of S, size (bottom).None
Returns:
NameTypeDescription
selfobject, fitted reconciler.

MinTrace.predict

predict(S, y_hat, level=None)
Predict using reconciler. Predict using fitted mean and probabilistic reconcilers. Parameters:
NameTypeDescriptionDefault
SndarraySumming matrix of size (base, bottom).required
y_hatndarrayForecast values of size (base, horizon).required
levelOptional[list[int]]float list 0-100, confidence levels for prediction intervals. Default is None.None
Returns:
NameTypeDescription
y_tildedictReconciliated predictions.

MinTrace.fit_predict

fit_predict(
    S,
    y_hat,
    idx_bottom=None,
    y_insample=None,
    y_hat_insample=None,
    sigmah=None,
    level=None,
    intervals_method=None,
    num_samples=None,
    seed=None,
    tags=None,
)
MinTrace Reconciliation Method. Parameters:
NameTypeDescriptionDefault
SndarraySumming matrix of size (base, bottom).required
y_hatndarrayForecast values of size (base, horizon).required
idx_bottomndarrayIndices corresponding to the bottom level of S, size (bottom).None
y_insampleOptional[ndarray]Insample values of size (base, insample_size). Only used by wls_var, mint_cov, mint_shrinkNone
y_hat_insampleOptional[ndarray]Insample fitted values of size (base, insample_size). Only used by wls_var, mint_cov, mint_shrinkNone
sigmahOptional[ndarray]Estimated standard deviation of the conditional marginal distribution.None
levelOptional[list[int]]float list 0-100, confidence levels for prediction intervals.None
intervals_methodOptional[str]Sampler for prediction intervals, one of normality, bootstrap, permbu.None
num_samplesOptional[int]Number of samples for probabilistic coherent distribution.None
seedOptional[int]Seed for reproducibility.None
tagsOptional[dict[str, ndarray]]Each key is a level and each value its S indices.None
Returns:
NameTypeDescription
y_tildeReconciliated y_hat using the MinTrace approach.

MinTrace.sample

sample(num_samples)
Sample probabilistic coherent distribution. Generates n samples from a probabilistic coherent distribution. The method uses fitted mean and probabilistic reconcilers, defined by the intervals_method selected during the reconciler’s instantiation. Currently available: normality, bootstrap, permbu. Parameters:
NameTypeDescriptionDefault
num_samplesintnumber of samples generated from coherent distribution.required
Returns:
NameTypeDescription
samplesndarrayCoherent samples of size (num_series, horizon, num_samples).

MinTraceSparse

MinTraceSparse(method, nonnegative=False, num_threads=1, qp=True)
Bases: MinTrace MinTraceSparse Reconciliation Class. This is the implementation of OLS and WLS estimators using sparse matrices. It is not guaranteed to give identical results to the non-sparse version, but works much more efficiently on data sets with many time series. See the parent class for more details. Parameters:
NameTypeDescriptionDefault
methodstrOne of ols, wls_struct, or wls_var.required
nonnegativeboolReturn non-negative reconciled forecasts.False
num_threadsintNumber of threads to execute non-negative quadratic programming calls.1
qpboolImplement non-negativity constraint with a quadratic programming approach. SettingTrue

MinTraceSparse.fit

fit(
    S,
    y_hat,
    y_insample=None,
    y_hat_insample=None,
    sigmah=None,
    intervals_method=None,
    num_samples=None,
    seed=None,
    tags=None,
    idx_bottom=None,
)
MinTraceSparse Fit Method. Parameters:
NameTypeDescriptionDefault
Scsr_matrixSumming matrix of size (base, bottom).required
y_hatndarrayForecast values of size (base, horizon).required
y_insampleOptional[ndarray]Insample values of size (base, insample_size). Only used with “wls_var”.None
y_hat_insampleOptional[ndarray]Insample forecast values of size (base, insample_size). Only used with “wls_var”None
sigmahOptional[ndarray]Estimated standard deviation of the conditional marginal distribution.None
intervals_methodOptional[str]Sampler for prediction intervals, one of normality, bootstrap, permbu.None
num_samplesOptional[int]Number of samples for probabilistic coherent distribution.None
seedOptional[int]Seed for reproducibility.None
tagsOptional[dict[str, ndarray]]Each key is a level and each value its S indices.None
idx_bottomOptional[ndarray]Indices corresponding to the bottom level of S, size (bottom).None
Returns:
NameTypeDescription
selfMinTraceSparseobject, fitted reconciler.

MinTraceSparse.predict

predict(S, y_hat, level=None)
Predict using reconciler. Predict using fitted mean and probabilistic reconcilers. Parameters:
NameTypeDescriptionDefault
SndarraySumming matrix of size (base, bottom).required
y_hatndarrayForecast values of size (base, horizon).required
levelOptional[list[int]]float list 0-100, confidence levels for prediction intervals. Default is None.None
Returns:
NameTypeDescription
y_tildedictReconciliated predictions.

MinTraceSparse.fit_predict

fit_predict(
    S,
    y_hat,
    idx_bottom=None,
    y_insample=None,
    y_hat_insample=None,
    sigmah=None,
    level=None,
    intervals_method=None,
    num_samples=None,
    seed=None,
    tags=None,
)
MinTrace Reconciliation Method. Parameters:
NameTypeDescriptionDefault
SndarraySumming matrix of size (base, bottom).required
y_hatndarrayForecast values of size (base, horizon).required
idx_bottomndarrayIndices corresponding to the bottom level of S, size (bottom).None
y_insampleOptional[ndarray]Insample values of size (base, insample_size). Only used by wls_var, mint_cov, mint_shrinkNone
y_hat_insampleOptional[ndarray]Insample fitted values of size (base, insample_size). Only used by wls_var, mint_cov, mint_shrinkNone
sigmahOptional[ndarray]Estimated standard deviation of the conditional marginal distribution.None
levelOptional[list[int]]float list 0-100, confidence levels for prediction intervals.None
intervals_methodOptional[str]Sampler for prediction intervals, one of normality, bootstrap, permbu.None
num_samplesOptional[int]Number of samples for probabilistic coherent distribution.None
seedOptional[int]Seed for reproducibility.None
tagsOptional[dict[str, ndarray]]Each key is a level and each value its S indices.None
Returns:
NameTypeDescription
y_tildeReconciliated y_hat using the MinTrace approach.

MinTraceSparse.sample

sample(num_samples)
Sample probabilistic coherent distribution. Generates n samples from a probabilistic coherent distribution. The method uses fitted mean and probabilistic reconcilers, defined by the intervals_method selected during the reconciler’s instantiation. Currently available: normality, bootstrap, permbu. Parameters:
NameTypeDescriptionDefault
num_samplesintnumber of samples generated from coherent distribution.required
Returns:
NameTypeDescription
samplesndarrayCoherent samples of size (num_series, horizon, num_samples).

5. Optimal Combination

OptimalCombination

OptimalCombination(method, nonnegative=False, num_threads=1)
Bases: MinTrace Optimal Combination Reconciliation Class. This reconciliation algorithm was proposed by Hyndman et al. 2011, the method uses generalized least squares estimator using the coherency errors covariance matrix. Consider the covariance of the base forecast textrmVar(epsilon_h)=Sigma_h\\textrm{Var}(\\epsilon\_{h}) = \\Sigma\_{h}, the mathbfP\\mathbf{P} matrix of this method is defined by: mathbfP=left(mathbfSintercalSigma_hdaggermathbfSright)1mathbfSintercalSigmahdagger \\mathbf{P} = \\left(\\mathbf{S}^{\\intercal}\\Sigma\_{h}^{\\dagger}\\mathbf{S}\\right)^{-1}\\mathbf{S}^{\\intercal}\\Sigma^{\\dagger}_{h} where Sigmahdagger\\Sigma_{h}^{\\dagger} denotes the variance pseudo-inverse. The method was later proven equivalent to MinTrace variants. Parameters:
NameTypeDescriptionDefault
methodstrstr, allowed optimal combination methods: ‘ols’, ‘wls_struct’.required
nonnegativeboolbool, reconciled forecasts should be nonnegative?False

OptimalCombination.fit

fit(
    S,
    y_hat,
    y_insample=None,
    y_hat_insample=None,
    sigmah=None,
    intervals_method=None,
    num_samples=None,
    seed=None,
    tags=None,
    idx_bottom=None,
)
MinTrace Fit Method. Parameters:
NameTypeDescriptionDefault
SSumming matrix of size (base, bottom).required
y_hatForecast values of size (base, horizon).required
y_insampleOptional[ndarray]Insample values of size (base, insample_size). Only used with “wls_var”, “mint_cov”, “mint_shrink”.None
y_hat_insampleOptional[ndarray]Insample forecast values of size (base, insample_size). Only used with “wls_var”, “mint_cov”, “mint_shrink”None
sigmahOptional[ndarray]Estimated standard deviation of the conditional marginal distribution.None
intervals_methodOptional[str]Sampler for prediction intervals, one of normality, bootstrap, permbu.None
num_samplesOptional[int]Number of samples for probabilistic coherent distribution.None
seedOptional[int]Seed for reproducibility.None
tagsOptional[dict[str, ndarray]]Each key is a level and each value its S indices.None
idx_bottomOptional[ndarray]Indices corresponding to the bottom level of S, size (bottom).None
Returns:
NameTypeDescription
selfobject, fitted reconciler.

OptimalCombination.predict

predict(S, y_hat, level=None)
Predict using reconciler. Predict using fitted mean and probabilistic reconcilers. Parameters:
NameTypeDescriptionDefault
SndarraySumming matrix of size (base, bottom).required
y_hatndarrayForecast values of size (base, horizon).required
levelOptional[list[int]]float list 0-100, confidence levels for prediction intervals. Default is None.None
Returns:
NameTypeDescription
y_tildedictReconciliated predictions.

OptimalCombination.fit_predict

fit_predict(
    S,
    y_hat,
    idx_bottom=None,
    y_insample=None,
    y_hat_insample=None,
    sigmah=None,
    level=None,
    intervals_method=None,
    num_samples=None,
    seed=None,
    tags=None,
)
MinTrace Reconciliation Method. Parameters:
NameTypeDescriptionDefault
SndarraySumming matrix of size (base, bottom).required
y_hatndarrayForecast values of size (base, horizon).required
idx_bottomndarrayIndices corresponding to the bottom level of S, size (bottom).None
y_insampleOptional[ndarray]Insample values of size (base, insample_size). Only used by wls_var, mint_cov, mint_shrinkNone
y_hat_insampleOptional[ndarray]Insample fitted values of size (base, insample_size). Only used by wls_var, mint_cov, mint_shrinkNone
sigmahOptional[ndarray]Estimated standard deviation of the conditional marginal distribution.None
levelOptional[list[int]]float list 0-100, confidence levels for prediction intervals.None
intervals_methodOptional[str]Sampler for prediction intervals, one of normality, bootstrap, permbu.None
num_samplesOptional[int]Number of samples for probabilistic coherent distribution.None
seedOptional[int]Seed for reproducibility.None
tagsOptional[dict[str, ndarray]]Each key is a level and each value its S indices.None
Returns:
NameTypeDescription
y_tildeReconciliated y_hat using the MinTrace approach.

OptimalCombination.sample

sample(num_samples)
Sample probabilistic coherent distribution. Generates n samples from a probabilistic coherent distribution. The method uses fitted mean and probabilistic reconcilers, defined by the intervals_method selected during the reconciler’s instantiation. Currently available: normality, bootstrap, permbu. Parameters:
NameTypeDescriptionDefault
num_samplesintnumber of samples generated from coherent distribution.required
Returns:
NameTypeDescription
samplesndarrayCoherent samples of size (num_series, horizon, num_samples).

6. Emp. Risk Minimization

ERM

ERM(method, lambda_reg=0.01)
Bases: HReconciler Empirical Risk Minimization Reconciliation Class. The Empirical Risk Minimization reconciliation strategy relaxes the unbiasedness assumptions from previous reconciliation methods like MinT and optimizes square errors between the reconciled predictions and the validation data to obtain an optimal reconciliation matrix P. The exact solution for mathbfP\\mathbf{P} (method='closed') follows the expression: mathbfP\*=left(mathbfSintercalmathbfSright)1mathbfYintercalhatmathbfYleft(hatmathbfYhatmathbfYright)1\\mathbf{P}^{\*} = \\left(\\mathbf{S}^{\\intercal}\\mathbf{S}\\right)^{-1}\\mathbf{Y}^{\\intercal}\\hat{\\mathbf{Y}}\\left(\\hat{\\mathbf{Y}}\\hat{\\mathbf{Y}}\\right)^{-1} The alternative Lasso regularized mathbfP\\mathbf{P} solution (method='reg_bu') is useful when the observations of validation data is limited or the exact solution has low numerical stability. mathbfP\*=textargminmathbfPmathbfYmathbfSmathbfPhatY22+lambdamathbfPmathbfPtextBU1\\mathbf{P}^{\*} = \\text{argmin}_{\\mathbf{P}} ||\\mathbf{Y}-\\mathbf{S} \\mathbf{P} \\hat{Y} ||^{2}_{2} + \\lambda ||\\mathbf{P}-\\mathbf{P}_{\\text{BU}}||_{1} Parameters:
NameTypeDescriptionDefault
methodstrstr, one of closed, reg and reg_bu.required
lambda_regfloatfloat, l1 regularizer for reg and reg_bu.0.01

ERM.fit

fit(
    S,
    y_hat,
    y_insample,
    y_hat_insample,
    sigmah=None,
    intervals_method=None,
    num_samples=None,
    seed=None,
    tags=None,
    idx_bottom=None,
)
ERM Fit Method. Parameters:
NameTypeDescriptionDefault
SSumming matrix of size (base, bottom).required
y_hatForecast values of size (base, horizon).required
y_insampleTrain values of size (base, insample_size).required
y_hat_insampleInsample train predictions of size (base, insample_size).required
sigmahOptional[ndarray]Estimated standard deviation of the conditional marginal distribution.None
intervals_methodOptional[str]Sampler for prediction intervals, one of normality, bootstrap, permbu.None
num_samplesOptional[int]Number of samples for probabilistic coherent distribution.None
seedOptional[int]Seed for reproducibility.None
tagsOptional[dict[str, ndarray]]Each key is a level and each value its S indices.None
idx_bottomOptional[ndarray]Indices corresponding to the bottom level of S, size (bottom).None
Returns:
NameTypeDescription
selfobject, fitted reconciler.

ERM.predict

predict(S, y_hat, level=None)
Predict using reconciler. Predict using fitted mean and probabilistic reconcilers. Parameters:
NameTypeDescriptionDefault
SndarraySumming matrix of size (base, bottom).required
y_hatndarrayForecast values of size (base, horizon).required
levelOptional[list[int]]float list 0-100, confidence levels for prediction intervals. Default is None.None
Returns:
NameTypeDescription
y_tildedictReconciliated predictions.

ERM.fit_predict

fit_predict(
    S,
    y_hat,
    idx_bottom=None,
    y_insample=None,
    y_hat_insample=None,
    sigmah=None,
    level=None,
    intervals_method=None,
    num_samples=None,
    seed=None,
    tags=None,
)
ERM Reconciliation Method. Parameters:
NameTypeDescriptionDefault
SndarraySumming matrix of size (base, bottom).required
y_hatndarrayForecast values of size (base, horizon).required
idx_bottomndarrayIndices corresponding to the bottom level of S, size (bottom).None
y_insampleOptional[ndarray]Train values of size (base, insample_size).None
y_hat_insampleOptional[ndarray]Insample train predictions of size (base, insample_size).None
sigmahOptional[ndarray]Estimated standard deviation of the conditional marginal distribution.None
levelOptional[list[int]]float list 0-100, confidence levels for prediction intervals.None
intervals_methodOptional[str]Sampler for prediction intervals, one of normality, bootstrap, permbu.None
num_samplesOptional[int]Number of samples for probabilistic coherent distribution.None
seedOptional[int]Seed for reproducibility.None
tagsOptional[dict[str, ndarray]]Each key is a level and each value its S indices.None
Returns:
NameTypeDescription
y_tildeReconciliated y_hat using the ERM approach.

ERM.sample

sample(num_samples)
Sample probabilistic coherent distribution. Generates n samples from a probabilistic coherent distribution. The method uses fitted mean and probabilistic reconcilers, defined by the intervals_method selected during the reconciler’s instantiation. Currently available: normality, bootstrap, permbu. Parameters:
NameTypeDescriptionDefault
num_samplesintnumber of samples generated from coherent distribution.required
Returns:
NameTypeDescription
samplesndarrayCoherent samples of size (num_series, horizon, num_samples).

References

General Reconciliation

Hierarchical Probabilistic Coherent Predictions