层次混合网络 (HINT) 是一个高度模块化的框架,它将最先进的神经预测架构与任务特定的混合概率以及先进的层次协调策略相结合。这种强大的组合使得 HINT 能够生成准确且一致的概率预测。

HINT 将 TemporalNorm 模块集成到任何神经预测架构中,该模块将输入归一化到网络的非线性操作范围内,并通过全局跳跃连接重新组合输出的尺度,提高了准确性和训练鲁棒性。HINT 通过引导样本协调确保预测的一致性,从而将其基础样本恢复到聚合约束。

参考文献
- Kin G. Olivares, David Luo, Cristian Challu, Stefania La Vattiata, Max Mergenthaler, Artur Dubrawski (2023). “HINT: Hierarchical Mixture Networks For Coherent Probabilistic Forecasting”. Neural Information Processing Systems, submitted. Working Paper version available at arxiv.
- Kin G. Olivares, O. Nganba Meetei, Ruijun Ma, Rohan Reddy, Mengfei Cao, Lee Dicker (2022).”Probabilistic Hierarchical Forecasting with Deep Poisson Mixtures”. International Journal Forecasting, accepted paper available at arxiv.
- Kin G. Olivares, Federico Garza, David Luo, Cristian Challu, Max Mergenthaler, Souhaib Ben Taieb, Shanika Wickramasuriya, and Artur Dubrawski (2022). “HierarchicalForecast: A reference framework for hierarchical forecasting in python”. Journal of Machine Learning Research, submitted, abs/2207.03517, 2022b.

协调方法


源代码

get_identity_P

 get_identity_P (S:numpy.ndarray)

源代码

get_bottomup_P

 get_bottomup_P (S:numpy.ndarray)

*自下而上协调矩阵。

创建自下而上层次“投影”矩阵,其定义为:PBU=[0[b],[a]    I[b][b]]\mathbf{P}_{\text{BU}} = [\mathbf{0}_{\mathrm{[b],[a]}}\;|\;\mathbf{I}_{\mathrm{[b][b]}}]

参数
S: 大小为 (base, bottom) 的汇总矩阵。

返回值
P: 大小为 (bottom, base) 的协调矩阵。

参考文献
- Orcutt, G.H., Watts, H.W., & Edwards, J.B.(1968). “Data aggregation and information loss”. The American Economic Review, 58 , 773(787).*


源代码

get_mintrace_ols_P

 get_mintrace_ols_P (S:numpy.ndarray)

*MinTraceOLS 协调矩阵。

根据 Wickramasuriya 等人的提议,创建 MinTraceOLS 协调矩阵。

PMinTraceOLS=(SS)1S\mathbf{P}_{\text{MinTraceOLS}}=\left(\mathbf{S}^{\intercal}\mathbf{S}\right)^{-1}\mathbf{S}^{\intercal}

参数
S: 大小为 (base, bottom) 的汇总矩阵。

返回值
P: 大小为 (bottom, base) 的协调矩阵。

参考文献
- Wickramasuriya, S.L., Turlach, B.A. & Hyndman, R.J. (2020). “Optimal non-negative forecast reconciliation”. Stat Comput 30, 1167–1182, https://doi.org/10.1007/s11222-020-09930-0.*


源代码

get_mintrace_wls_P

 get_mintrace_wls_P (S:numpy.ndarray)

*MinTraceOLS 协调矩阵。

根据 Wickramasuriya 等人的提议,创建 MinTraceWLS 协调矩阵。取决于加权 GLS 估计量和相干性误差的协方差矩阵 Wh\mathbf{W}_{h} 的估计量。

Wh=Diag(S1[b]) \mathbf{W}_{h} = \mathrm{Diag}(\mathbf{S} \mathbb{1}_{[b]})

PMinTraceWLS=(SWhS)1SWh1\mathbf{P}_{\text{MinTraceWLS}}=\left(\mathbf{S}^{\intercal}\mathbf{W}_{h}\mathbf{S}\right)^{-1} \mathbf{S}^{\intercal}\mathbf{W}^{-1}_{h}

参数
S: 大小为 (base, bottom) 的汇总矩阵。

返回值
P: 大小为 (bottom, base) 的协调矩阵。

参考文献
- Wickramasuriya, S.L., Turlach, B.A. & Hyndman, R.J. (2020). “Optimal non-negative forecast reconciliation”. Stat Comput 30, 1167–1182, https://doi.org/10.1007/s11222-020-09930-0.*

HINT


源代码

HINT

 HINT (h:int, S:numpy.ndarray, model, reconciliation:str,
       alias:Optional[str]=None)

*HINT

层次混合网络 (HINT) 是一个高度模块化的框架,它将最先进的神经预测架构与任务特定的混合概率和先进的层次协调策略相结合。这种强大的组合使得 HINT 能够生成准确且一致的概率预测。

HINT 将 TemporalNorm 模块集成到任何神经预测架构中,该模块将输入归一化到网络的非线性操作范围内,并通过全局跳跃连接重新组合输出的尺度,提高了准确性和训练鲁棒性。HINT 通过引导样本协调确保预测的一致性,从而将其基础样本恢复到聚合约束。

