Skip to content

sample called with weights including 0 may yield such elements #982

@graidl

Description

@graidl

When calling sample(1:length(w), Weights()) with a Float32-weight vector w that includes some zero weights, it still can happen that an element with weight zero is returned.

More specifically, length(w) is returned with a probability of roughly 1/10,000,000 in my case of a 300 element weight vector with about 30 elements != 0. It seems this is the case due to some mathematical rounding issue.

Of course, if one knows this, it can easily be prevented by excluding the elements with probability zero, but I did not expect this behavior and was wondering why in my ML-application invalid actions that were masked out have been selected.

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