最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Tensorflow Probability: Normal Distribution: log_prob Incompatible shapes - Stack Overflow

programmeradmin1浏览0评论

I am working on TF Probability tutorials and working on a 2D grid approximation for mu, sigma of Normal distribution. I am trying to understand to what level I should expect broadcasting to work for the following code:

import tensorflow as tf
import tensorflow_probability as tfp
tfd = tfp.distributions

mu_list = tf.linspace(start=150, stop=160, num=100)
sigma_list = tf.linspace(start=7, stop=9, num=100)
mesh = tf.meshgrid(mu_list, sigma_list)
mu = tf.cast(tf.reshape(mesh[0], -1), tf.float32)
sig = tf.cast(tf.reshape(mesh[1], -1), tf.float32)
dists = tfd.Normal(loc=mu, scale=sig)
heights = tfd.Normal(loc=150, scale=20).sample(352)
dists.prob(heights)

This fails with

Incompatible shapes: [352] vs. [10000]

I am pretty sure I can solve this with either a tf.map_fn or a tf.vectorized_map operation, but curious if it is possible to generate a [10000, 352] shape tensor in the .prob/.log_prob call.

发布评论

评论列表(0)

  1. 暂无评论