Skip to content

BUG: The beta distribution generates random values equal to 0 #7694

@tomicapretto

Description

@tomicapretto

Describe the issue:

Someone reported a test failing in Bambi (see bambinos/bambi#888).

The test was checking whether random values generated from a beta likelihood were always in the (0, 1) interval.

I managed to reproduce the example in PyMC.

Reproduceable code example:

import numpy as np
import pymc as pm

mu = np.array(
    [
        7.07551617e-12,
        3.13190732e-11,
        1.37305053e-10,
        5.71933452e-08,
        3.47710424e-07,
        7.36626506e-06,
        1.69159968e-04,
        4.39823566e-03,
        3.43223695e-01,
        3.41184856e-01,
    ]
)

kappa = np.array(
    [
        2.42025905,
        2.40677827,
        2.40394316,
        2.36733373,
        2.36652374,
        2.3536546,
        2.35645956,
        2.34899749,
        2.37637218,
        2.35059481,
    ]
)

alpha = mu * kappa
beta = (1 - mu) * kappa

draws = pm.draw(pm.Beta.dist(alpha, beta))
print(draws)
print((draws == 0).sum())

Error message:

PyMC version information:

import pymc as pm
import pytensor as pt

print(pm.__version__)
print(pt.__version__)
5.20.1
2.28.1

Context for the issue:

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions