0

我在 Edward 中编写了概率矩阵分解模型。我正在尝试将其移植到 TFP,但我不确定如何定义对数似然和 KL 散度项。这是爱德华的代码 -

# MODEL
U = Normal(
    loc=0.0,
    scale=1.0,
    sample_shape=[n_latent_dims, batch_size])
V = Normal(
    loc=0.0,
    scale=1.0,
    sample_shape=[n_latent_dims, n_features])
R = Bernoulli(logits=tf.matmul(tf.transpose(U), V))
R_ph = tf.placeholder(tf.int32, [None, n_features])

# INFERENCE
qU = Normal(
    loc=tf.get_variable("qU/loc",
                        [n_latent_dims, batch_size]),
    scale=tf.nn.softplus(
        tf.get_variable("qU/scale",
                        [n_latent_dims, batch_size])))
qV = Normal(
    loc=tf.get_variable("qV/loc",
                        [n_latent_dims, n_features]),
    scale=tf.nn.softplus(
        tf.get_variable("qV/scale",
                        [n_latent_dims, n_features])))
qR = Bernoulli(logits=tf.matmul(tf.transpose(qU), qV))
qR_avg = Bernoulli(
    logits=tf.reduce_mean(qR.parameters['logits'], 0))
log_likli = tf.reduce_mean(qR_avg.log_prob(R_ph), 1)
inference = ed.KLqp(
    {
        U: qU,
        V: qV
    }, data={self.R: self.R_ph})
inference_init = inference.initialize()
init = tf.global_variables_initializer()
4

1 回答 1

0

好像你在https://github.com/tensorflow/probability/issues/364得到了答案

于 2019-04-13T15:53:11.803 回答