def categorical(self, name, logits, n_samples=None, group_ndims=0, dtype=tf.int32, **kwargs): """ Add a stochastic node in this :class:`BayesianNet` that follows the Categorical distribution. :param name: The name of the stochastic node. Must be unique in a :class:`BayesianNet`. See :class:`~zhusuan.distributions.univariate.Categorical` for more information about the other arguments. :return: A :class:`StochasticTensor` instance. """ dist = distributions.Categorical(logits, group_ndims=group_ndims, dtype=dtype, **kwargs) return self.stochastic(name, dist, n_samples=n_samples, **kwargs)
def __init__(self, name, logits, n_samples=None, group_ndims=0, dtype=None, **kwargs): cat = distributions.Categorical(logits, group_ndims=group_ndims, dtype=dtype, **kwargs) super(Categorical, self).__init__(name, cat, n_samples)
def __init__(self, logits, dtype=None): """ Construct the :class:`Categorical`. Args: logits: An N-D (N >= 1) `float` Tensor of shape ``(..., n_categories)``. Each slice `[i, j,..., k, :]` represents the un-normalized log probabilities for all categories. :math:`\\mathrm{logits} \\propto \\log p` dtype: The value type of samples from the distribution. (default ``tf.int32``) """ if dtype is None: dtype = tf.int32 super(Categorical, self).__init__( zd.Categorical(logits=logits, dtype=dtype))