tfsnippet.stochastic¶
-
tfsnippet.stochastic.
validate_n_samples
(value, name)¶ Validate the n_samples argument.
Parameters: 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 specificDistribution
type.It mimics the interface of
zhusuan.model.StochasticTensor
, except that it does not carry a name, and does not add itself to anyBayesianNet
context automatically. This modified design fits the concept ofModule
better than the originalzhusuan.model.StochasticTensor
.-
__init__
(distribution, tensor, n_samples=None, group_ndims=0, is_reparameterized=None, log_prob=None)¶ Construct the
StochasticTensor
.Parameters: - distribution (tfsnippet.distributions.Distribution) – The
distribution of this
StochasticTensor
. - tensor (tf.Tensor or TensorWrapper) – The samples or observations
of this
StochasticTensor
. - n_samples (tf.Tensor or int) – The number of samples taken in
Distribution.sample
. If notNone
, the first dimension of tensor should be the sampling dimension. - group_ndims (int or tf.Tensor) – The number of dimensions to be considered as events group in samples. (default 0)
- is_reparameterized (bool) – Whether or not the samples are
re-parameterized? If not specified, will inherit from
tfsnippet.distributions.Distribution.is_reparameterized
. - log_prob (tf.Tensor or None) – Pre-computed log-density of tensor, given group_ndims.
- distribution (tfsnippet.distributions.Distribution) – The
distribution of this
-
distribution
¶ Get the
Distribution
of thisStochasticTensor
.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
-