【问题标题】:How to Decompose and Visualise Slope Component in Tensorflow ProbabilityTensorflow概率中如何分解和可视化斜率分量
【发布时间】:2020-05-30 21:15:48
【问题描述】:

我正在运行 tensorflow 2.1 和 tensorflow_probability 0.9。我已经拟合了带有季节性成分的结构时间序列模型。我正在使用 Tensorflow Probability Structural Time Series Probability 示例中的代码: Tensorflow Github.

在示例中,有一个很好的分解图:


# Get the distributions over component outputs from the posterior marginals on
# training data, and from the forecast model.
component_dists = sts.decompose_by_component(
    demand_model,
    observed_time_series=demand_training_data,
    parameter_samples=q_samples_demand_)

forecast_component_dists = sts.decompose_forecast_by_component(
    demand_model,
    forecast_dist=demand_forecast_dist,
    parameter_samples=q_samples_demand_)




demand_component_means_, demand_component_stddevs_ = (
    {k.name: c.mean() for k, c in component_dists.items()},
    {k.name: c.stddev() for k, c in component_dists.items()})

(
    demand_forecast_component_means_,
    demand_forecast_component_stddevs_
) = (
    {k.name: c.mean() for k, c in forecast_component_dists.items()},
    {k.name: c.stddev() for k, c in forecast_component_dists.items()}
    )

当使用趋势组件时,是否可以同时分解和可视化:

趋势/_level_scale & 趋势/_slope_scale

我尝试了很多排列来提取趋势组件的嵌套元素,但没有成功。

提前感谢您的宝贵时间。

【问题讨论】:

    标签: time-series tensorflow-probability state-space


    【解决方案1】:

    我们没有为此编写单独的 STS 接口,但是您可以通过直接查询底层状态空间模型的边际均值和协方差来访问潜在状态的后验(在这种情况下,包括水平和斜率) :

    ssm = model.make_state_space_model(
            num_timesteps=num_timesteps,
            param_vals=parameter_samples)
    posterior_means, posterior_covs = (
      ssm.posterior_marginals(observed_time_series))
    

    您还应该能够通过运行 ssm.posterior_sample(observed_time_series, num_samples) 从关节后部抽取样本。

    目前从没有批次形状的模型中提取后验样本时似乎存在故障 (Could not find valid device for node. Node:{{node Reshape}}):虽然我们修复了这个问题,但它应该可以添加人工批次维度作为解决方法: ssm.posterior_sample(observed_time_series[tf.newaxis, ...], num_samples).

    【讨论】:

    • 非常感谢戴夫。对于后边距,我发现我还必须添加人工批量维度。 terior_means,terior_covs = (ssm.posterior_marginals(observed_time_series[...,tf.newaxis]))。列中需要 tf.newaxis。绝妙的解决方案。
    • 啊对---尾随单位维度表示它是一维时间序列。在 STS 中,这只是假设,但 LinearGaussianStateSpaceModel 期望明确地看到它。很高兴你的工作顺利!
    • 不管怎样,在tfp-nightly 的最新版本中应该不再需要人工批量维度解决方法(我们修复了故障)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-07
    • 2017-11-02
    • 2019-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多