首页 > 解决方案 > 基于TensorFlow概率中的另一个随机变量从张量中选择一个法线

问题描述

我试图根据分类分布的输出从一系列正态分布中选择一个样本,但似乎无法提出完全正确的方法。使用类似的东西:

tfp.distributions.JointDistributionSequential([
        tfp.distributions.Categorical(probs=[0, 0, 1/2, 1/2]),
        lambda c: tfp.distributions.Normal([0, 1, -10, 30], 1)[..., c]
    ])

完全返回我想要的单个案例,但是如果我想要一次多个样本,这会中断(因为 c 变成了一个 numpy 数组而不是一个整数。这可能吗?如果可以,我应该怎么做?

(我也尝试使用 OneHotCategorical 和乘法,但这根本不起作用!)

标签: pythontensorflowdata-scienceprobabilitytensorflow-probability

解决方案


还有另一个发行版

tfd.MixtureSameFamily(
  mixture_distribution=tfd.Categorical(probs=[0, 0, .5, .5]),
  components_distribution=tfd.Normal([0, 1, -10, 30], 1))

推荐阅读