我是tensorflow概率的新手。我正在构建一个分层模型,为此我使用JointDistributionSequentialAPI:
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
)
]
)
然后,我打算使用混合物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
)
这行不通。我打算混合的是"0"处的随机变量;结束";批次形状(N,t,s(的层次模型的x_t_s。我想我需要将它们提供给混合物的组件参数。问题是,我无法轻松地从模型对象中检索这些变量。
有人能解决这个问题吗?
请注意,我尝试使用jds.model[-1]而不是jds,但这指向lambda函数,这不是我在这里需要的。
这里有几个想法。
- 考虑第一个分布的
SphericalUniform
- 对于相同类型的
Mixture
,请考虑使用MixtureSameFamily
- 将混合物放入层次模型中。即不是最后的分布是vMF而是
MixtureSameFamily(Categorical(...), VonMisesFisher(...))
- 如果以后要访问组件,可以调用
ds, xs = jds.sample_distributions()
,然后查看ds[-1].component_distribution
欢迎发送电子邮件tfprobability@tensorflow.org还有问题。