可用协调方法
- 自下而上 (BottomUp)
- MinTraceOLS
- MinTraceWLS
- 单位矩阵 (Identity)

参数
h: int, 预测视野。
model: NeuralForecast 模型,来自 架构集合 的实例化模型类。
S: np.ndarray, 大小为 (base, bottom) 的汇总矩阵,参见 HierarchicalForecast 的 aggregate 方法
reconciliation: str, HINT 的协调方法,可选值为 [‘BottomUp’, ‘MinTraceOLS’, ‘MinTraceWLS’]。
alias: str, 可选,模型的自定义名称。
*


源代码

HINT.fit

 HINT.fit (dataset, val_size=0, test_size=0, random_seed=None,
           distributed_config=None)

*HINT.fit

HINT 通过最小化复合对数似然目标,在整个分层数据集上进行训练。HINT 框架将 TemporalNorm 集成到神经预测架构中,用于尺度解耦优化,从而增强跨层次学习系列尺度的鲁棒性。

参数
dataset: NeuralForecast 的 TimeSeriesDataset,详情请参阅此处
val_size: int, 验证集大小,(默认为 0)。
test_size: int, 测试集大小,(默认为 0)。
random_seed: int, 用于预测的随机种子。

返回值
self: 一个已拟合的基础 NeuralForecast 模型。
*


源代码

HINT.predict

 HINT.predict (dataset, step_size=1, random_seed=None,
               **data_module_kwargs)

*HINT.predict

在整个分层数据集上拟合基础模型后。HINT 使用引导样本协调恢复分层聚合约束。

参数
dataset: NeuralForecast 的 TimeSeriesDataset,详情请参阅此处
step_size: int, 连续预测之间的步长,(默认为 1)。
random_seed: int, 用于预测的随机种子。
**data_kwarg: dataset 模块的附加参数。

返回值
y_hat: NeuralForecast 模型的 numpy 预测结果。
*

使用示例

在此示例中,我们将使用 HINT 进行层次预测任务,这是一个具有聚合约束的多元回归问题。聚合约束可以用汇总矩阵 S[i][b]\mathbf{S}_{[i][b]} 紧凑地表示,下图显示了一个示例。

在此示例中,我们将对 TourismL 数据集进行一致性预测。

大纲
1. 导入包
2. 加载层次数据集
3. 拟合和预测 HINT
4. 预测图

import matplotlib.pyplot as plt

from neuralforecast.losses.pytorch import GMM, sCRPS
from datasetsforecast.hierarchical import HierarchicalData

# Auxiliary sorting
def sort_df_hier(Y_df, S_df):
    # NeuralForecast core, sorts unique_id lexicographically
    # by default, this class matches S_df and Y_hat_df order.    
    Y_df.unique_id = Y_df.unique_id.astype('category')
    Y_df.unique_id = Y_df.unique_id.cat.set_categories(S_df.index)
    Y_df = Y_df.sort_values(by=['unique_id', 'ds'])
    return Y_df

# Load TourismSmall dataset
horizon = 12
Y_df, S_df, tags = HierarchicalData.load('./data', 'TourismLarge')
Y_df['ds'] = pd.to_datetime(Y_df['ds'])
Y_df = sort_df_hier(Y_df, S_df)
level = [80,90]

# Instantiate HINT
# BaseNetwork + Distribution + Reconciliation
nhits = NHITS(h=horizon,
              input_size=24,
              loss=GMM(n_components=10, level=level),
              max_steps=2000,
              early_stop_patience_steps=10,
              val_check_steps=50,
              scaler_type='robust',
              learning_rate=1e-3,
              valid_loss=sCRPS(level=level))

model = HINT(h=horizon, S=S_df.values,
             model=nhits,  reconciliation='BottomUp')

# Fit and Predict
nf = NeuralForecast(models=[model], freq='MS')
Y_hat_df = nf.cross_validation(df=Y_df, val_size=12, n_windows=1)
Y_hat_df = Y_hat_df.reset_index()
# Plot coherent probabilistic forecast
unique_id = 'TotalAll'
Y_plot_df = Y_df[Y_df.unique_id==unique_id]
plot_df = Y_hat_df[Y_hat_df.unique_id==unique_id]
plot_df = Y_plot_df.merge(plot_df, on=['ds', 'unique_id'], how='left')
n_years = 5

plt.plot(plot_df['ds'][-12*n_years:], plot_df['y_x'][-12*n_years:], c='black', label='True')
plt.plot(plot_df['ds'][-12*n_years:], plot_df['HINT'][-12*n_years:], c='purple', label='mean')
plt.plot(plot_df['ds'][-12*n_years:], plot_df['HINT-median'][-12*n_years:], c='blue', label='median')
plt.fill_between(x=plot_df['ds'][-12*n_years:],
                 y1=plot_df['HINT-lo-90'][-12*n_years:].values,
                 y2=plot_df['HINT-hi-90'][-12*n_years:].values,
                 alpha=0.4, label='level 90')
plt.legend()
plt.grid()
plt.plot()