TFP 分发应该能够开箱即用地进行批处理。但是,我面临批量混合分布的问题。这是一个玩具示例(使用急切执行):
tfd = tfp.distributions
mix = np.array([[0.6, 0.4],[0.3, 0.7]] )
bimix_gauss = tfd.Mixture(
cat=tfd.Categorical(probs=mix),
components=[
tfd.Normal(loc=[-1.0, -2.0], scale=[0.1, 0.1]),
tfd.Normal(loc=[+1.0, +2.0], scale=[0.5, 0.5]),
])
print(bimix_gauss.sample())
print(bimix_gauss.prob(0.0))
基本上,它只是对默认示例的支持:https ://www.tensorflow.org/probability/api_docs/python/tfp/distributions/Mixture
采样工作正常,但此分布的概率返回错误:
InvalidArgumentError: cannot compute Add as input #1(zero-based) was expected to be a double tensor but is a float tensor [Op:Add] name: Mixture/prob/add/
任何猜测,我做错了什么?
PS。批量高斯分布的相同示例可以正常工作。