Пример #1
0
 def _log_prob(self, counts):
   counts = self._assert_valid_sample(counts)
   log_unnormalized_prob = math_ops.reduce_sum(
       counts * math_ops.log(self.p),
       reduction_indices=[-1])
   log_normalizer = -distribution_util.log_combinations(self.n, counts)
   return log_unnormalized_prob - log_normalizer
Пример #2
0
  def log_prob(self, counts, name="log_prob"):
    """`Log(P[counts])`, computed for every batch member.

    For each batch of counts `[n_1,...,n_k]`, `P[counts]` is the probability
    that after sampling `n` draws from this Multinomial distribution, the
    number of draws falling in class `j` is `n_j`.  Note that different
    sequences of draws can result in the same counts, thus the probability
    includes a combinatorial coefficient.

    Args:
      counts:  Non-negative tensor with dtype `dtype` and whose shape can
        be broadcast with `self.p` and `self.n`.  For fixed leading dimensions,
        the last dimension represents counts for the corresponding Multinomial
        distribution in `self.p`. `counts` is only legal if it sums up to `n`
        and its components are equal to integer values.
      name:  Name to give this Op, defaults to "log_prob".

    Returns:
      Log probabilities for each record, shape `[N1,...,Nm]`.
    """
    n = self._n
    p = self._p
    with ops.name_scope(self.name):
      with ops.op_scope([n, p, counts], name):
        counts = self._check_counts(counts)

        prob_prob = math_ops.reduce_sum(counts * math_ops.log(self._p),
                                        reduction_indices=[-1])
        log_prob = prob_prob + distribution_util.log_combinations(
            n, counts)
        return log_prob
 def _log_prob(self, counts):
   counts = self._maybe_assert_valid_sample(counts)
   ordered_prob = (
       special_math_ops.lbeta(self.concentration + counts)
       - special_math_ops.lbeta(self.concentration))
   return ordered_prob + distribution_util.log_combinations(
       self.total_count, counts)
 def _log_prob(self, counts):
     counts = self._assert_valid_counts(counts)
     ordered_prob = (special_math_ops.lbeta(self.alpha + counts) -
                     special_math_ops.lbeta(self.alpha))
     log_prob = ordered_prob + distribution_util.log_combinations(
         self.n, counts)
     return log_prob
Пример #5
0
    def log_prob(self, counts, name="log_prob"):
        """`Log(P[counts])`, computed for every batch member.

    For each batch of counts `[n_1,...,n_k]`, `P[counts]` is the probability
    that after sampling `n` draws from this Dirichlet Multinomial
    distribution, the number of draws falling in class `j` is `n_j`.  Note that
    different sequences of draws can result in the same counts, thus the
    probability includes a combinatorial coefficient.

    Args:
      counts:  Non-negative tensor with dtype `dtype` and whose shape can be
        broadcast with `self.alpha`.  For fixed leading dimensions, the last
        dimension represents counts for the corresponding Dirichlet Multinomial
        distribution in `self.alpha`. `counts` is only legal if it sums up to
        `n` and its components are equal to integer values.
      name:  Name to give this Op, defaults to "log_prob".

    Returns:
      Log probabilities for each record, shape `[N1,...,Nn]`.
    """
        n = self._n
        alpha = self._alpha
        with ops.name_scope(self.name):
            with ops.name_scope(name, values=[n, alpha, counts]):
                counts = self._check_counts(counts)

                ordered_prob = (special_math_ops.lbeta(alpha + counts) -
                                special_math_ops.lbeta(alpha))
                log_prob = ordered_prob + distribution_util.log_combinations(
                    n, counts)
                return log_prob
Пример #6
0
 def _log_prob(self, counts):
   counts = self._assert_valid_counts(counts)
   ordered_prob = (special_math_ops.lbeta(self.alpha + counts) -
                   special_math_ops.lbeta(self.alpha))
   log_prob = ordered_prob + distribution_util.log_combinations(
       self.n, counts)
   return log_prob
Пример #7
0
    def log_prob(self, counts, name="log_prob"):
        """`Log(P[counts])`, computed for every batch member.

    For each batch of counts `[n_1,...,n_k]`, `P[counts]` is the probability
    that after sampling `n` draws from this Multinomial distribution, the
    number of draws falling in class `j` is `n_j`.  Note that different
    sequences of draws can result in the same counts, thus the probability
    includes a combinatorial coefficient.

    Args:
      counts:  Non-negative tensor with dtype `dtype` and whose shape can
        be broadcast with `self.p` and `self.n`.  For fixed leading dimensions,
        the last dimension represents counts for the corresponding Multinomial
        distribution in `self.p`. `counts` is only legal if it sums up to `n`
        and its components are equal to integer values.
      name:  Name to give this Op, defaults to "log_prob".

    Returns:
      Log probabilities for each record, shape `[N1,...,Nm]`.
    """
        n = self._n
        p = self._p
        with ops.name_scope(self.name):
            with ops.op_scope([n, p, counts], name):
                counts = self._check_counts(counts)

                prob_prob = math_ops.reduce_sum(counts * math_ops.log(self._p),
                                                reduction_indices=[-1])
                log_prob = prob_prob + distribution_util.log_combinations(
                    n, counts)
                return log_prob
