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)
| 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 |