zhusuan.legacy¶
Special¶
-
class
Empirical(dtype, batch_shape=None, value_shape=None, group_ndims=0, is_continuous=None, **kwargs)¶ Bases:
zhusuan.distributions.base.DistributionWarning
Deprecated in 0.4, will be removed in 0.4.1.
The class of Empirical distribution. Distribution for any variables, which are sampled from an empirical distribution and have no explicit density. You can not sample from the distribution or calculate probabilities and log-probabilities. See
Distributionfor details.Parameters: - dtype – The value type of samples from the distribution.
- batch_shape – A TensorShape describing the batch_shape of the distribution.
- value_shape – A TensorShape describing the value_shape of the distribution.
- group_ndims – A 0-D int32 Tensor representing the number of
dimensions in batch_shape (counted from the end) that are grouped
into a single event, so that their probabilities are calculated
together. Default is 0, which means a single value is an event.
See
Distributionfor more detailed explanation. - is_continuous – A bool or None. Whether the distribution is continuous or not. If None, will consider it continuous only if dtype is a float type.
-
class
Implicit(samples, value_shape=None, group_ndims=0, **kwargs)¶ Bases:
zhusuan.distributions.base.DistributionWarning
Deprecated in 0.4, will be removed in 0.4.1.
The class of Implicit distribution. The distribution abstracts variables whose distribution have no explicit form. A common example of implicit variables are the generated samples from a GAN. See
Distributionfor details.Parameters: - samples – A Tensor.
- value_shape – A TensorShape describing the value_shape of the distribution.
- group_ndims – A 0-D int32 Tensor representing the number of
dimensions in batch_shape (counted from the end) that are grouped
into a single event, so that their probabilities are calculated
together. Default is 0, which means a single value is an event.
See
Distributionfor more detailed explanation.
Stochastic¶
-
class
Normal(name, mean=0.0, _sentinel=None, std=None, logstd=None, n_samples=None, group_ndims=0, is_reparameterized=True, check_numerics=False, **kwargs)¶ Bases:
zhusuan.framework.bn.StochasticTensorWarning
Deprecated in 0.4, will be removed in 0.4.1.
The class of univariate Normal StochasticTensor. See
StochasticTensorfor details.Parameters: - name – A string. The name of the StochasticTensor. Must be unique in the BayesianNet context.
- _sentinel – Used to prevent positional parameters. Internal, do not use.
- mean – A float Tensor. The mean of the Normal distribution. Should be broadcastable to match logstd.
- std – A float Tensor. The standard deviation of the Normal distribution. Should be positive and broadcastable to match mean.
- logstd – A float Tensor. The log standard deviation of the Normal distribution. Should be broadcastable to match mean.
- n_samples – A 0-D int32 Tensor or None. Number of samples generated by this StochasticTensor.
- group_ndims – A 0-D int32 Tensor representing the number of
dimensions in batch_shape (counted from the end) that are grouped
into a single event, so that their probabilities are calculated
together. Default is 0, which means a single value is an event.
See
Distributionfor more detailed explanation. - is_reparameterized – A Bool. If True, gradients on samples from this StochasticTensor are allowed to propagate into inputs, using the reparametrization trick from (Kingma, 2013).
- check_numerics – Bool. Whether to check numeric issues.
-
bn¶ The
BayesianNetwhere theStochasticTensorlives.Returns: A BayesianNetinstance.
-
cond_log_p¶ The conditional log probability of the
StochasticTensor, evaluated at its current value (given bytensor).Returns: A Tensor.
-
dist¶ - The distribution followed by the
StochasticTensor.Returns: A Distributioninstance.
-
distribution¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
The distribution followed by the
StochasticTensor.Returns: A Distributioninstance.
-
dtype¶ The sample type of the
StochasticTensor.Returns: A DTypeinstance.
-
is_observed()¶ Whether the
StochasticTensoris observed or not.Returns: A bool.
-
log_prob(given)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Compute the log probability density (mass) function of the underlying distribution at the given value.
Parameters: given – A Tensor. Returns: A Tensor. The log probability value.
-
name¶ The name of the
StochasticTensor.Returns: A string.
-
net¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
The
BayesianNetwhere theStochasticTensorlives.Returns: A BayesianNetinstance.
-
prob(given)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Compute the probability density (mass) function of the underlying distribution at the given value.
Parameters: given – A Tensor. Returns: A Tensor. The probability value.
-
sample(n_samples)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Sample from the underlying distribution.
Parameters: n_samples – A 0-D int32 Tensor. The number of samples. Returns: A Tensor.
-
shape¶ Return the static shape of this
StochasticTensor.Returns: A TensorShapeinstance.
-
tensor¶ The value of this
StochasticTensor. If it is observed, then the observation is returned, otherwise samples are returned.Returns: A Tensor.
-
class
FoldNormal(name, mean=0.0, _sentinel=None, std=None, logstd=None, n_samples=None, group_ndims=0, is_reparameterized=True, check_numerics=False, **kwargs)¶ Bases:
zhusuan.framework.bn.StochasticTensorWarning
Deprecated in 0.4, will be removed in 0.4.1.
The class of univariate FoldNormal StochasticTensor. See
StochasticTensorfor details.Parameters: - name – A string. The name of the StochasticTensor. Must be unique in the BayesianNet context.
- mean – A float Tensor. The mean of the FoldNormal distribution. Should be broadcastable to match std or logstd.
- _sentinel – Used to prevent positional parameters. Internal, do not use.
- std – A float Tensor. The standard deviation of the FoldNormal distribution. Should be positive and broadcastable to match mean.
- logstd – A float Tensor. The log standard deviation of the FoldNormal distribution. Should be broadcastable to match mean.
- n_samples – A 0-D int32 Tensor or None. Number of samples generated by this StochasticTensor.
- group_ndims – A 0-D int32 Tensor representing the number of
dimensions in batch_shape (counted from the end) that are grouped
into a single event, so that their probabilities are calculated
together. Default is 0, which means a single value is an event.
See
Distributionfor more detailed explanation. - is_reparameterized – A Bool. If True, gradients on samples from this StochasticTensor are allowed to propagate into inputs, using the reparametrization trick from (Kingma, 2013).
- check_numerics – Bool. Whether to check numeric issues.
-
bn¶ The
BayesianNetwhere theStochasticTensorlives.Returns: A BayesianNetinstance.
-
cond_log_p¶ The conditional log probability of the
StochasticTensor, evaluated at its current value (given bytensor).Returns: A Tensor.
-
dist¶ - The distribution followed by the
StochasticTensor.Returns: A Distributioninstance.
-
distribution¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
The distribution followed by the
StochasticTensor.Returns: A Distributioninstance.
-
dtype¶ The sample type of the
StochasticTensor.Returns: A DTypeinstance.
-
is_observed()¶ Whether the
StochasticTensoris observed or not.Returns: A bool.
-
log_prob(given)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Compute the log probability density (mass) function of the underlying distribution at the given value.
Parameters: given – A Tensor. Returns: A Tensor. The log probability value.
-
name¶ The name of the
StochasticTensor.Returns: A string.
-
net¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
The
BayesianNetwhere theStochasticTensorlives.Returns: A BayesianNetinstance.
-
prob(given)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Compute the probability density (mass) function of the underlying distribution at the given value.
Parameters: given – A Tensor. Returns: A Tensor. The probability value.
-
sample(n_samples)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Sample from the underlying distribution.
Parameters: n_samples – A 0-D int32 Tensor. The number of samples. Returns: A Tensor.
-
shape¶ Return the static shape of this
StochasticTensor.Returns: A TensorShapeinstance.
-
tensor¶ The value of this
StochasticTensor. If it is observed, then the observation is returned, otherwise samples are returned.Returns: A Tensor.
-
class
Bernoulli(name, logits, n_samples=None, group_ndims=0, dtype=tf.int32, **kwargs)¶ Bases:
zhusuan.framework.bn.StochasticTensorWarning
Deprecated in 0.4, will be removed in 0.4.1.
The class of univariate Bernoulli StochasticTensor. See
StochasticTensorfor details.Parameters: - name – A string. The name of the StochasticTensor. Must be unique in the BayesianNet context.
- logits –
A float Tensor. The log-odds of probabilities of being 1.
\[\mathrm{logits} = \log \frac{p}{1 - p}\] - n_samples – A 0-D int32 Tensor or None. Number of samples generated by this StochasticTensor.
- group_ndims – A 0-D int32 Tensor representing the number of
dimensions in batch_shape (counted from the end) that are grouped
into a single event, so that their probabilities are calculated
together. Default is 0, which means a single value is an event.
See
Distributionfor more detailed explanation. - dtype – The value type of this StochasticTensor. Can be int (tf.int16, tf.int32, tf.int64) or float (tf.float16, tf.float32, tf.float64). Default is int32.
-
bn¶ The
BayesianNetwhere theStochasticTensorlives.Returns: A BayesianNetinstance.
-
cond_log_p¶ The conditional log probability of the
StochasticTensor, evaluated at its current value (given bytensor).Returns: A Tensor.
-
dist¶ - The distribution followed by the
StochasticTensor.Returns: A Distributioninstance.
-
distribution¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
The distribution followed by the
StochasticTensor.Returns: A Distributioninstance.
-
dtype¶ The sample type of the
StochasticTensor.Returns: A DTypeinstance.
-
is_observed()¶ Whether the
StochasticTensoris observed or not.Returns: A bool.
-
log_prob(given)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Compute the log probability density (mass) function of the underlying distribution at the given value.
Parameters: given – A Tensor. Returns: A Tensor. The log probability value.
-
name¶ The name of the
StochasticTensor.Returns: A string.
-
net¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
The
BayesianNetwhere theStochasticTensorlives.Returns: A BayesianNetinstance.
-
prob(given)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Compute the probability density (mass) function of the underlying distribution at the given value.
Parameters: given – A Tensor. Returns: A Tensor. The probability value.
-
sample(n_samples)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Sample from the underlying distribution.
Parameters: n_samples – A 0-D int32 Tensor. The number of samples. Returns: A Tensor.
-
shape¶ Return the static shape of this
StochasticTensor.Returns: A TensorShapeinstance.
-
tensor¶ The value of this
StochasticTensor. If it is observed, then the observation is returned, otherwise samples are returned.Returns: A Tensor.
-
class
Categorical(name, logits, n_samples=None, group_ndims=0, dtype=tf.int32, **kwargs)¶ Bases:
zhusuan.framework.bn.StochasticTensorWarning
Deprecated in 0.4, will be removed in 0.4.1.
The class of univariate Categorical StochasticTensor. See
StochasticTensorfor details.Parameters: - name – A string. The name of the StochasticTensor. Must be unique in the BayesianNet context.
- logits –
A N-D (N >= 1) float Tensor of shape (…, n_categories). Each slice [i, j,…, k, :] represents the un-normalized log probabilities for all categories.
\[\mathrm{logits} \propto \log p\] - n_samples – A 0-D int32 Tensor or None. Number of samples generated by this StochasticTensor.
- group_ndims – A 0-D int32 Tensor representing the number of
dimensions in batch_shape (counted from the end) that are grouped
into a single event, so that their probabilities are calculated
together. Default is 0, which means a single value is an event.
See
Distributionfor more detailed explanation. - dtype – The value type of this StochasticTensor. Can be float32, float64, int32, or int64. Default is int32.
A single sample is a (N-1)-D Tensor with tf.int32 values in range [0, n_categories).
-
bn¶ The
BayesianNetwhere theStochasticTensorlives.Returns: A BayesianNetinstance.
-
cond_log_p¶ The conditional log probability of the
StochasticTensor, evaluated at its current value (given bytensor).Returns: A Tensor.
-
dist¶ - The distribution followed by the
StochasticTensor.Returns: A Distributioninstance.
-
distribution¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
The distribution followed by the
StochasticTensor.Returns: A Distributioninstance.
-
dtype¶ The sample type of the
StochasticTensor.Returns: A DTypeinstance.
-
is_observed()¶ Whether the
StochasticTensoris observed or not.Returns: A bool.
-
log_prob(given)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Compute the log probability density (mass) function of the underlying distribution at the given value.
Parameters: given – A Tensor. Returns: A Tensor. The log probability value.
-
name¶ The name of the
StochasticTensor.Returns: A string.
-
net¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
The
BayesianNetwhere theStochasticTensorlives.Returns: A BayesianNetinstance.
-
prob(given)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Compute the probability density (mass) function of the underlying distribution at the given value.
Parameters: given – A Tensor. Returns: A Tensor. The probability value.
-
sample(n_samples)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Sample from the underlying distribution.
Parameters: n_samples – A 0-D int32 Tensor. The number of samples. Returns: A Tensor.
-
shape¶ Return the static shape of this
StochasticTensor.Returns: A TensorShapeinstance.
-
tensor¶ The value of this
StochasticTensor. If it is observed, then the observation is returned, otherwise samples are returned.Returns: A Tensor.
-
class
OnehotCategorical(name, logits, n_samples=None, group_ndims=0, dtype=tf.int32, **kwargs)¶ Bases:
zhusuan.framework.bn.StochasticTensorWarning
Deprecated in 0.4, will be removed in 0.4.1.
The class of one-hot Categorical StochasticTensor. See
StochasticTensorfor details.Parameters: - name – A string. The name of the StochasticTensor. Must be unique in the BayesianNet context.
- logits –
A N-D (N >= 1) float Tensor of shape (…, n_categories). Each slice [i, j, …, k, :] represents the un-normalized log probabilities for all categories.
\[\mathrm{logits} \propto \log p\] - n_samples – A 0-D int32 Tensor or None. Number of samples generated by this StochasticTensor.
- group_ndims – A 0-D int32 Tensor representing the number of
dimensions in batch_shape (counted from the end) that are grouped
into a single event, so that their probabilities are calculated
together. Default is 0, which means a single value is an event.
See
Distributionfor more detailed explanation. - dtype – The value type of this StochasticTensor. Can be int (tf.int16, tf.int32, tf.int64) or float (tf.float16, tf.float32, tf.float64). Default is int32.
A single sample is a N-D Tensor with the same shape as logits. Each slice [i, j, …, k, :] is a one-hot vector of the selected category.
-
bn¶ The
BayesianNetwhere theStochasticTensorlives.Returns: A BayesianNetinstance.
-
cond_log_p¶ The conditional log probability of the
StochasticTensor, evaluated at its current value (given bytensor).Returns: A Tensor.
-
dist¶ - The distribution followed by the
StochasticTensor.Returns: A Distributioninstance.
-
distribution¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
The distribution followed by the
StochasticTensor.Returns: A Distributioninstance.
-
dtype¶ The sample type of the
StochasticTensor.Returns: A DTypeinstance.
-
is_observed()¶ Whether the
StochasticTensoris observed or not.Returns: A bool.
-
log_prob(given)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Compute the log probability density (mass) function of the underlying distribution at the given value.
Parameters: given – A Tensor. Returns: A Tensor. The log probability value.
-
name¶ The name of the
StochasticTensor.Returns: A string.
-
net¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
The
BayesianNetwhere theStochasticTensorlives.Returns: A BayesianNetinstance.
-
prob(given)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Compute the probability density (mass) function of the underlying distribution at the given value.
Parameters: given – A Tensor. Returns: A Tensor. The probability value.
-
sample(n_samples)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Sample from the underlying distribution.
Parameters: n_samples – A 0-D int32 Tensor. The number of samples. Returns: A Tensor.
-
shape¶ Return the static shape of this
StochasticTensor.Returns: A TensorShapeinstance.
-
tensor¶ The value of this
StochasticTensor. If it is observed, then the observation is returned, otherwise samples are returned.Returns: A Tensor.
-
Discrete¶
-
OnehotDiscrete¶ alias of
zhusuan.legacy.framework.stochastic.OnehotCategorical
-
class
Uniform(name, minval=0.0, maxval=1.0, n_samples=None, group_ndims=0, is_reparameterized=True, check_numerics=False, **kwargs)¶ Bases:
zhusuan.framework.bn.StochasticTensorWarning
Deprecated in 0.4, will be removed in 0.4.1.
The class of univariate Uniform StochasticTensor. See
StochasticTensorfor details.Parameters: - name – A string. The name of the StochasticTensor. Must be unique in the BayesianNet context.
- minval – A float Tensor. The lower bound on the range of the uniform distribution. Should be broadcastable to match maxval.
- maxval – A float Tensor. The upper bound on the range of the uniform distribution. Should be element-wise bigger than minval.
- n_samples – A 0-D int32 Tensor or None. Number of samples generated by this StochasticTensor.
- group_ndims – A 0-D int32 Tensor representing the number of
dimensions in batch_shape (counted from the end) that are grouped
into a single event, so that their probabilities are calculated
together. Default is 0, which means a single value is an event.
See
Distributionfor more detailed explanation. - is_reparameterized – A Bool. If True, gradients on samples from this StochasticTensor are allowed to propagate into inputs, using the reparametrization trick from (Kingma, 2013).
- check_numerics – Bool. Whether to check numeric issues.
-
bn¶ The
BayesianNetwhere theStochasticTensorlives.Returns: A BayesianNetinstance.
-
cond_log_p¶ The conditional log probability of the
StochasticTensor, evaluated at its current value (given bytensor).Returns: A Tensor.
-
dist¶ - The distribution followed by the
StochasticTensor.Returns: A Distributioninstance.
-
distribution¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
The distribution followed by the
StochasticTensor.Returns: A Distributioninstance.
-
dtype¶ The sample type of the
StochasticTensor.Returns: A DTypeinstance.
-
is_observed()¶ Whether the
StochasticTensoris observed or not.Returns: A bool.
-
log_prob(given)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Compute the log probability density (mass) function of the underlying distribution at the given value.
Parameters: given – A Tensor. Returns: A Tensor. The log probability value.
-
name¶ The name of the
StochasticTensor.Returns: A string.
-
net¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
The
BayesianNetwhere theStochasticTensorlives.Returns: A BayesianNetinstance.
-
prob(given)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Compute the probability density (mass) function of the underlying distribution at the given value.
Parameters: given – A Tensor. Returns: A Tensor. The probability value.
-
sample(n_samples)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Sample from the underlying distribution.
Parameters: n_samples – A 0-D int32 Tensor. The number of samples. Returns: A Tensor.
-
shape¶ Return the static shape of this
StochasticTensor.Returns: A TensorShapeinstance.
-
tensor¶ The value of this
StochasticTensor. If it is observed, then the observation is returned, otherwise samples are returned.Returns: A Tensor.
-
class
Gamma(name, alpha, beta, n_samples=None, group_ndims=0, check_numerics=False, **kwargs)¶ Bases:
zhusuan.framework.bn.StochasticTensorWarning
Deprecated in 0.4, will be removed in 0.4.1.
The class of univariate Gamma StochasticTensor. See
StochasticTensorfor details.Parameters: - name – A string. The name of the StochasticTensor. Must be unique in the BayesianNet context.
- alpha – A float Tensor. The shape parameter of the Gamma distribution. Should be positive and broadcastable to match beta.
- beta – A float Tensor. The inverse scale parameter of the Gamma distribution. Should be positive and broadcastable to match alpha.
- n_samples – A 0-D int32 Tensor or None. Number of samples generated by this StochasticTensor.
- group_ndims – A 0-D int32 Tensor representing the number of
dimensions in batch_shape (counted from the end) that are grouped
into a single event, so that their probabilities are calculated
together. Default is 0, which means a single value is an event.
See
Distributionfor more detailed explanation. - check_numerics – Bool. Whether to check numeric issues.
-
bn¶ The
BayesianNetwhere theStochasticTensorlives.Returns: A BayesianNetinstance.
-
cond_log_p¶ The conditional log probability of the
StochasticTensor, evaluated at its current value (given bytensor).Returns: A Tensor.
-
dist¶ - The distribution followed by the
StochasticTensor.Returns: A Distributioninstance.
-
distribution¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
The distribution followed by the
StochasticTensor.Returns: A Distributioninstance.
-
dtype¶ The sample type of the
StochasticTensor.Returns: A DTypeinstance.
-
is_observed()¶ Whether the
StochasticTensoris observed or not.Returns: A bool.
-
log_prob(given)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Compute the log probability density (mass) function of the underlying distribution at the given value.
Parameters: given – A Tensor. Returns: A Tensor. The log probability value.
-
name¶ The name of the
StochasticTensor.Returns: A string.
-
net¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
The
BayesianNetwhere theStochasticTensorlives.Returns: A BayesianNetinstance.
-
prob(given)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Compute the probability density (mass) function of the underlying distribution at the given value.
Parameters: given – A Tensor. Returns: A Tensor. The probability value.
-
sample(n_samples)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Sample from the underlying distribution.
Parameters: n_samples – A 0-D int32 Tensor. The number of samples. Returns: A Tensor.
-
shape¶ Return the static shape of this
StochasticTensor.Returns: A TensorShapeinstance.
-
tensor¶ The value of this
StochasticTensor. If it is observed, then the observation is returned, otherwise samples are returned.Returns: A Tensor.
-
class
Beta(name, alpha, beta, n_samples=None, group_ndims=0, check_numerics=False, **kwargs)¶ Bases:
zhusuan.framework.bn.StochasticTensorWarning
Deprecated in 0.4, will be removed in 0.4.1.
The class of univariate Beta StochasticTensor. See
StochasticTensorfor details.Parameters: - name – A string. The name of the StochasticTensor. Must be unique in the BayesianNet context.
- alpha – A float Tensor. One of the two shape parameters of the Beta distribution. Should be positive and broadcastable to match beta.
- beta – A float Tensor. One of the two shape parameters of the Beta distribution. Should be positive and broadcastable to match alpha.
- n_samples – A 0-D int32 Tensor or None. Number of samples generated by this StochasticTensor.
- group_ndims – A 0-D int32 Tensor representing the number of
dimensions in batch_shape (counted from the end) that are grouped
into a single event, so that their probabilities are calculated
together. Default is 0, which means a single value is an event.
See
Distributionfor more detailed explanation. - check_numerics – Bool. Whether to check numeric issues.
-
bn¶ The
BayesianNetwhere theStochasticTensorlives.Returns: A BayesianNetinstance.
-
cond_log_p¶ The conditional log probability of the
StochasticTensor, evaluated at its current value (given bytensor).Returns: A Tensor.
-
dist¶ - The distribution followed by the
StochasticTensor.Returns: A Distributioninstance.
-
distribution¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
The distribution followed by the
StochasticTensor.Returns: A Distributioninstance.
-
dtype¶ The sample type of the
StochasticTensor.Returns: A DTypeinstance.
-
is_observed()¶ Whether the
StochasticTensoris observed or not.Returns: A bool.
-
log_prob(given)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Compute the log probability density (mass) function of the underlying distribution at the given value.
Parameters: given – A Tensor. Returns: A Tensor. The log probability value.
-
name¶ The name of the
StochasticTensor.Returns: A string.
-
net¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
The
BayesianNetwhere theStochasticTensorlives.Returns: A BayesianNetinstance.
-
prob(given)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Compute the probability density (mass) function of the underlying distribution at the given value.
Parameters: given – A Tensor. Returns: A Tensor. The probability value.
-
sample(n_samples)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Sample from the underlying distribution.
Parameters: n_samples – A 0-D int32 Tensor. The number of samples. Returns: A Tensor.
-
shape¶ Return the static shape of this
StochasticTensor.Returns: A TensorShapeinstance.
-
tensor¶ The value of this
StochasticTensor. If it is observed, then the observation is returned, otherwise samples are returned.Returns: A Tensor.
-
class
Poisson(name, rate, n_samples=None, group_ndims=0, dtype=tf.int32, check_numerics=False, **kwargs)¶ Bases:
zhusuan.framework.bn.StochasticTensorWarning
Deprecated in 0.4, will be removed in 0.4.1.
The class of univariate Poisson StochasticTensor. See
StochasticTensorfor details.Parameters: - name – A string. The name of the StochasticTensor. Must be unique in the BayesianNet context.
- rate – A float Tensor. The rate parameter of Poisson distribution. Must be positive.
- n_samples – A 0-D int32 Tensor or None. Number of samples generated by this StochasticTensor.
- group_ndims – A 0-D int32 Tensor representing the number of
dimensions in batch_shape (counted from the end) that are grouped
into a single event, so that their probabilities are calculated
together. Default is 0, which means a single value is an event.
See
Distributionfor more detailed explanation. - dtype – The value type of this StochasticTensor. Can be int (tf.int16, tf.int32, tf.int64) or float (tf.float16, tf.float32, tf.float64). Default is int32.
- check_numerics – Bool. Whether to check numeric issues.
-
bn¶ The
BayesianNetwhere theStochasticTensorlives.Returns: A BayesianNetinstance.
-
cond_log_p¶ The conditional log probability of the
StochasticTensor, evaluated at its current value (given bytensor).Returns: A Tensor.
-
dist¶ - The distribution followed by the
StochasticTensor.Returns: A Distributioninstance.
-
distribution¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
The distribution followed by the
StochasticTensor.Returns: A Distributioninstance.
-
dtype¶ The sample type of the
StochasticTensor.Returns: A DTypeinstance.
-
is_observed()¶ Whether the
StochasticTensoris observed or not.Returns: A bool.
-
log_prob(given)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Compute the log probability density (mass) function of the underlying distribution at the given value.
Parameters: given – A Tensor. Returns: A Tensor. The log probability value.
-
name¶ The name of the
StochasticTensor.Returns: A string.
-
net¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
The
BayesianNetwhere theStochasticTensorlives.Returns: A BayesianNetinstance.
-
prob(given)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Compute the probability density (mass) function of the underlying distribution at the given value.
Parameters: given – A Tensor. Returns: A Tensor. The probability value.
-
sample(n_samples)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Sample from the underlying distribution.
Parameters: n_samples – A 0-D int32 Tensor. The number of samples. Returns: A Tensor.
-
shape¶ Return the static shape of this
StochasticTensor.Returns: A TensorShapeinstance.
-
tensor¶ The value of this
StochasticTensor. If it is observed, then the observation is returned, otherwise samples are returned.Returns: A Tensor.
-
class
Binomial(name, logits, n_experiments, n_samples=None, group_ndims=0, dtype=tf.int32, check_numerics=False, **kwargs)¶ Bases:
zhusuan.framework.bn.StochasticTensorWarning
Deprecated in 0.4, will be removed in 0.4.1.
The class of univariate Binomial StochasticTensor. See
StochasticTensorfor details.Parameters: - name – A string. The name of the StochasticTensor. Must be unique in the BayesianNet context.
- logits –
A float Tensor. The log-odds of probabilities.
\[\mathrm{logits} = \log \frac{p}{1 - p}\] - n_experiments – A 0-D int32 Tensor. The number of experiments for each sample.
- n_samples – A 0-D int32 Tensor or None. Number of samples generated by this StochasticTensor.
- group_ndims – A 0-D int32 Tensor representing the number of
dimensions in batch_shape (counted from the end) that are grouped
into a single event, so that their probabilities are calculated
together. Default is 0, which means a single value is an event.
See
Distributionfor more detailed explanation. - dtype – The value type of this StochasticTensor. Can be int (tf.int16, tf.int32, tf.int64) or float (tf.float16, tf.float32, tf.float64). Default is int32.
- check_numerics – Bool. Whether to check numeric issues.
-
bn¶ The
BayesianNetwhere theStochasticTensorlives.Returns: A BayesianNetinstance.
-
cond_log_p¶ The conditional log probability of the
StochasticTensor, evaluated at its current value (given bytensor).Returns: A Tensor.
-
dist¶ - The distribution followed by the
StochasticTensor.Returns: A Distributioninstance.
-
distribution¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
The distribution followed by the
StochasticTensor.Returns: A Distributioninstance.
-
dtype¶ The sample type of the
StochasticTensor.Returns: A DTypeinstance.
-
is_observed()¶ Whether the
StochasticTensoris observed or not.Returns: A bool.
-
log_prob(given)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Compute the log probability density (mass) function of the underlying distribution at the given value.
Parameters: given – A Tensor. Returns: A Tensor. The log probability value.
-
name¶ The name of the
StochasticTensor.Returns: A string.
-
net¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
The
BayesianNetwhere theStochasticTensorlives.Returns: A BayesianNetinstance.
-
prob(given)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Compute the probability density (mass) function of the underlying distribution at the given value.
Parameters: given – A Tensor. Returns: A Tensor. The probability value.
-
sample(n_samples)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Sample from the underlying distribution.
Parameters: n_samples – A 0-D int32 Tensor. The number of samples. Returns: A Tensor.
-
shape¶ Return the static shape of this
StochasticTensor.Returns: A TensorShapeinstance.
-
tensor¶ The value of this
StochasticTensor. If it is observed, then the observation is returned, otherwise samples are returned.Returns: A Tensor.
-
class
InverseGamma(name, alpha, beta, n_samples=None, group_ndims=0, check_numerics=False, **kwargs)¶ Bases:
zhusuan.framework.bn.StochasticTensorWarning
Deprecated in 0.4, will be removed in 0.4.1.
The class of univariate InverseGamma StochasticTensor. See
StochasticTensorfor details.Parameters: - name – A string. The name of the StochasticTensor. Must be unique in the BayesianNet context.
- alpha – A float Tensor. The shape parameter of the InverseGamma distribution. Should be positive and broadcastable to match beta.
- beta – A float Tensor. The scale parameter of the InverseGamma distribution. Should be positive and broadcastable to match alpha.
- n_samples – A 0-D int32 Tensor or None. Number of samples generated by this StochasticTensor.
- group_ndims – A 0-D int32 Tensor representing the number of
dimensions in batch_shape (counted from the end) that are grouped
into a single event, so that their probabilities are calculated
together. Default is 0, which means a single value is an event.
See
Distributionfor more detailed explanation. - check_numerics – Bool. Whether to check numeric issues.
-
bn¶ The
BayesianNetwhere theStochasticTensorlives.Returns: A BayesianNetinstance.
-
cond_log_p¶ The conditional log probability of the
StochasticTensor, evaluated at its current value (given bytensor).Returns: A Tensor.
-
dist¶ - The distribution followed by the
StochasticTensor.Returns: A Distributioninstance.
-
distribution¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
The distribution followed by the
StochasticTensor.Returns: A Distributioninstance.
-
dtype¶ The sample type of the
StochasticTensor.Returns: A DTypeinstance.
-
is_observed()¶ Whether the
StochasticTensoris observed or not.Returns: A bool.
-
log_prob(given)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Compute the log probability density (mass) function of the underlying distribution at the given value.
Parameters: given – A Tensor. Returns: A Tensor. The log probability value.
-
name¶ The name of the
StochasticTensor.Returns: A string.
-
net¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
The
BayesianNetwhere theStochasticTensorlives.Returns: A BayesianNetinstance.
-
prob(given)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Compute the probability density (mass) function of the underlying distribution at the given value.
Parameters: given – A Tensor. Returns: A Tensor. The probability value.
-
sample(n_samples)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Sample from the underlying distribution.
Parameters: n_samples – A 0-D int32 Tensor. The number of samples. Returns: A Tensor.
-
shape¶ Return the static shape of this
StochasticTensor.Returns: A TensorShapeinstance.
-
tensor¶ The value of this
StochasticTensor. If it is observed, then the observation is returned, otherwise samples are returned.Returns: A Tensor.
-
class
Laplace(name, loc, scale, n_samples=None, group_ndims=0, is_reparameterized=True, check_numerics=False, **kwargs)¶ Bases:
zhusuan.framework.bn.StochasticTensorWarning
Deprecated in 0.4, will be removed in 0.4.1.
The class of univariate Laplace StochasticTensor. See
StochasticTensorfor details.Parameters: - name – A string. The name of the StochasticTensor. Must be unique in the BayesianNet context.
- loc – A float Tensor. The location parameter of the Laplace distribution. Should be broadcastable to match scale.
- scale – A float Tensor. The scale parameter of the Laplace distribution. Should be positive and broadcastable to match loc.
- n_samples – A 0-D int32 Tensor or None. Number of samples generated by this StochasticTensor.
- group_ndims – A 0-D int32 Tensor representing the number of
dimensions in batch_shape (counted from the end) that are grouped
into a single event, so that their probabilities are calculated
together. Default is 0, which means a single value is an event.
See
Distributionfor more detailed explanation. - is_reparameterized – A Bool. If True, gradients on samples from this StochasticTensor are allowed to propagate into inputs, using the reparametrization trick from (Kingma, 2013).
- check_numerics – Bool. Whether to check numeric issues.
-
bn¶ The
BayesianNetwhere theStochasticTensorlives.Returns: A BayesianNetinstance.
-
cond_log_p¶ The conditional log probability of the
StochasticTensor, evaluated at its current value (given bytensor).Returns: A Tensor.
-
dist¶ - The distribution followed by the
StochasticTensor.Returns: A Distributioninstance.
-
distribution¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
The distribution followed by the
StochasticTensor.Returns: A Distributioninstance.
-
dtype¶ The sample type of the
StochasticTensor.Returns: A DTypeinstance.
-
is_observed()¶ Whether the
StochasticTensoris observed or not.Returns: A bool.
-
log_prob(given)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Compute the log probability density (mass) function of the underlying distribution at the given value.
Parameters: given – A Tensor. Returns: A Tensor. The log probability value.
-
name¶ The name of the
StochasticTensor.Returns: A string.
-
net¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
The
BayesianNetwhere theStochasticTensorlives.Returns: A BayesianNetinstance.
-
prob(given)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Compute the probability density (mass) function of the underlying distribution at the given value.
Parameters: given – A Tensor. Returns: A Tensor. The probability value.
-
sample(n_samples)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Sample from the underlying distribution.
Parameters: n_samples – A 0-D int32 Tensor. The number of samples. Returns: A Tensor.
-
shape¶ Return the static shape of this
StochasticTensor.Returns: A TensorShapeinstance.
-
tensor¶ The value of this
StochasticTensor. If it is observed, then the observation is returned, otherwise samples are returned.Returns: A Tensor.
-
class
MultivariateNormalCholesky(name, mean, cov_tril, n_samples=None, group_ndims=0, is_reparameterized=True, check_numerics=False, **kwargs)¶ Bases:
zhusuan.framework.bn.StochasticTensorWarning
Deprecated in 0.4, will be removed in 0.4.1.
The class of multivariate normal StochasticTensor, where covariance is parameterized with the lower triangular matrix \(L\) in Cholesky decomposition \(LL^T = \Sigma\).
See
StochasticTensorfor details.Parameters: - name – A string. The name of the StochasticTensor. Must be unique in the BayesianNet context.
- mean – An N-D float Tensor of shape […, n_dim]. Each slice [i, j, …, k, :] represents the mean of a single multivariate normal distribution.
- cov_tril – An (N+1)-D float Tensor of shape […, n_dim, n_dim]. Each slice [i, …, k, :, :] represents the lower triangular matrix in the Cholesky decomposition of the covariance of a single distribution.
- n_samples – A 0-D int32 Tensor or None. Number of samples generated by this StochasticTensor.
- group_ndims – A 0-D int32 Tensor representing the number of
dimensions in batch_shape (counted from the end) that are grouped
into a single event, so that their probabilities are calculated
together. Default is 0, which means a single value is an event.
See
Distributionfor more detailed explanation. - is_reparameterized – A Bool. If True, gradients on samples from this distribution are allowed to propagate into inputs, using the reparametrization trick from (Kingma, 2013).
- check_numerics – Bool. Whether to check numeric issues.
-
bn¶ The
BayesianNetwhere theStochasticTensorlives.Returns: A BayesianNetinstance.
-
cond_log_p¶ The conditional log probability of the
StochasticTensor, evaluated at its current value (given bytensor).Returns: A Tensor.
-
dist¶ - The distribution followed by the
StochasticTensor.Returns: A Distributioninstance.
-
distribution¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
The distribution followed by the
StochasticTensor.Returns: A Distributioninstance.
-
dtype¶ The sample type of the
StochasticTensor.Returns: A DTypeinstance.
-
is_observed()¶ Whether the
StochasticTensoris observed or not.Returns: A bool.
-
log_prob(given)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Compute the log probability density (mass) function of the underlying distribution at the given value.
Parameters: given – A Tensor. Returns: A Tensor. The log probability value.
-
name¶ The name of the
StochasticTensor.Returns: A string.
-
net¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
The
BayesianNetwhere theStochasticTensorlives.Returns: A BayesianNetinstance.
-
prob(given)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Compute the probability density (mass) function of the underlying distribution at the given value.
Parameters: given – A Tensor. Returns: A Tensor. The probability value.
-
sample(n_samples)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Sample from the underlying distribution.
Parameters: n_samples – A 0-D int32 Tensor. The number of samples. Returns: A Tensor.
-
shape¶ Return the static shape of this
StochasticTensor.Returns: A TensorShapeinstance.
-
tensor¶ The value of this
StochasticTensor. If it is observed, then the observation is returned, otherwise samples are returned.Returns: A Tensor.
-
class
MatrixVariateNormalCholesky(name, mean, u_tril, v_tril, n_samples=None, group_ndims=0, is_reparameterized=True, check_numerics=False, **kwargs)¶ Bases:
zhusuan.framework.bn.StochasticTensorWarning
Deprecated in 0.4, will be removed in 0.4.1.
The class of matrix variate normal StochasticTensor, where covariances \(U\) and \(V\) are parameterized with the lower triangular matrix in Cholesky decomposition,
\[L_u \text{s.t.} L_u L_u^T = U,\; L_v \text{s.t.} L_v L_v^T = V\]See
StochasticTensorfor details.Parameters: - name – A string. The name of the StochasticTensor. Must be unique in the BayesianNet context.
- mean – An N-D float Tensor of shape […, n_row, n_col]. Each slice [i, j, …, k, :, :] represents the mean of a single matrix variate normal distribution.
- u_tril – An N-D float Tensor of shape […, n_row, n_row]. Each slice [i, j, …, k, :, :] represents the lower triangular matrix in the Cholesky decomposition of the among-row covariance of a single matrix variate normal distribution.
- v_tril – An N-D float Tensor of shape […, n_col, n_col]. Each slice [i, j, …, k, :, :] represents the lower triangular matrix in the Cholesky decomposition of the among-column covariance of a single matrix variate normal distribution.
- n_samples – A 0-D int32 Tensor or None. Number of samples generated by this StochasticTensor.
- group_ndims – A 0-D int32 Tensor representing the number of
dimensions in batch_shape (counted from the end) that are grouped
into a single event, so that their probabilities are calculated
together. Default is 0, which means a single value is an event.
See
Distributionfor more detailed explanation. - is_reparameterized – A Bool. If True, gradients on samples from this distribution are allowed to propagate into inputs, using the reparametrization trick from (Kingma, 2013).
- check_numerics – Bool. Whether to check numeric issues.
-
bn¶ The
BayesianNetwhere theStochasticTensorlives.Returns: A BayesianNetinstance.
-
cond_log_p¶ The conditional log probability of the
StochasticTensor, evaluated at its current value (given bytensor).Returns: A Tensor.
-
dist¶ - The distribution followed by the
StochasticTensor.Returns: A Distributioninstance.
-
distribution¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
The distribution followed by the
StochasticTensor.Returns: A Distributioninstance.
-
dtype¶ The sample type of the
StochasticTensor.Returns: A DTypeinstance.
-
is_observed()¶ Whether the
StochasticTensoris observed or not.Returns: A bool.
-
log_prob(given)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Compute the log probability density (mass) function of the underlying distribution at the given value.
Parameters: given – A Tensor. Returns: A Tensor. The log probability value.
-
name¶ The name of the
StochasticTensor.Returns: A string.
-
net¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
The
BayesianNetwhere theStochasticTensorlives.Returns: A BayesianNetinstance.
-
prob(given)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Compute the probability density (mass) function of the underlying distribution at the given value.
Parameters: given – A Tensor. Returns: A Tensor. The probability value.
-
sample(n_samples)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Sample from the underlying distribution.
Parameters: n_samples – A 0-D int32 Tensor. The number of samples. Returns: A Tensor.
-
shape¶ Return the static shape of this
StochasticTensor.Returns: A TensorShapeinstance.
-
tensor¶ The value of this
StochasticTensor. If it is observed, then the observation is returned, otherwise samples are returned.Returns: A Tensor.
-
class
Multinomial(name, logits, n_experiments, normalize_logits=True, n_samples=None, group_ndims=0, dtype=tf.int32, **kwargs)¶ Bases:
zhusuan.framework.bn.StochasticTensorWarning
Deprecated in 0.4, will be removed in 0.4.1.
The class of Multinomial StochasticTensor. See
StochasticTensorfor details.Parameters: - name – A string. The name of the StochasticTensor. Must be unique in the BayesianNet context.
- logits –
A N-D (N >= 1) float Tensor of shape […, n_categories]. Each slice [i, j, …, k, :] represents the log probabilities for all categories. By default (when normalize_logits=True), the probabilities could be un-normalized.
\[\mathrm{logits} \propto \log p\] - n_experiments – A 0-D int32 Tensor or None. When it is a 0-D int32 integer, it represents the number of experiments for each sample, which should be invariant among samples. In this situation _sample function is supported. When it is None, _sample function is not supported, and when calculating probabilities the number of experiments will be inferred from given, so it could vary among samples.
- normalize_logits – A bool indicating whether logits should be normalized when computing probability. If you believe logits is already normalized, set it to False to speed up. Default is True.
- n_samples – A 0-D int32 Tensor or None. Number of samples generated by this StochasticTensor.
- group_ndims – A 0-D int32 Tensor representing the number of
dimensions in batch_shape (counted from the end) that are grouped
into a single event, so that their probabilities are calculated
together. Default is 0, which means a single value is an event.
See
Distributionfor more detailed explanation. - dtype – The value type of this StochasticTensor. Can be int (tf.int16, tf.int32, tf.int64) or float (tf.float16, tf.float32, tf.float64). Default is int32.
A single sample is a N-D Tensor with the same shape as logits. Each slice [i, j, …, k, :] is a vector of counts for all categories.
-
bn¶ The
BayesianNetwhere theStochasticTensorlives.Returns: A BayesianNetinstance.
-
cond_log_p¶ The conditional log probability of the
StochasticTensor, evaluated at its current value (given bytensor).Returns: A Tensor.
-
dist¶ - The distribution followed by the
StochasticTensor.Returns: A Distributioninstance.
-
distribution¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
The distribution followed by the
StochasticTensor.Returns: A Distributioninstance.
-
dtype¶ The sample type of the
StochasticTensor.Returns: A DTypeinstance.
-
is_observed()¶ Whether the
StochasticTensoris observed or not.Returns: A bool.
-
log_prob(given)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Compute the log probability density (mass) function of the underlying distribution at the given value.
Parameters: given – A Tensor. Returns: A Tensor. The log probability value.
-
name¶ The name of the
StochasticTensor.Returns: A string.
-
net¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
The
BayesianNetwhere theStochasticTensorlives.Returns: A BayesianNetinstance.
-
prob(given)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Compute the probability density (mass) function of the underlying distribution at the given value.
Parameters: given – A Tensor. Returns: A Tensor. The probability value.
-
sample(n_samples)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Sample from the underlying distribution.
Parameters: n_samples – A 0-D int32 Tensor. The number of samples. Returns: A Tensor.
-
shape¶ Return the static shape of this
StochasticTensor.Returns: A TensorShapeinstance.
-
tensor¶ The value of this
StochasticTensor. If it is observed, then the observation is returned, otherwise samples are returned.Returns: A Tensor.
-
class
UnnormalizedMultinomial(name, logits, normalize_logits=True, group_ndims=0, dtype=tf.int32, **kwargs)¶ Bases:
zhusuan.framework.bn.StochasticTensorWarning
Deprecated in 0.4, will be removed in 0.4.1.
The class of UnnormalizedMultinomial StochasticTensor. UnnormalizedMultinomial distribution calculates probabilities differently from
Multinomial: It considers the bag-of-words given as a statistics of an ordered result sequence, and calculates the probability of the (imagined) ordered sequence. Hence it does not multiply the term\[\binom{n}{k_1, k_2, \dots} = \frac{n!}{\prod_{i} k_i!}\]See
StochasticTensorfor details.Parameters: - name – A string. The name of the StochasticTensor. Must be unique in the BayesianNet context.
- logits –
A N-D (N >= 1) float Tensor of shape […, n_categories]. Each slice [i, j, …, k, :] represents the log probabilities for all categories. By default (when normalize_logits=True), the probabilities could be un-normalized.
\[\mathrm{logits} \propto \log p\] - normalize_logits – A bool indicating whether logits should be normalized when computing probability. If you believe logits is already normalized, set it to False to speed up. Default is True.
- group_ndims – A 0-D int32 Tensor representing the number of
dimensions in batch_shape (counted from the end) that are grouped
into a single event, so that their probabilities are calculated
together. Default is 0, which means a single value is an event.
See
Distributionfor more detailed explanation. - dtype – The value type of this StochasticTensor. Can be int (tf.int16, tf.int32, tf.int64) or float (tf.float16, tf.float32, tf.float64). Default is int32.
A single sample is a N-D Tensor with the same shape as logits. Each slice [i, j, …, k, :] is a vector of counts for all categories.
-
bn¶ The
BayesianNetwhere theStochasticTensorlives.Returns: A BayesianNetinstance.
-
cond_log_p¶ The conditional log probability of the
StochasticTensor, evaluated at its current value (given bytensor).Returns: A Tensor.
-
dist¶ - The distribution followed by the
StochasticTensor.Returns: A Distributioninstance.
-
distribution¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
The distribution followed by the
StochasticTensor.Returns: A Distributioninstance.
-
dtype¶ The sample type of the
StochasticTensor.Returns: A DTypeinstance.
-
is_observed()¶ Whether the
StochasticTensoris observed or not.Returns: A bool.
-
log_prob(given)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Compute the log probability density (mass) function of the underlying distribution at the given value.
Parameters: given – A Tensor. Returns: A Tensor. The log probability value.
-
name¶ The name of the
StochasticTensor.Returns: A string.
-
net¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
The
BayesianNetwhere theStochasticTensorlives.Returns: A BayesianNetinstance.
-
prob(given)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Compute the probability density (mass) function of the underlying distribution at the given value.
Parameters: given – A Tensor. Returns: A Tensor. The probability value.
-
sample(n_samples)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Sample from the underlying distribution.
Parameters: n_samples – A 0-D int32 Tensor. The number of samples. Returns: A Tensor.
-
shape¶ Return the static shape of this
StochasticTensor.Returns: A TensorShapeinstance.
-
tensor¶ The value of this
StochasticTensor. If it is observed, then the observation is returned, otherwise samples are returned.Returns: A Tensor.
-
BagofCategoricals¶ alias of
zhusuan.legacy.framework.stochastic.UnnormalizedMultinomial
-
class
Dirichlet(name, alpha, n_samples=None, group_ndims=0, check_numerics=False, **kwargs)¶ Bases:
zhusuan.framework.bn.StochasticTensorWarning
Deprecated in 0.4, will be removed in 0.4.1.
The class of Dirichlet StochasticTensor. See
StochasticTensorfor details.Parameters: - name – A string. The name of the StochasticTensor. Must be unique in the BayesianNet context.
- alpha – A N-D (N >= 1) float Tensor of shape (…, n_categories). Each slice [i, j, …, k, :] represents the concentration parameter of a Dirichlet distribution. Should be positive.
- n_samples – A 0-D int32 Tensor or None. Number of samples generated by this StochasticTensor.
- group_ndims – A 0-D int32 Tensor representing the number of
dimensions in batch_shape (counted from the end) that are grouped
into a single event, so that their probabilities are calculated
together. Default is 0, which means a single value is an event.
See
Distributionfor more detailed explanation. - check_numerics – Bool. Whether to check numeric issues.
A single sample is a N-D Tensor with the same shape as alpha. Each slice [i, j, …, k, :] of the sample is a vector of probabilities of a Categorical distribution [x_1, x_2, … ], which lies on the simplex
\[\sum_{i} x_i = 1, 0 < x_i < 1\]-
bn¶ The
BayesianNetwhere theStochasticTensorlives.Returns: A BayesianNetinstance.
-
cond_log_p¶ The conditional log probability of the
StochasticTensor, evaluated at its current value (given bytensor).Returns: A Tensor.
-
dist¶ - The distribution followed by the
StochasticTensor.Returns: A Distributioninstance.
-
distribution¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
The distribution followed by the
StochasticTensor.Returns: A Distributioninstance.
-
dtype¶ The sample type of the
StochasticTensor.Returns: A DTypeinstance.
-
is_observed()¶ Whether the
StochasticTensoris observed or not.Returns: A bool.
-
log_prob(given)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Compute the log probability density (mass) function of the underlying distribution at the given value.
Parameters: given – A Tensor. Returns: A Tensor. The log probability value.
-
name¶ The name of the
StochasticTensor.Returns: A string.
-
net¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
The
BayesianNetwhere theStochasticTensorlives.Returns: A BayesianNetinstance.
-
prob(given)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Compute the probability density (mass) function of the underlying distribution at the given value.
Parameters: given – A Tensor. Returns: A Tensor. The probability value.
-
sample(n_samples)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Sample from the underlying distribution.
Parameters: n_samples – A 0-D int32 Tensor. The number of samples. Returns: A Tensor.
-
shape¶ Return the static shape of this
StochasticTensor.Returns: A TensorShapeinstance.
-
tensor¶ The value of this
StochasticTensor. If it is observed, then the observation is returned, otherwise samples are returned.Returns: A Tensor.
-
class
BinConcrete(name, temperature, logits, n_samples=None, group_ndims=0, is_reparameterized=True, check_numerics=False, **kwargs)¶ Bases:
zhusuan.framework.bn.StochasticTensorWarning
Deprecated in 0.4, will be removed in 0.4.1.
The class of univariate BinConcrete StochasticTensor from (Maddison, 2016). It is the binary case of
Concrete. SeeStochasticTensorfor details.See also
ConcreteandExpConcreteParameters: - name – A string. The name of the StochasticTensor. Must be unique in the BayesianNet context.
- temperature – A 0-D float Tensor. The temperature of the relaxed distribution. The temperature should be positive.
- logits –
A float Tensor. The log-odds of probabilities of being 1.
\[\mathrm{logits} = \log \frac{p}{1 - p}\] - n_samples – A 0-D int32 Tensor or None. Number of samples generated by this StochasticTensor.
- group_ndims – A 0-D int32 Tensor representing the number of
dimensions in batch_shape (counted from the end) that are grouped
into a single event, so that their probabilities are calculated
together. Default is 0, which means a single value is an event.
See
Distributionfor more detailed explanation. - is_reparameterized – A Bool. If True, gradients on samples from this StochasticTensor are allowed to propagate into inputs, using the reparametrization trick from (Kingma, 2013).
- check_numerics – Bool. Whether to check numeric issues.
-
bn¶ The
BayesianNetwhere theStochasticTensorlives.Returns: A BayesianNetinstance.
-
cond_log_p¶ The conditional log probability of the
StochasticTensor, evaluated at its current value (given bytensor).Returns: A Tensor.
-
dist¶ - The distribution followed by the
StochasticTensor.Returns: A Distributioninstance.
-
distribution¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
The distribution followed by the
StochasticTensor.Returns: A Distributioninstance.
-
dtype¶ The sample type of the
StochasticTensor.Returns: A DTypeinstance.
-
is_observed()¶ Whether the
StochasticTensoris observed or not.Returns: A bool.
-
log_prob(given)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Compute the log probability density (mass) function of the underlying distribution at the given value.
Parameters: given – A Tensor. Returns: A Tensor. The log probability value.
-
name¶ The name of the
StochasticTensor.Returns: A string.
-
net¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
The
BayesianNetwhere theStochasticTensorlives.Returns: A BayesianNetinstance.
-
prob(given)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Compute the probability density (mass) function of the underlying distribution at the given value.
Parameters: given – A Tensor. Returns: A Tensor. The probability value.
-
sample(n_samples)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Sample from the underlying distribution.
Parameters: n_samples – A 0-D int32 Tensor. The number of samples. Returns: A Tensor.
-
shape¶ Return the static shape of this
StochasticTensor.Returns: A TensorShapeinstance.
-
tensor¶ The value of this
StochasticTensor. If it is observed, then the observation is returned, otherwise samples are returned.Returns: A Tensor.
-
BinGumbelSoftmax¶
-
class
ExpConcrete(name, temperature, logits, n_samples=None, group_ndims=0, is_reparameterized=True, check_numerics=False, **kwargs)¶ Bases:
zhusuan.framework.bn.StochasticTensorWarning
Deprecated in 0.4, will be removed in 0.4.1.
The class of ExpConcrete StochasticTensor from (Maddison, 2016), transformed from
Concreteby taking logarithm. SeeStochasticTensorfor details.See also
BinConcreteandConcreteParameters: - temperature – A 0-D float Tensor. The temperature of the relaxed distribution. The temperature should be positive.
- logits –
A N-D (N >= 1) float Tensor of shape (…, n_categories). Each slice [i, j, …, k, :] represents the un-normalized log probabilities for all categories.
\[\mathrm{logits} \propto \log p\] - n_samples – A 0-D int32 Tensor or None. Number of samples generated by this StochasticTensor.
- group_ndims – A 0-D int32 Tensor representing the number of
dimensions in batch_shape (counted from the end) that are grouped
into a single event, so that their probabilities are calculated
together. Default is 0, which means a single value is an event.
See
Distributionfor more detailed explanation. - is_reparameterized – A Bool. If True, gradients on samples from this StochasticTensor are allowed to propagate into inputs, using the reparametrization trick from (Kingma, 2013).
- check_numerics – Bool. Whether to check numeric issues.
-
bn¶ The
BayesianNetwhere theStochasticTensorlives.Returns: A BayesianNetinstance.
-
cond_log_p¶ The conditional log probability of the
StochasticTensor, evaluated at its current value (given bytensor).Returns: A Tensor.
-
dist¶ - The distribution followed by the
StochasticTensor.Returns: A Distributioninstance.
-
distribution¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
The distribution followed by the
StochasticTensor.Returns: A Distributioninstance.
-
dtype¶ The sample type of the
StochasticTensor.Returns: A DTypeinstance.
-
is_observed()¶ Whether the
StochasticTensoris observed or not.Returns: A bool.
-
log_prob(given)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Compute the log probability density (mass) function of the underlying distribution at the given value.
Parameters: given – A Tensor. Returns: A Tensor. The log probability value.
-
name¶ The name of the
StochasticTensor.Returns: A string.
-
net¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
The
BayesianNetwhere theStochasticTensorlives.Returns: A BayesianNetinstance.
-
prob(given)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Compute the probability density (mass) function of the underlying distribution at the given value.
Parameters: given – A Tensor. Returns: A Tensor. The probability value.
-
sample(n_samples)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Sample from the underlying distribution.
Parameters: n_samples – A 0-D int32 Tensor. The number of samples. Returns: A Tensor.
-
shape¶ Return the static shape of this
StochasticTensor.Returns: A TensorShapeinstance.
-
tensor¶ The value of this
StochasticTensor. If it is observed, then the observation is returned, otherwise samples are returned.Returns: A Tensor.
-
ExpGumbelSoftmax¶
-
class
Concrete(name, temperature, logits, n_samples=None, group_ndims=0, is_reparameterized=True, check_numerics=False, **kwargs)¶ Bases:
zhusuan.framework.bn.StochasticTensorWarning
Deprecated in 0.4, will be removed in 0.4.1.
The class of Concrete (or Gumbel-Softmax) StochasticTensor from (Maddison, 2016; Jang, 2016), served as the continuous relaxation of the
OnehotCategorical. SeeStochasticTensorfor details.See also
Parameters: - temperature – A 0-D float Tensor. The temperature of the relaxed distribution. The temperature should be positive.
- logits –
A N-D (N >= 1) float Tensor of shape (…, n_categories). Each slice [i, j, …, k, :] represents the un-normalized log probabilities for all categories.
\[\mathrm{logits} \propto \log p\] - n_samples – A 0-D int32 Tensor or None. Number of samples generated by this StochasticTensor.
- group_ndims – A 0-D int32 Tensor representing the number of
dimensions in batch_shape (counted from the end) that are grouped
into a single event, so that their probabilities are calculated
together. Default is 0, which means a single value is an event.
See
Distributionfor more detailed explanation. - is_reparameterized – A Bool. If True, gradients on samples from this StochasticTensor are allowed to propagate into inputs, using the reparametrization trick from (Kingma, 2013).
- check_numerics – Bool. Whether to check numeric issues.
-
bn¶ The
BayesianNetwhere theStochasticTensorlives.Returns: A BayesianNetinstance.
-
cond_log_p¶ The conditional log probability of the
StochasticTensor, evaluated at its current value (given bytensor).Returns: A Tensor.
-
dist¶ - The distribution followed by the
StochasticTensor.Returns: A Distributioninstance.
-
distribution¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
The distribution followed by the
StochasticTensor.Returns: A Distributioninstance.
-
dtype¶ The sample type of the
StochasticTensor.Returns: A DTypeinstance.
-
is_observed()¶ Whether the
StochasticTensoris observed or not.Returns: A bool.
-
log_prob(given)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Compute the log probability density (mass) function of the underlying distribution at the given value.
Parameters: given – A Tensor. Returns: A Tensor. The log probability value.
-
name¶ The name of the
StochasticTensor.Returns: A string.
-
net¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
The
BayesianNetwhere theStochasticTensorlives.Returns: A BayesianNetinstance.
-
prob(given)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Compute the probability density (mass) function of the underlying distribution at the given value.
Parameters: given – A Tensor. Returns: A Tensor. The probability value.
-
sample(n_samples)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Sample from the underlying distribution.
Parameters: n_samples – A 0-D int32 Tensor. The number of samples. Returns: A Tensor.
-
shape¶ Return the static shape of this
StochasticTensor.Returns: A TensorShapeinstance.
-
tensor¶ The value of this
StochasticTensor. If it is observed, then the observation is returned, otherwise samples are returned.Returns: A Tensor.
-
GumbelSoftmax¶
-
class
Empirical(name, dtype, batch_shape, n_samples=None, group_ndims=0, value_shape=None, is_continuous=None, **kwargs)¶ Bases:
zhusuan.framework.bn.StochasticTensorWarning
Deprecated in 0.4, will be removed in 0.4.1.
The class of Empirical StochasticTensor. For any inference it is always required that the variables are observed. See
StochasticTensorfor details.Parameters: - name – A string. The name of the StochasticTensor. Must be unique in the BayesianNet context.
- dtype – The value type of samples from the distribution.
- batch_shape – A TensorShape describing the batch_shape of the distribution.
- value_shape – A TensorShape describing the value_shape of the distribution.
- is_continuous – A bool or None. Whether the distribution is continuous or not. If None, will consider it continuous only if dtype is a float type.
- n_samples – A 0-D int32 Tensor or None. Number of samples generated by this StochasticTensor.
- group_ndims – A 0-D int32 Tensor representing the number of
dimensions in batch_shape (counted from the end) that are grouped
into a single event, so that their probabilities are calculated
together. Default is 0, which means a single value is an event.
See
Distributionfor more detailed explanation.
-
bn¶ The
BayesianNetwhere theStochasticTensorlives.Returns: A BayesianNetinstance.
-
cond_log_p¶ The conditional log probability of the
StochasticTensor, evaluated at its current value (given bytensor).Returns: A Tensor.
-
dist¶ - The distribution followed by the
StochasticTensor.Returns: A Distributioninstance.
-
distribution¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
The distribution followed by the
StochasticTensor.Returns: A Distributioninstance.
-
dtype¶ The sample type of the
StochasticTensor.Returns: A DTypeinstance.
-
is_observed()¶ Whether the
StochasticTensoris observed or not.Returns: A bool.
-
log_prob(given)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Compute the log probability density (mass) function of the underlying distribution at the given value.
Parameters: given – A Tensor. Returns: A Tensor. The log probability value.
-
name¶ The name of the
StochasticTensor.Returns: A string.
-
net¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
The
BayesianNetwhere theStochasticTensorlives.Returns: A BayesianNetinstance.
-
prob(given)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Compute the probability density (mass) function of the underlying distribution at the given value.
Parameters: given – A Tensor. Returns: A Tensor. The probability value.
-
sample(n_samples)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Sample from the underlying distribution.
Parameters: n_samples – A 0-D int32 Tensor. The number of samples. Returns: A Tensor.
-
shape¶ Return the static shape of this
StochasticTensor.Returns: A TensorShapeinstance.
-
tensor¶ The value of this
StochasticTensor. If it is observed, then the observation is returned, otherwise samples are returned.Returns: A Tensor.
-
class
Implicit(name, samples, value_shape=None, group_ndims=0, n_samples=None, **kwargs)¶ Bases:
zhusuan.framework.bn.StochasticTensorWarning
Deprecated in 0.4, will be removed in 0.4.1.
The class of Implicit StochasticTensor. This distribution always sample the implicit tensor provided. See
StochasticTensorfor details.Parameters: - name – A string. The name of the StochasticTensor. Must be unique in the BayesianNet context.
- samples – A N-D (N >= 1) float Tensor.
- value_shape – A list or tuple describing the value_shape of the distribution. The entries of the list can either be int, Dimension or None.
- group_ndims – A 0-D int32 Tensor representing the number of
dimensions in batch_shape (counted from the end) that are grouped
into a single event, so that their probabilities are calculated
together. Default is 0, which means a single value is an event.
See
Distributionfor more detailed explanation. - n_samples – A 0-D int32 Tensor or None. Number of samples generated by this StochasticTensor.
-
bn¶ The
BayesianNetwhere theStochasticTensorlives.Returns: A BayesianNetinstance.
-
cond_log_p¶ The conditional log probability of the
StochasticTensor, evaluated at its current value (given bytensor).Returns: A Tensor.
-
dist¶ - The distribution followed by the
StochasticTensor.Returns: A Distributioninstance.
-
distribution¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
The distribution followed by the
StochasticTensor.Returns: A Distributioninstance.
-
dtype¶ The sample type of the
StochasticTensor.Returns: A DTypeinstance.
-
is_observed()¶ Whether the
StochasticTensoris observed or not.Returns: A bool.
-
log_prob(given)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Compute the log probability density (mass) function of the underlying distribution at the given value.
Parameters: given – A Tensor. Returns: A Tensor. The log probability value.
-
name¶ The name of the
StochasticTensor.Returns: A string.
-
net¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
The
BayesianNetwhere theStochasticTensorlives.Returns: A BayesianNetinstance.
-
prob(given)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Compute the probability density (mass) function of the underlying distribution at the given value.
Parameters: given – A Tensor. Returns: A Tensor. The probability value.
-
sample(n_samples)¶ Warning
Deprecated in 0.4, will be removed in 0.4.1.
Sample from the underlying distribution.
Parameters: n_samples – A 0-D int32 Tensor. The number of samples. Returns: A Tensor.
-
shape¶ Return the static shape of this
StochasticTensor.Returns: A TensorShapeinstance.
-
tensor¶ The value of this
StochasticTensor. If it is observed, then the observation is returned, otherwise samples are returned.Returns: A Tensor.