Ejemplo n.º 1
0
    def 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
        Concrete distribution.

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

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

        :return: A :class:`StochasticTensor` instance.
        """
        dist = distributions.Concrete(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)
Ejemplo 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(Concrete, self).__init__(
            zd.Concrete(temperature=temperature,
                        logits=logits,
                        is_reparameterized=is_reparameterized,
                        check_numerics=check_numerics))
Ejemplo n.º 3
0
 def __init__(self,
              name,
              temperature,
              logits,
              n_samples=None,
              group_event_ndims=0,
              is_reparameterized=True,
              check_numerics=False):
     concrete = distributions.Concrete(
         temperature,
         logits,
         group_event_ndims=group_event_ndims,
         is_reparameterized=is_reparameterized,
         check_numerics=check_numerics)
     super(Concrete, self).__init__(name, concrete, n_samples)
Ejemplo 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(Concrete, self).__init__(
            zd.Concrete(temperature=temperature,
                        logits=logits,
                        is_reparameterized=is_reparameterized,
                        check_numerics=check_numerics))