Esempio n. 1
0
    def exp_concrete(self,
                     name,
                     temperature,
                     logits,
                     n_samples=None,
                     group_ndims=0,
                     is_reparameterized=True,
                     check_numerics=False,
                     **kwargs):
        """
        Add a stochastic node in this :class:`BayesianNet` that follows the
        ExpConcrete distribution.

        :param name: The name of the stochastic node. Must be unique in a
            :class:`BayesianNet`.

        See
        :class:`~zhusuan.distributions.multivariate.ExpConcrete`
        for more information about the other arguments.

        :return: A :class:`StochasticTensor` instance.
        """
        dist = distributions.ExpConcrete(temperature,
                                         logits,
                                         group_ndims=group_ndims,
                                         is_reparameterized=is_reparameterized,
                                         check_numerics=check_numerics,
                                         **kwargs)
        return self.stochastic(name, dist, n_samples=n_samples, **kwargs)
Esempio n. 2
0
    def __init__(self,
                 temperature,
                 logits,
                 is_reparameterized=True,
                 check_numerics=None):
        """
        Construct the :class:`ExpConcrete`.

        Args:
            temperature: A 0-D `float` Tensor. The temperature of the relaxed
                distribution. The temperature should be positive.
            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`
            is_reparameterized (bool): Whether or not the gradients can
                be propagated through parameters? (default :obj:`True`)
            check_numerics (bool): Whether or not to check numerical issues.
                Default to ``tfsnippet.settings.check_numerics``.
        """
        if check_numerics is None:
            check_numerics = settings.check_numerics
        super(ExpConcrete, self).__init__(
            zd.ExpConcrete(temperature=temperature,
                           logits=logits,
                           is_reparameterized=is_reparameterized,
                           check_numerics=check_numerics))
Esempio n. 3
0
 def __init__(self,
              name,
              temperature,
              logits,
              n_samples=None,
              group_event_ndims=0,
              is_reparameterized=True,
              check_numerics=False):
     exp_concrete = distributions.ExpConcrete(
         temperature,
         logits,
         group_event_ndims=group_event_ndims,
         is_reparameterized=is_reparameterized,
         check_numerics=check_numerics)
     super(ExpConcrete, self).__init__(name, exp_concrete, n_samples)
Esempio n. 4
0
    def __init__(self,
                 temperature,
                 logits,
                 is_reparameterized=True,
                 check_numerics=False):
        """
        Construct the :class:`ExpConcrete`.

        Args:
            temperature: A 0-D `float` Tensor. The temperature of the relaxed
                distribution. The temperature should be positive.
            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`
        """
        super(ExpConcrete, self).__init__(
            zd.ExpConcrete(temperature=temperature,
                           logits=logits,
                           is_reparameterized=is_reparameterized,
                           check_numerics=check_numerics))