python - 张量流概率:从联合分布中检索特定的随机变量
问题描述
我是张量流概率的新手。我正在构建一个分层模型,为此我使用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
)
这行不通。我打算混合的是批处理形状(N,T,S)的分层模型“末端”的随机变量x_t_s 。我想我需要将它们提供给混合物的components参数。问题是我无法轻松地从模型对象中检索这些变量。
有没有人看到解决这个问题的方法?
请注意,我尝试使用jds.model[-1]而不是jds,但这指向 lambda 函数,这不是我在这里需要的。
解决方案
这里有几个想法。
- 考虑
SphericalUniform
第一个分布。 - 对于
Mixture
相同类型的 s,可以考虑使用MixtureSameFamily
. - 将混合物放入分层模型中。即最后一个发行版不是一个 vMF,它可能是一个
MixtureSameFamily(Categorical(...), VonMisesFisher(...))
. - 如果您以后想访问组件,可以调用
ds, xs = jds.sample_distributions()
,然后查看ds[-1].component_distribution
如有问题,请随时发送电子邮件至 tfprobability@tensorflow.org。
推荐阅读
- android - 即使在启用 Places API 后,android 中的位置自动建议也不起作用
- ocr - 如何为 Tesseract 4.1.0 创建训练数据文件
- go - 同时收听 Go 通道数组
- java - Google Oauth By url For youtube api
- css - 边框半径在 Windows Outlook 上的电子邮件模板中不起作用
- session - Session中存储大量数据
- r - 在一定的权重条件下向数据集中添加一列
- javascript - 循环遍历计算属性 Vue
- android - 第一次没有得到服务器 android volley 的响应
- excel - 当 A 列(帐户代码)相同时,求和 B 列(借方)[Excel]