-
Notifications
You must be signed in to change notification settings - Fork 69
Add ShiftedBetaGeometric
discrete distribution
#574
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
base: main
Are you sure you want to change the base?
Conversation
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 mentioned in the original issue that I think this makes more sense in pymc-marketing directly. Just left one comment that is relevant regardless of where you implement it in the end
class ShiftedBetaGeometricRV(RandomVariable): | ||
name = "sbg" | ||
signature = "(),()->()" | ||
|
||
dtype = "int64" | ||
_print_name = ("ShiftedBetaGeometric", "\\operatorname{ShiftedBetaGeometric}") | ||
|
||
@classmethod | ||
def rng_fn(cls, rng, alpha, beta, size): | ||
if size is None: | ||
size = np.broadcast_shapes(alpha.shape, beta.shape) | ||
|
||
alpha = np.broadcast_to(alpha, size) | ||
beta = np.broadcast_to(beta, size) | ||
|
||
p = rng.beta(a=alpha, b=beta, size=size) | ||
|
||
samples = rng.geometric(p, size=size) | ||
|
||
return samples |
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.
Use a SymbolicRandomVariable that defines the random method in terms of pytensor operations. That way it will work automatically in all backends (jax/numba), not just C/python
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.
Closes #573
test_random_edge_cases
uses rather extreme values and may be unstable.