-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
【Hackathon 5th No.18】Add Binomial and Poisson API -part #57856
Merged
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
0606964
Add Binomial and Poisson
NKNaN 4566aae
update __init__.py
NKNaN 5486dee
update api and add test binomial
NKNaN 700c2ea
fix binomial
NKNaN 8ed6913
update api and add test
NKNaN 5a058fb
fix testing
NKNaN e3a1651
update
NKNaN 9f33de6
update
NKNaN 7495ecc
update poisson
NKNaN c6134bf
fix en docs
NKNaN b5789b2
fix test timeout
NKNaN 7beabd0
fix test timeout
NKNaN aac4888
fix test timeout
NKNaN 69735d4
fix test
NKNaN 18b74ba
fix test
NKNaN f1629d6
fix docs
NKNaN 49db8fb
fix test
NKNaN 0dfe211
fix test
NKNaN 1150b6c
fix test coverage
NKNaN 5bf911a
update docs
NKNaN d686dde
update poisson and poisson test
NKNaN 0e19d49
update poisson
NKNaN 4afb38c
update poisson test
NKNaN b2f8549
update binomial
NKNaN 8bf89a3
update binomial api and tests
NKNaN af9c127
update docs and tests
NKNaN 70d5abf
update doc test
NKNaN 3fc4ad6
fix conflict
NKNaN 6f5e3df
update signiture
NKNaN File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
update docs
- Loading branch information
commit 5bf911a744dd3afbd88ec4f08e2059433027b595
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ class Binomial(distribution.Distribution): | |
r""" | ||
The Binomial distribution with size `total_count` and `probability` parameters. | ||
|
||
In probability theory and statistics, the binomial distribution is the most basic probability distribution, | ||
In probability theory and statistics, the binomial distribution is the most basic discrete probability distribution defined on :math:`[0, n] \cap \mathbb{N}`, | ||
which can be viewed as the number of times a potentially unfair coin is tossed to get heads, and the result | ||
of its random variable can be viewed as the sum of a series of independent Bernoulli experiments. | ||
|
||
|
@@ -38,15 +38,14 @@ class Binomial(distribution.Distribution): | |
|
||
In the above equation: | ||
|
||
* :math:`total_count = n`: is the size. | ||
* :math:`probability = p`: is the probability. | ||
* :math:`total_count = n`: is the size, meaning the total number of Bernoulli experiments. | ||
* :math:`probability = p`: is the probability of the event happening in one Bernoulli experiments. | ||
|
||
Args: | ||
total_count(int|Tensor): The size of Binomial distribution, meaning the number of independent bernoulli | ||
trials with probability parameter p. The random variable counts the number of success | ||
among n independent bernoulli trials. The data type of `total_count` will be convert to float32. | ||
probability(float|Tensor): The probability of Binomial distribution, meaning the probability of success | ||
for each individual bernoulli trial. The data type of `probability` will be convert to float32. | ||
total_count(int|Tensor): The size of Binomial distribution which should be greater than 0, meaning the number of independent bernoulli | ||
trials with probability parameter :math:`p`. The data type of :attr:`total_count` will be convert to float32. | ||
probability(float|Tensor): The probability of Binomial distribution which should reside in [0, 1], meaning the probability of success | ||
for each individual bernoulli trial. The data type of :attr:`probability` will be convert to float32. | ||
|
||
Examples: | ||
.. code-block:: python | ||
|
@@ -141,13 +140,13 @@ def variance(self): | |
return self.total_count * self.probability * (1 - self.probability) | ||
|
||
def sample(self, shape=()): | ||
"""Generate binomial samples of the specified shape. | ||
"""Generate binomial samples of the specified shape. The final shape would be ``shape+batch_shape`` . | ||
|
||
Args: | ||
shape (Sequence[int], optional): Prepended shape of the generated samples. | ||
|
||
Returns: | ||
Tensor: A tensor with prepended dimensions shape. The data type is float32. | ||
Tensor: Sampled data with shape `sample_shape` + `batch_shape`. | ||
""" | ||
if not isinstance(shape, Iterable): | ||
raise TypeError('sample shape must be Iterable object.') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Iterable 和 Sequence 语义略有区别 https://stackoverflow.com/questions/72157296/what-is-the-difference-between-type-hinting-a-variable-as-an-iterable-versus-a-s ,此处应该是只需要传入Sequence |
||
|
@@ -259,7 +258,7 @@ def prob(self, value): | |
return paddle.exp(self.log_prob(value)) | ||
|
||
def kl_divergence(self, other): | ||
r"""The KL-divergence between two binomial distributions. | ||
r"""The KL-divergence between two binomial distributions with the same :attr:`total_count`. | ||
|
||
The probability density function (pdf) is | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已修改