Skip to content

sampling from Dirichlet produces NaN and Inf at extreme alpha #1702

Open
@clolesen

Description

@clolesen

In my code a random process generates alpha vectors for Dirichlet distributions and on rare occasions these can have extreme values. When sampling with an alpha where all values are extremely low the rand() function returns an array of NaN, sometimes with an Inf in there. Here is an example:

rand(Dirichlet([8e-5, 1e-5, 2e-5]))

At slightly less extreme values it produce NaN arrays less frequently, but still sometimes:

rand(Dirichlet([8e-4, 1e-4, 2e-4]))

It seem to only happen when all values are low.

I don't know if this is really a bug. There is no practical difference between these examples and using less extreme values that works (they are so extreme they will always produce certainty in one category). So it is easy to make a work around to makes my code run. However, I thought report it anyway as it might highlight a deeper, less noticeable problem?

I have also experienced it producing a vector where the values doesn't sum to 1. So much that the Categorical distribution throws and error saying that it is not a probability vector. But I failed to make a reproducible example (might be a bug of my own then?). Is this something there could be an explanation for?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions