我是 tensorflow 的新手,正在尝试将 STAN 模型转换为 TFP。这是我的 TFP 模型,使用JointDistributionCoroutineAutoBatched
.
def make_joint_distribution_coroutine(Depth,N_RNA):
def model():
## c1 prior
c1 = yield tfd.Gamma(concentration = 1.1, rate = 0.005)
## c2 prior
c2 = yield tfd.Gamma(concentration = 1.1, rate = 0.005)
## s prior
s = yield GammaModeSD(1,1)
## theta prior
theta = yield tfd.LogNormal(0,s)
## p prior
p = yield BetaModeConc(0.1,c1)
## tfp bug, need to cast tensor to float32
#theta = tf.cast(theta, tf.float32)
#p = tf.cast(p, tf.float32)
## q formula
q = (theta*p)/(1-p+theta*p)
## qi prior
qi = yield BetaModeConc(tf.repeat(q,N_RNA), c2)
## qi likelihood
k = yield tfd.Binomial(tf.cast(Depth,tf.float32),qi)
# p likelihood
a = yield tfd.Binomial(tf.cast(Depth,tf.float32),p)
return tfd.JointDistributionCoroutineAutoBatched(model)
我的模型生成两组不同的数据,它们是a
和k
。如果它只有a
or k
,那么我可以指定我的log_prob
功能
def joint_log_prob(*args):
return joint.log_prob(*args, likelihood = data)
或者
joint_log_prob = lambda *x: model.log_prob(x + (data,))
但我的问题是如何将两组不同的数据合并到一个log_prob
函数中?谢谢!