python - 基于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 和乘法,但这根本不起作用!)
解决方案
还有另一个发行版:
tfd.MixtureSameFamily(
mixture_distribution=tfd.Categorical(probs=[0, 0, .5, .5]),
components_distribution=tfd.Normal([0, 1, -10, 30], 1))
推荐阅读
- ffmpeg - 创建 PIP 视频,同时为画中画添加透明度?
- javascript - 使用节点 js 的 ajax 响应
- c++ - 在 C++ 中使用 Tesseract OCR 时如何启用“安静模式”?
- c++ - C ++将函数的结果传递给另一个函数
- android-source - 将移动网络添加到 Android 设备
- mysql - 如何在本月 1 日到上月 17 日之间进行选择
- javascript - 将相同函数的结果添加到没有临时变量的多个变量中
- php - WooCommerce 中特定类别的子类别的最低购物车数量
- powerbi - 根据切片器选择创建计算表
- kubernetes - 使用 kubeadm join 命令加入现有集群时出现未经授权的错误