MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / binomial

Method binomial

tensorflow/python/ops/stateful_random_ops.py:535–583  ·  view source on GitHub ↗

Outputs random values from a binomial distribution. The generated values follow a binomial distribution with specified count and probability of success parameters. Example: ```python counts = [10., 20.] # Probability of success. probs = [0.8, 0.9] rng = tf.random.

(self, shape, counts, probs, dtype=dtypes.int32, name=None)

Source from the content-addressed store, hash-verified

533 dtype=dtype, name=name)
534
535 def binomial(self, shape, counts, probs, dtype=dtypes.int32, name=None):
536 """Outputs random values from a binomial distribution.
537
538 The generated values follow a binomial distribution with specified count and
539 probability of success parameters.
540
541 Example:
542
543 ```python
544 counts = [10., 20.]
545 # Probability of success.
546 probs = [0.8, 0.9]
547
548 rng = tf.random.experimental.Generator.from_seed(seed=234)
549 binomial_samples = rng.binomial(shape=[2], counts=counts, probs=probs)
550 ```
551
552
553 Args:
554 shape: A 1-D integer Tensor or Python array. The shape of the output
555 tensor.
556 counts: A 0/1-D Tensor or Python value. The counts of the binomial
557 distribution. Must be broadcastable with the leftmost dimension
558 defined by `shape`.
559 probs: A 0/1-D Tensor or Python value. The probability of success for the
560 binomial distribution. Must be broadcastable with the leftmost
561 dimension defined by `shape`.
562 dtype: The type of the output. Default: tf.int32
563 name: A name for the operation (optional).
564
565 Returns:
566 samples: A Tensor of the specified shape filled with random binomial
567 values. For each i, each samples[i, ...] is an independent draw from
568 the binomial distribution on counts[i] trials with probability of
569 success probs[i].
570 """
571 dtype = dtypes.as_dtype(dtype)
572 with ops.name_scope(name, "binomial", [shape, counts, probs]) as name:
573 counts = ops.convert_to_tensor(counts, name="counts")
574 probs = ops.convert_to_tensor(probs, name="probs")
575 shape_tensor = _shape_tensor(shape)
576 return gen_stateful_random_ops.stateful_random_binomial(
577 self.state.handle,
578 self.algorithm,
579 shape=shape_tensor,
580 counts=counts,
581 probs=probs,
582 dtype=dtype,
583 name=name)
584
585 # TODO(wangpeng): implement other distributions
586

Callers 6

synthetic_dataFunction · 0.80
funcMethod · 0.80
testZeroShapeMethod · 0.80
testShapeMethod · 0.80
testCornerCasesMethod · 0.80
testSparseExpandDimsMethod · 0.80

Calls 2

_shape_tensorFunction · 0.85
name_scopeMethod · 0.45

Tested by 6

synthetic_dataFunction · 0.64
funcMethod · 0.64
testZeroShapeMethod · 0.64
testShapeMethod · 0.64
testCornerCasesMethod · 0.64
testSparseExpandDimsMethod · 0.64