Autoregressive model

本文深入探讨了Autoregressive(AR)模型的概念及其在时间序列预测中的应用。AR模型通过建立当前值与历史值之间的线性关系进行预测,是一种经典的Markov模型。文章详细解释了AR过程的数学公式,包括如何利用白噪声和过程平均值来定义模型的随机性和不确定性。此外,还介绍了如何使用tfp库中的sts.Autoregressive组件在TensorFlow平台上构建AR模型。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在下面build_model的代码中涉及到tfp中的sts.Autoregressive.很长时间不用,恍惚中忘记了何为Autoregressive?通过阅读Autoregressive Model: Definition & The AR Process学习到以下几点:

  • auto不是英文单词,而是表示self的希腊语.这可能也说明这个模型有多么经典.
  • autoregressive model旨在寻找当前时刻的值,与相近历史值的线性关系,因此又叫做markov model.与过去几个值,由order这个参数来指定.
  • autoregressive model本身是一个包含随机信息的过程,可以很好的预测未来趋势,但无法得到准确的point estimation.(The AR process is an example of a stochastic process, which have degrees of uncertainty or randomness built in. The randomness means that you might be able to predict future trends pretty well with past data, but you’re never going to get 100 percent accuracy. Usually, the process gets “close enough” for it to be useful in most scenarios.)

数学公式还是最简洁的表达方式,AR model表示如下:

y t = φ 1 y t − 1 + φ 2 y t − 2 + . . . + φ p y t − p + A t + δ y_t = \varphi_1 y_{t-1} + \varphi_2 y_{t-2} + ... + \varphi_p y_{t-p} + A_t+ \delta yt=φ1yt1+φ2yt2+...+φpytp+At+δ

  • y t − 1 y_{t-1} yt1, y t − 2 y_{t-2} yt2, …, y t − p y_{t-p} ytp are the past series values.
  • A t A_t At is white noise (i.e. randomness)
  • δ \delta δ is defined by the following equation:

δ = ( 1 − ∑ i = 1 p ϕ i ) μ \delta = (1 - \sum_{i=1}^p \phi_i) \mu δ=(1i=1pϕi)μ
where μ \mu μ is the process mean.

为在markdown中写出上述公式,参照了LaTeX Math Symbols and Motivating Examples.

def build_model(observed_time_series):
  hour_of_day_effect = sts.Seasonal(
      num_seasons=24,
      observed_time_series=observed_time_series,
      name='hour_of_day_effect')
  day_of_week_effect = sts.Seasonal(
      num_seasons=7, num_steps_per_season=24,
      observed_time_series=observed_time_series,
      name='day_of_week_effect')
  temperature_effect = sts.LinearRegression(
      design_matrix=tf.reshape(temperature - np.mean(temperature),
                               (-1, 1)), name='temperature_effect')
  autoregressive = sts.Autoregressive(
      order=1, # scalar Python positive int specifying the number of past timesteps to regress on.
      observed_time_series=observed_time_series,
      name='autoregressive')
  model = sts.Sum([hour_of_day_effect,
                   day_of_week_effect,
                   temperature_effect,
                   autoregressive],
                   observed_time_series=observed_time_series)
  return model

代码来自Structural Time Series Modeling Case Studies: Atmospheric CO2 and Electricity Demand

流模型是一种建立原始分布与简单分布之间映射关系的方法,通过对更简单的分布建模来绕开后验过于复杂无法求解的问题。其中一种流模型叫做Autoregressive Flow (ARFlow),它使用了重要的change of variables theorem来建立映射关系,并通过变化后的目标函数和梯度求解方法进行优化。ARFlow可以通过PixelCNN的Mask方法得到条件密度函数(CDF)分布的参数,并计算CDF得到变量z,并通过PDF计算Jacobian矩阵的行列式。另一种流模型是RealNVP,类似于Autoregressive Model,但不同之处在于RealNVP通过MLP获得用于计算CDF的对应分布的参数,然后根据这些参数计算变量z,并通过log_prob()方法得到概率密度函数。最后,如果处理离散数据,如图像中的像素值,连续方法可能会导致性能下降。因此,在流模型中可以给原始数据添加噪音来提高对离散数据的拟合性能。对于离散数据的建模,可以使用Gaussian Mixture Model (GMM),通过PyTorch的Distribution库计算GMM模型,其中每个数据的每个component的权重通过logits进行softmax计算。在ARFlow中,可以使用GMM的CDF计算概率,如果要进行采样,可以通过计算GMM的CDF的逆函数。采样过程类似于从GMM中采样一个数,可以先根据logits选择Gaussian component,然后从所选的Gaussian中采样得到最终的样本。<span class="em">1</span><span class="em">2</span><span class="em">3</span><span class="em">4</span>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值