Skip to content

Cannot sample from a type that implements rand() #615

@nluetts

Description

@nluetts

Hi,

with regard to distributions from which to sample in a model, the Guide states:

distr can be a value of any type that implements rand(distr), which samples a value from the distribution distr.

https://github.com/TuringLang/Turing.jl/blob/d76d914231db0198b99e5ca5d69d80934ee016b3/docs/src/using-turing/guide.md?plain=1#L19

I have a set of samples from which I want to derive a distribution to sample from and use KernelDensityEstimate.jl to build a KDE from which one can sample using rand().
This returns a 1x1 Matrix, funny enough, but I wrapped the KDE in my own struct and defined the method Random.rand() such that it returns a float. It still does not work, I get the error:

ERROR: ArgumentError: the right-hand side of a `~` must be a `Distribution` or an array of `Distribution`s

From the Guide I was pretty sure my approach should work. Is the Guide wrong or is this a misunderstanding?
Thank you!

Turing v0.24.0, DynamicPPL v0.21.6, Julia 1.8.5

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