【发布时间】:2020-12-29 00:10:11
【问题描述】:
我是张量流概率的新手。 我正在构建一个分层模型,为此我使用 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
)
这不起作用。我打算混合的是分层模型“末端”的随机变量,x_t_s,批量形状(N,T,S)。我想我需要将它们提供给混合的 components 参数。问题是我无法轻松地从 model 对象中检索这些变量。
有没有人想办法解决这个问题?
请注意,我尝试使用 jds.model[-1] 而不是 jds,但这指向 lambda 函数,这不是我需要的.
【问题讨论】:
标签: python tensorflow tensorflow-probability mixture-model hierarchical-bayesian