Пример #8
0
  def log_prob(self, counts, name="log_prob"):
    """`Log(P[counts])`, computed for every batch member.

    For each batch of counts `[n_1,...,n_k]`, `P[counts]` is the probability
    that after sampling `n` draws from this Dirichlet Multinomial
    distribution, the number of draws falling in class `j` is `n_j`.  Note that
    different sequences of draws can result in the same counts, thus the
    probability includes a combinatorial coefficient.

    Args:
      counts:  Non-negative tensor with dtype `dtype` and whose shape can be
        broadcast with `self.alpha`.  For fixed leading dimensions, the last
        dimension represents counts for the corresponding Dirichlet Multinomial
        distribution in `self.alpha`. `counts` is only legal if it sums up to
        `n` and its components are equal to integer values.
      name:  Name to give this Op, defaults to "log_prob".

    Returns:
      Log probabilities for each record, shape `[N1,...,Nn]`.
    """
    n = self._n
    alpha = self._alpha
    with ops.name_scope(self.name):
      with ops.name_scope(name, values=[n, alpha, counts]):
        counts = self._check_counts(counts)

        ordered_prob = (special_math_ops.lbeta(alpha + counts) -
                        special_math_ops.lbeta(alpha))
        log_prob = ordered_prob + distribution_util.log_combinations(
            n, counts)
        return log_prob
  def testLogCombinationsShape(self):
    # Shape [2, 2]
    n = [[2, 5], [12, 15]]

    with self.test_session():
      n = np.array(n, dtype=np.float32)
      # Shape [2, 2, 4]
      counts = [[[1., 1, 0, 0], [2., 2, 1, 0]], [[4., 4, 1, 3], [10, 1, 1, 4]]]
      log_binom = distribution_util.log_combinations(n, counts)
      self.assertEqual([2, 2], log_binom.get_shape())
  def testLogCombinationsShape(self):
    # Shape [2, 2]
    n = [[2, 5], [12, 15]]

    with self.test_session():
      n = np.array(n, dtype=np.float32)
      # Shape [2, 2, 4]
      counts = [[[1., 1, 0, 0], [2., 2, 1, 0]], [[4., 4, 1, 3], [10, 1, 1, 4]]]
      log_binom = distribution_util.log_combinations(n, counts)
      self.assertEqual([2, 2], log_binom.get_shape())
  def testLogCombinationsBinomial(self):
    n = [2, 5, 12, 15]
    k = [1, 2, 4, 11]
    log_combs = np.log(special.binom(n, k))

    with self.test_session():
      n = np.array(n, dtype=np.float32)
      counts = [[1., 1], [2., 3], [4., 8], [11, 4]]
      log_binom = distribution_util.log_combinations(n, counts)
      self.assertEqual([4], log_binom.get_shape())
      self.assertAllClose(log_combs, log_binom.eval())
    def testLogCombinationsBinomial(self):
        n = [2, 5, 12, 15]
        k = [1, 2, 4, 11]
        log_combs = np.log(special.binom(n, k))

        with self.test_session():
            n = np.array(n, dtype=np.float32)
            counts = [[1., 1], [2., 3], [4., 8], [11, 4]]
            log_binom = distribution_util.log_combinations(n, counts)
            self.assertEqual([4], log_binom.get_shape())
            self.assertAllClose(log_combs, log_binom.eval())
 def _log_prob(self, counts):
     counts = self._maybe_assert_valid_sample(counts)
     ordered_prob = (special_math_ops.lbeta(self.concentration + counts) -
                     special_math_ops.lbeta(self.concentration))
     return ordered_prob + distribution_util.log_combinations(
         self.total_count, counts)
Пример #14
0
 def _log_normalization(self, counts):
     counts = self._maybe_assert_valid_sample(counts)
     return -distribution_util.log_combinations(self.total_count, counts)
Пример #15
0
 def _log_normalization(self, counts):
   counts = self._maybe_assert_valid_sample(counts)
   return -distribution_util.log_combinations(self.total_count, counts)