Skip to main content
Here we provide a collection of methods designed to provide hierarchically coherent probabilistic distributions, which means that they generate samples of multivariate time series with hierarchical linear constraints. We designed these methods to extend the core.HierarchicalForecast capabilities class. Check their usage example here.

1. Normality

Normality

Normality(S, P, y_hat, sigmah, W, seed=0)
Normality Probabilistic Reconciliation Class. The Normality method leverages the Gaussian Distribution linearity, to generate hierarchically coherent prediction distributions. This class is meant to be used as the sampler input as other HierarchicalForecast reconciliation classes. Given base forecasts under a normal distribution: y^hN(μ^,W^h)\hat{y}_{h} \sim \mathrm{N}(\hat{\boldsymbol{\mu}}, \hat{\mathbf{W}}_{h}) The reconciled forecasts are also normally distributed: y~hN(SPμ^,SPW^hPS)\tilde{y}_{h} \sim \mathrm{N}(\mathbf{S}\mathbf{P}\hat{\boldsymbol{\mu}}, \mathbf{S}\mathbf{P}\hat{\mathbf{W}}_{h} \mathbf{P}^{\intercal} \mathbf{S}^{\intercal}) Parameters:
NameTypeDescriptionDefault
SUnion[ndarray, spmatrix]np.array, summing matrix of size (base, bottom).required
PUnion[ndarray, spmatrix]np.array, reconciliation matrix of size (bottom, base).required
y_hatndarrayPoint forecasts values of size (base, horizon).required
WUnion[ndarray, spmatrix]np.array, hierarchical covariance matrix of size (base, base).required
sigmahndarraynp.array, forecast standard dev. of size (base, horizon).required
seedintint, random seed for numpy generator’s replicability. Default is 0.0

Normality.get_samples

get_samples(num_samples)
Normality Coherent Samples. Obtains coherent samples under the Normality assumptions. Parameters:
NameTypeDescriptionDefault
num_samplesintnumber of samples generated from coherent distribution.required
Returns:
NameTypeDescription
samplesndarrayCoherent samples of size (base, horizon, num_samples).

2. Bootstrap

Bootstrap

Bootstrap(
    S, P, y_hat, y_insample, y_hat_insample, num_samples=100, seed=0, W=None
)
Bootstrap Probabilistic Reconciliation Class. This method goes beyond the normality assumption for the base forecasts, the technique simulates future sample paths and uses them to generate base sample paths that are latered reconciled. This clever idea and its simplicity allows to generate coherent bootstraped prediction intervals for any reconciliation strategy. This class is meant to be used as the sampler input as other HierarchicalForecast reconciliation classes. Given a boostraped set of simulated sample paths: y^tau[1],,y^tau[B])\hat{\mathbf{y}}^{[1]}_{\\tau}, \dots ,\hat{\mathbf{y}}^{[B]}_{\\tau}) The reconciled sample paths allow for reconciled distributional forecasts: (SPy^tau[1],,SPy^tau[B])(\mathbf{S}\mathbf{P}\hat{\mathbf{y}}^{[1]}_{\\tau}, \dots ,\mathbf{S}\mathbf{P}\hat{\mathbf{y}}^{[B]}_{\\tau}) Parameters:
NameTypeDescriptionDefault
SUnion[ndarray, spmatrix]np.array, summing matrix of size (base, bottom).required
PUnion[ndarray, spmatrix]np.array, reconciliation matrix of size (bottom, base).required
y_hatndarrayPoint forecasts values of size (base, horizon).required
y_insamplendarrayInsample values of size (base, insample_size).required
y_hat_insamplendarrayInsample point forecasts of size (base, insample_size).required
num_samplesintint, number of bootstraped samples generated.100
seedintint, random seed for numpy generator’s replicability.0

Bootstrap.get_samples

get_samples(num_samples)
Bootstrap Sample Reconciliation Method. Applies Bootstrap sample reconciliation method as defined by Gamakumara 2020. Generating independent sample paths and reconciling them with Bootstrap. Parameters:
NameTypeDescriptionDefault
num_samplesintint, number of samples generated from coherent distribution.required
Returns:
NameTypeDescription
samplesCoherent samples of size (base, horizon, num_samples).

3. PERMBU

PERMBU

PERMBU(
    S,
    tags,
    y_hat,
    y_insample,
    y_hat_insample,
    sigmah,
    num_samples=None,
    seed=0,
    P=None,
)
PERMBU Probabilistic Reconciliation Class. The PERMBU method leverages empirical bottom-level marginal distributions with empirical copula functions (describing bottom-level dependencies) to generate the distribution of aggregate-level distributions using BottomUp reconciliation. The sample reordering technique in the PERMBU method reinjects multivariate dependencies into independent bottom-level samples. hatepsilon_i,t\\hat{\\epsilon}\_{i,t} Algorithm:
  1. For all series compute conditional marginals distributions.
  2. Compute residuals hatepsilon_i,t\\hat{\\epsilon}\_{i,t} and obtain rank permutations.
  3. Obtain K-sample from the bottom-level series predictions.
  4. Apply recursively through the hierarchical structure: 4.1. For a given aggregate series ii and its children series: 4.2. Obtain children’s empirical joint using sample reordering copula. 4.2. From the children’s joint obtain the aggregate series’s samples.
Parameters:
NameTypeDescriptionDefault
Sarraysumming matrix of size (base, bottom).required
tagsdict[str, ndarray]Each key is a level and each value its S indices.required
y_insamplearrayInsample values of size (base, insample_size).required
y_hat_insamplearrayInsample point forecasts of size (base, insample_size).required
sigmaharrayforecast standard dev. of size (base, horizon).required
num_samplesintnumber of normal prediction samples generated. Default is NoneNone
seedintrandom seed for numpy generator’s replicability. Default is 0.0

PERMBU.get_samples

get_samples(num_samples=None)
PERMBU Sample Reconciliation Method. Applies PERMBU reconciliation method as defined by Taieb et. al 2017. Generating independent base prediction samples, restoring its multivariate dependence using estimated copula with reordering and applying the BottomUp aggregation to the new samples. Parameters:
NameTypeDescriptionDefault
num_samplesintnumber of samples generated from coherent distribution.None
Returns:
NameTypeDescription
samplesndarrayCoherent samples of size (base, horizon, num_samples).

References