Stochastic Tensor Value Types

class tf.contrib.bayesflow.stochastic_tensor.MeanValue


tf.contrib.bayesflow.stochastic_tensor.MeanValue.__init__(stop_gradient=False) {:#MeanValue.init}


tf.contrib.bayesflow.stochastic_tensor.MeanValue.declare_inputs(unused_stochastic_tensor, unused_inputs_dict)


tf.contrib.bayesflow.stochastic_tensor.MeanValue.popped_above(unused_value_type)


tf.contrib.bayesflow.stochastic_tensor.MeanValue.pushed_above(unused_value_type)


tf.contrib.bayesflow.stochastic_tensor.MeanValue.stop_gradient


class tf.contrib.bayesflow.stochastic_tensor.SampleValue

Draw samples, possibly adding new outer dimensions along the way.

This ValueType draws samples from StochasticTensors run within its context, increasing the rank according to the requested shape.

Examples:

mu = tf.zeros((2,3))
sigma = tf.ones((2, 3))
with sg.value_type(sg.SampleValue()):
  st = sg.StochasticTensor(
    tf.contrib.distributions.Normal, mu=mu, sigma=sigma)
# draws 1 sample and does not reshape
assertEqual(st.value().get_shape(), (2, 3))
mu = tf.zeros((2,3))
sigma = tf.ones((2, 3))
with sg.value_type(sg.SampleValue(4)):
  st = sg.StochasticTensor(
    tf.contrib.distributions.Normal, mu=mu, sigma=sigma)
# draws 4 samples each with shape (2, 3) and concatenates
assertEqual(st.value().get_shape(), (4, 2, 3))

tf.contrib.bayesflow.stochastic_tensor.SampleValue.__init__(shape=(), stop_gradient=False) {:#SampleValue.init}

Sample according to shape.

For the given StochasticTensor st using this value type, the shape of st.value() will match that of st.distribution.sample(shape).

Args:
  • shape: A shape tuple or int32 tensor. The sample shape. Default is a scalar: take one sample and do not change the size.
  • stop_gradient: If True, StochasticTensors' values are wrapped in stop_gradient, to avoid backpropagation through.

tf.contrib.bayesflow.stochastic_tensor.SampleValue.declare_inputs(unused_stochastic_tensor, unused_inputs_dict)


tf.contrib.bayesflow.stochastic_tensor.SampleValue.popped_above(unused_value_type)


tf.contrib.bayesflow.stochastic_tensor.SampleValue.pushed_above(unused_value_type)


tf.contrib.bayesflow.stochastic_tensor.SampleValue.shape


tf.contrib.bayesflow.stochastic_tensor.SampleValue.stop_gradient


tf.contrib.bayesflow.stochastic_tensor.value_type(dist_value_type)

Creates a value type context for any StochasticTensor created within.

Typical usage:

with sg.value_type(sg.MeanValue(stop_gradients=True)):
  st = sg.StochasticTensor(tf.contrib.distributions.Normal, mu=mu,
                           sigma=sigma)

In the example above, st.value() (or equivalently, tf.identity(st)) will be the mean value of the Normal distribution, i.e., mu (possibly broadcasted to the shape of sigma). Furthermore, because the MeanValue was marked with stop_gradients=True, this value will have been wrapped in a stop_gradients call to disable any possible backpropagation.

Args:
  • dist_value_type: An instance of MeanValue, SampleValue, or any other stochastic value type.
Yields:

A context for StochasticTensor objects that controls the value created when they are initialized.

Raises:
  • TypeError: if dist_value_type is not an instance of a stochastic value type.

tf.contrib.bayesflow.stochastic_tensor.get_current_value_type()