You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在TFP状态空间构建分层贝叶斯不可观测成分模型?

在TFP状态空间中构建分层贝叶斯不可观测成分模型(Hierarchical UCM)的问题

我刚接触TensorFlow Probability(TFP)及概率编程,想咨询如何在TFP状态空间中构建分层贝叶斯不可观测成分模型(Hierarchical UCM)。

我的思路是指定一个全局回归参数,让所有模型的回归参数围绕该全局参数分布,尝试的代码如下:

# 指定全局回归参数,所有模型的回归参数围绕该参数分布
global_loc = tfp.HalfNormal(100)

# 第一个模型的趋势成分
trend_effect1 = tfp.sts.LocalLinearTrend(
    level_scale_prior=tfd.HalfNormal(100),
    slope_scale_prior=tfd.HalfNormal(100),
    observed_time_series=df_endo1.values,
    name='trend_effect'
)

# 第一个模型的回归成分,权重先验以全局参数为中心
exo_effects1 = tfp.sts.LinearRegression(
    design_matrix=df_exog1.values,
    weights_prior=tfd.Normal(loc=global_loc, scale = 1),
    name='exo_effects',
)

# 组合第一个模型
model1 = tfp.sts.Sum(
    [trend_effect1, exo_effects1],
    observed_time_series=df_endo1.values,
    observation_noise_scale_prior=tfp.distributions.HalfNormal(10)
)

# 第二个模型的趋势成分,斜率先验以全局参数为中心
trend_effect2 = tfp.sts.LocalLinearTrend(
    level_scale_prior=tfd.HalfNormal(1),
    slope_scale_prior=tfd.Normal(loc = global_loc, scale = 1),
    observed_time_series=df_endo2.values,
    name='trend_effect'
)

# 第二个模型的回归成分,权重先验以全局参数为中心
exo_effects2 = tfp.sts.LinearRegression(
    design_matrix=df_exog2.values,
    weights_prior=tfd.Normal(loc=global_loc, scale = 1),
    name='exo_effects',
)

# 组合第二个模型
model2 = tfp.sts.Sum(
    [trend_effect2, exo_effects2],
    observed_time_series=df_endo2.values,
    observation_noise_scale_prior=tfp.distributions.HalfNormal(10)
)
...

这段代码无法正常运行,我也参考过TFP的多层模型,但不确定如何将其应用到UCM上。同时也欢迎提供TFP之外的解决方案,比如基于statsmodels中UCM的贝叶斯模型实现思路。


内容的提问来源于stack exchange,提问作者DBruwel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 04:20:24