Given a 1D tensor containing the means of a Bernoulli distribution, how do I sample a corresponding 1D tensor with the given means?
TensorFlow only seems to have random_normal and random_uniform functions implemented. I could use something complicated like:
tf.ceil(tf.sub(tf.random_uniform((1, means.get_shape()[0])),means))
but the ceil function has no gradient defined in TensorFlow.
You can use tf.select, which is differentiable.
means = tf.constant([.3,.8])
a = tf.select(tf.random_uniform([1, 2])- means > 0.5, tf.ones([1,2]), tf.zeros([1,2]))
with tf.Session(''): a.eval()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With