我是张量流概率的新手。我正在构建一个分层模型,为此我使用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 函数,这不是我在这里需要的。