tfsnippet.stochastic

tfsnippet.stochastic.validate_n_samples(value, name)

Validate the n_samples argument.

Parameters:
  • value – An int32 value, a int32 tf.Tensor, or None.
  • name (str) – Name of the argument (in error message).
Returns:

The validated n_samples argument value.

Return type:

int or tf.Tensor

Raises:

TypeError or ValueError or None – If the value cannot be validated.

class tfsnippet.stochastic.StochasticTensor(distribution, tensor, n_samples=None, group_ndims=0, is_reparameterized=None, log_prob=None)

Bases: tfsnippet.utils.tensor_wrapper.TensorWrapper

Samples or observations of a stochastic variable.

StochasticTensor is a tensor-like object, carrying samples or observations of a random variable, following some distribution of a specific Distribution type.

It mimics the interface of zhusuan.model.StochasticTensor, except that it does not carry a name, and does not add itself to any BayesianNet context automatically. This modified design fits the concept of Module better than the original zhusuan.model.StochasticTensor.

__init__(distribution, tensor, n_samples=None, group_ndims=0, is_reparameterized=None, log_prob=None)

Construct the StochasticTensor.

Parameters:
distribution

Get the Distribution of this StochasticTensor.

Returns:The distribution instance.
Return type:Distribution
group_ndims

Get the number of dimensions to be considered as events group.

Returns:The configured group_ndims.
Return type:int or tf.Tensor
is_continuous

Whether or not this StochasticTensor is continuous?

Returns:Equivalent to self.distribution.is_continuous.
Return type:bool
is_reparameterized

Whether or not this StochasticTensor is re-parameterized?

Returns:A boolean indicating whether it is re-parameterized.
Return type:bool
log_prob(group_ndims=None)

Compute the log-densities of this StochasticTensor.

Parameters:group_ndims (int or tf.Tensor) – If specified, overriding the configured group_ndims.
Returns:The log-densities.
Return type:tf.Tensor
n_samples

Get the number of samples taken in Distribution.sample.

Returns:The number of samples.
Return type:int or tf.Tensor or None
prob(group_ndims=None)

Compute the densities of this StochasticTensor.

Parameters:group_ndims (int or tf.Tensor) – If specified, overriding the configured group_ndims.
Returns:The densities.
Return type:tf.Tensor
tensor

Get the samples or observations tensor.

Returns:The tensor specified at construction.
Return type:tf.Tensor