【问题标题】:Tensorflow probability: retrieving specific random variable from joint distribution张量流概率:从联合分布中检索特定的随机变量
【发布时间】:2020-12-29 00:10:11
【问题描述】:

我是张量流概率的新手。 我正在构建一个分层模型,为此我使用 JointDistributionSequential API:

jds = tfp.distributions.JointDistributionSequential(
[
    # mu_g ~ uniform on sphere
    tfp.distributions.VonMisesFisher(
        mean_direction= [1] + [0]*(D-1),
        concentration=0,
        validate_args=True,
        name="mu_g"
    ),
    # epsilon ~ Exponential
    tfp.distributions.Exponential(
        rate=1,
        validate_args=True,
        name="epsilon"
    ),
    # mu_s ~ von Mises Fisher centered on mu_g
    lambda epsilon, mu_g: tfp.distributions.VonMisesFisher(
        mean_direction=mu_g,
        concentration=np.array(
            [epsilon]*S
        ),
        validate_args=True,
        name="mu_s"
    ),
    # sigma ~ Exponential
    tfp.distributions.Exponential(
        rate=1,
        validate_args=True,
        name="sigma"
    ),
    # mu_t_s ~ von Mises Fisher centered on mu_s
    lambda sigma, mu_s: tfp.distributions.VonMisesFisher(
        mean_direction=mu_s,
        concentration=np.array(
            [
                [sigma]*S
            ]*T
        ),
        validate_args=True,
        name="mu_t_s"
    ),
    # kappa ~ Exponential
    tfp.distributions.Exponential(
        rate=1,
        validate_args=True,
        name="kappa"
    ),
    # x_t_s ~ mixture of L groups of vMF
    lambda kappa, mu_t_s: tfp.distributions.VonMisesFisher(
        mean_direction=mu_t_s,
        concentration=np.array(
            [
                [
                    [
                        kappa
                    ]*S
                ]*T
            ]*N
        ),
        validate_args=True,
    name="x_t_s
    )            
]
)

然后我打算使用 Mixture API 创建这些模型的混合:

l = tfp.distributions.Categorical(
probs=np.array(
    [
        [
            [
                [1.0/L]*L
            ]*S
        ]*T 
    ]*N               
),
name="l"
)

mixture = tfd.Mixture(
cat=l,
components=[
    jds
] * L,
validate_args=True
)

这不起作用。我打算混合的是分层模型“末端”的随机变量,x_t_s,批量形状(N,T,S)。我想我需要将它们提供给混合的 components 参数。问题是我无法轻松地从 model 对象中检索这些变量。

有没有人想办法解决这个问题?

请注意,我尝试使用 jds.model[-1] 而不是 jds,但这指向 lambda 函数,这不是我需要的.

【问题讨论】:

    标签: python tensorflow tensorflow-probability mixture-model hierarchical-bayesian


    【解决方案1】:

    这里有几个想法。

    1. 考虑使用SphericalUniform 进行第一次分发。
    2. 对于同类型的Mixtures,考虑使用MixtureSameFamily
    3. 将混合物放入分层模型中。即,最后一个发行版不是 vMF,而是MixtureSameFamily(Categorical(...), VonMisesFisher(...))
    4. 如果以后想访问组件,可以拨打ds, xs = jds.sample_distributions(),看ds[-1].component_distribution

    如有问题,请随时发送电子邮件至 tfprobability@tensorflow.org。

    【讨论】:

    • 您好,感谢您的帮助 :) 1- 感谢您的提示,但这不会让我的臀部看起来很奇怪吗? 2-3-我考虑过那个设计,问题是如果我这样做,x_t_s vMF 的 L 表示将从相同的mu_t_s 分布中提取,对吗?我想要的是生成 L 独立的mu_g,从而产生不同的mu_smu_s_t 分布
    • 4-sample_distributions 方法确实返回了一个 vMF,但使用给定参数实例化,有没有办法将 RV 作为jds 分布的结果返回,以便调用此 RV 的示例方法每次都会产生新的参数?
    • 1 - 分布相同,不会改变任何东西,只是更简洁
    • 2/3 - 这有点太详细了,无法在评论中解决。您可能需要考虑使用 tfd.Sample,以避免您为复制这些分布的参数而进行的所有数组堆叠。查看分布的 batch_shape 和 event_shape 属性会很有帮助。
    • 4 - TFP 中的所有分布均已归一化,因此“每次都生成新参数”的唯一方法是在关节上调用 sample。如果你想要的只是最后一部分,你可以写jds.sample()[-1]。如果你想要100个不同参数的样本,你可以写jds.sample(100)
    猜你喜欢
    • 2020-07-02
    • 1970-01-01
    • 2018-07-31
    • 2020-04-06
    • 1970-01-01
    • 2012-03-15
    • 1970-01-01
    • 2021-10-07
    • 1970-01-01
    相关资源
    最近更新 更多