【问题标题】:How do I translate this Edward code to TFP code?如何将此 Edward 代码转换为 TFP 代码?
【发布时间】:2019-04-12 20:27:17
【问题描述】:

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

# 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()

【问题讨论】:

    标签: tensorflow tensorflow-probability edward


    【解决方案1】:

    【讨论】:

    • 是的!俊鹏非常乐于助人。但我对使用 TFP 编码 PMF 的其他方式持开放态度。
    猜你喜欢
    • 2019-11-19
    • 2019-05-26
    • 2018-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多