-
Notifications
You must be signed in to change notification settings - Fork 242
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
more random functions #4145
more random functions #4145
Conversation
python/hail/expr/functions.py
Outdated
|
||
Parameters | ||
---------- | ||
a : float or :class:`.Expression` of type :py:data:`.tfloat64` |
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.
you can simplify this here and elsewhere:
float or :class`Float64Expression`
python/hail/expr/functions.py
Outdated
max=nullable(expr_float64), | ||
seed=nullable(int)) | ||
def rand_beta(a, b, min=None, max=None, seed=None) -> Float64Expression: | ||
"""Returns a random floating-point number drawn from a beta distribution |
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.
I'd shorten to "Returns a random draw from a beta distribution." and link beta distribution to: https://en.wikipedia.org/wiki/Beta_distribution
python/hail/expr/functions.py
Outdated
---------- | ||
a : float or :class:`.Expression` of type :py:data:`.tfloat64` | ||
b : float or :class:`.Expression` of type :py:data:`.tfloat64` | ||
min : float or :class:`.Expression` of type :py:data:`.tfloat64` |
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.
convention is:
float or :class`Float64Expression`, optional
python/hail/expr/functions.py
Outdated
(Optional) Left boundary of truncated beta distribution. | ||
max : float or :class:`.Expression` of type :py:data:`.tfloat64` | ||
(Optional) Right boundary of truncated beta distribution. | ||
seed : :obj:`int` or `None` |
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.
:obj:`int`, optional
make this change below too (and check that all these random functions are consistently documented)
python/hail/expr/functions.py
Outdated
max : float or :class:`.Expression` of type :py:data:`.tfloat64` | ||
(Optional) Right boundary of truncated beta distribution. | ||
seed : :obj:`int` or `None` | ||
If not `None`, function will be seeded with provided seed. |
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.
Just put "Random seed".
python/hail/methods/statgen.py
Outdated
@@ -2207,6 +2204,7 @@ def balding_nichols_model(n_populations, n_samples, n_variants, n_partitions=Non | |||
mixture) | |||
return MatrixTable(jmt) | |||
|
|||
|
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.
remove line
|
||
def rgamma(a: Double, scale: Double): Double = Gamma.random(a, scale, random) | ||
|
||
def rdraw(a: Array[Double]): Int = { |
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.
rcat(prob)
|
||
def rdraw(a: Array[Double]): Int = { | ||
val sum = a.sum | ||
val probs = Array.tabulate(a.length)(i => a(i) / sum) |
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.
no need for rescaling. Just set draw = random.nextDouble() * sum
python/hail/expr/functions.py
Outdated
|
||
Warning | ||
------- | ||
This function may be slow over very large arrays. |
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.
This function may be slow when the number of categories is large.
Examples | ||
-------- | ||
|
||
>>> hl.rand_dirichlet([1, 1, 1]).value |
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.
what behavior do you get if a value is negative?
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.
>>> hl.rand_dirichlet([-1, -1, 1]).value
[nan, nan, nan]
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.
great!
python/hail/expr/functions.py
Outdated
""" | ||
return _seeded_func("rand_norm", tfloat64, seed, mean, sd) | ||
|
||
|
||
@typecheck(lamb=expr_float64, seed=nullable(int)) | ||
def rand_pois(lamb, seed=None) -> Float64Expression: | ||
"""Samples from a Poisson distribution with rate parameter `lamb` (RNG). | ||
"""Samples from a Poisson distribution with rate parameter `lamb`. |
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 parameter name to lambda and link to https://en.wikipedia.org/wiki/Poisson_distribution
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.
lambda
is a reserved word in python, unfortunately
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.
oh right, that's why we used lamb. ok
python/hail/expr/functions.py
Outdated
"""Returns a random index from an array of unnormalized probabilities. | ||
def rand_cat(prob, seed=None) -> Int32Expression: | ||
"""Samples from a `categorical distribution | ||
<https://en.wikipedia.org/wiki/Categorical_distribution>`__ |
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.
add period
python/hail/expr/functions.py
Outdated
def rand_beta(a, b, lower=None, upper=None, seed=None) -> Float64Expression: | ||
"""Samples from a `beta distribution | ||
<https://en.wikipedia.org/wiki/Beta_distribution>`__ with parameters `a` | ||
(alpha) and `b` (beta). |
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.
nice, very clear
don't forget to make a discuss post on the breaking change on the parameter names (lower/upper) |
(mostly the ones that balding nichols uses.)