tf.contrib.bayesflow.stochastic_tensor.SampleAndReshapeValue

class tf.contrib.bayesflow.stochastic_tensor.SampleAndReshapeValue

Ask the StochasticTensor for n samples and reshape the result.

Sampling from a StochasticTensor increases the rank of the value by 1 (because each sample represents a new outer dimension).

This ValueType requests n samples from StochasticTensors run within its context that the outer two dimensions are reshaped to intermix the samples with the outermost (usually batch) dimension.

Example:

# mu and sigma are both shaped (2, 3)
mu = [[0.0, -1.0, 1.0], [0.0, -1.0, 1.0]]
sigma = tf.constant([[1.1, 1.2, 1.3], [1.1, 1.2, 1.3]])

with sg.value_type(sg.SampleAndReshapeValue(n=2)):
  dt = sg.DistributionTensor(
      distributions.Normal, mu=mu, sigma=sigma)

# sample(2) creates a (2, 2, 3) tensor, and the two outermost dimensions
# are reshaped into one: the final value is a (4, 3) tensor.
dt_value = dt.value()
assertEqual(dt_value.get_shape(), (4, 3))

dt_value_val = sess.run([dt_value])[0]  # or e.g. run([tf.identity(dt)])[0]
assertEqual(dt_value_val.shape, (4, 3))
doc_TensorFlow
2016-10-14 12:44:19
Comments
Leave a Comment

Please login to continue.