-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Adding the Hypergeometric Distribution (hypergeometricCdf + inverseHypergeometricCdf) (#15798) #15821
Conversation
Code review:
Otherwise looks great! |
b909dd1
to
18d8fb0
Compare
a06990d
to
db03528
Compare
0fb078e
to
515fdc4
Compare
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.
LGTM
Hey @sriram201 , |
This seems to have been a pushing mixup. I fixed it |
Cool, thanks!
…On Tue, Apr 13, 2021, 22:44 sriram201 ***@***.***> wrote:
Hey @sriram201 <https://github.com/sriram201> ,
This diff looks good, but it seems to be missing the
inverse_hypergeometric_cdf. Would you be able to please add it to this diff?
This seems to have been a pushing mixup. I fixed it
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#15821 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAHOJBRNFREU6VTXYCAZVVDTISNKDANCNFSM4ZBKP7UQ>
.
|
df36faf
to
da3c41d
Compare
da3c41d
to
997e4bd
Compare
.. function:: hypergeometric_cdf(populationSize, numberOfSuccesses, sampleSize, observedSuccesses) -> double | ||
|
||
Compute the Hypergeometric cdf with given populationSize, numberOfSuccesses, sampleSize | ||
and observed_successes: P(N <= observedSuccesses). The populationSize must be a positive integer |
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.
Please change observedSuccesses
to value
(just to be consistent with the other functions)
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.
(please explain in the text here that value is observedSuccesses)
@@ -66,12 +66,25 @@ Mathematical Functions | |||
|
|||
Returns the value of ``string`` interpreted as a base-``radix`` number. | |||
|
|||
.. function:: hypergeometric_cdf(populationSize, numberOfSuccesses, sampleSize, observedSuccesses) -> double |
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.
Please change observedSuccesses
to value
(just to be consistent with the other functions)
(also in the function itself)
@SqlType(StandardTypes.INTEGER) long populationSize, | ||
@SqlType(StandardTypes.INTEGER) long numberOfSuccesses, | ||
@SqlType(StandardTypes.INTEGER) long sampleSize, | ||
@SqlType(StandardTypes.INTEGER) long observedSuccesses) |
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.
Please change observedSuccesses
to value
(just to be consistent with the other functions)
|
||
HypergeometricDistribution distribution = new HypergeometricDistribution((int) populationSize, (int) numberOfSuccesses, (int) sampleSize); | ||
|
||
return distribution.cumulativeProbability((int) observedSuccesses); |
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.
Please change observedSuccesses
to value
(just to be consistent with the other functions)
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.
works for me
presto-main/src/test/java/com/facebook/presto/operator/scalar/TestMathFunctions.java
Show resolved
Hide resolved
Cool.
…On Mon, Apr 26, 2021 at 11:10 PM sriram201 ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In
presto-main/src/main/java/com/facebook/presto/operator/scalar/MathFunctions.java
<#15821 (comment)>:
> + @ScalarFunction
+ @SqlType(StandardTypes.DOUBLE)
+ public static double hypergeometricCdf(
+ @SqlType(StandardTypes.INTEGER) long populationSize,
+ @SqlType(StandardTypes.INTEGER) long numberOfSuccesses,
+ @SqlType(StandardTypes.INTEGER) long sampleSize,
+ @SqlType(StandardTypes.INTEGER) long observedSuccesses)
+ {
+ checkCondition(populationSize > 0, INVALID_FUNCTION_ARGUMENT, "populationSize must be greater than 0");
+ checkCondition(numberOfSuccesses >= 0, INVALID_FUNCTION_ARGUMENT, "numberOfSuccesses cannot be negative");
+ checkCondition(numberOfSuccesses <= populationSize, INVALID_FUNCTION_ARGUMENT, "numberOfSuccesses cannot exceed populationSize");
+ checkCondition(sampleSize <= populationSize, INVALID_FUNCTION_ARGUMENT, "sampleSize cannot exceed populationSize");
+
+ HypergeometricDistribution distribution = new HypergeometricDistribution((int) populationSize, (int) numberOfSuccesses, (int) sampleSize);
+
+ return distribution.cumulativeProbability((int) observedSuccesses);
works for me
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#15821 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAHOJBSAY2XDMWUVDL7R67TTKXCEHANCNFSM4ZBKP7UQ>
.
|
997e4bd
to
8cca542
Compare
presto-main/src/main/java/com/facebook/presto/operator/scalar/MathFunctions.java
Outdated
Show resolved
Hide resolved
presto-main/src/main/java/com/facebook/presto/operator/scalar/MathFunctions.java
Outdated
Show resolved
Hide resolved
presto-main/src/main/java/com/facebook/presto/operator/scalar/MathFunctions.java
Outdated
Show resolved
Hide resolved
8cca542
to
ea10fae
Compare
@rongrong the diffs seems updated and ready for review. |
Hey @sriram201 - I see that this diff has merge conflicts, could you please resolve them? |
ea10fae
to
678254b
Compare
Done. Sorry about that |
Adding the CDF and the inverse CDF for the Hypergeometric Distribution
678254b
to
8c2fa52
Compare
Gentle ping! 🙏 |
This pull request has been automatically marked as stale because it has not had recent activity. If you'd still like this PR merged, please comment on the task, make sure you've addressed reviewer comments, and rebase on the latest master. Thank you for your contributions! |
Adding the Hypergeometric Distribution
Test plan - (Added unit tests)