Skip to content
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

Error when calling rand on a product measure #248

Closed
slwu89 opened this issue Feb 11, 2023 · 3 comments
Closed

Error when calling rand on a product measure #248

slwu89 opened this issue Feb 11, 2023 · 3 comments

Comments

@slwu89
Copy link
Contributor

slwu89 commented Feb 11, 2023

Hi, I encountered a strange problem when sampling from a product measure. My actual error occurred in the context of making a Markov chain, specifically from this line https://github.com/cscherrer/MeasureTheory.jl/blob/50d90d7aa42f60324a7fb9ba9dc45d4e2cac9d8e/src/combinators/chain.jl#L44

My MWE is below, using the same mu product measure object that was created in my erroring code, and using the same rng with the Xoshiro prng generator as was in the code (I suppose it is the default argument when using the rand method on the Chain object). Interestingly when calling rand on the product measure object without specifying the rng it works fine. The error is a method error from deep within the random number generation.

using Random
using MeasureTheory
rng = ResettableRNG(Random.Xoshiro(), 6542022242862247233)
mu = ProductMeasure([Binomial(n = 990, p = 0.00995017), Binomial(n = 10, p = 0.0246901)])
rand(rng, mu)
rand(mu)

The error is:

ERROR: MethodError: no method matching rng_native_52(::ResettableRNG{Xoshiro, UInt64})

Here's my Julia info, and I'm on MeasureTheory v0.18.1. Thanks!

Julia Version 1.8.5
Commit 17cfb8e65ea (2023-01-08 06:45 UTC)
Platform Info:
  OS: macOS (arm64-apple-darwin21.5.0)
  CPU: 8 × Apple M1
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-13.0.1 (ORCJIT, apple-m1)
  Threads: 1 on 4 virtual cores
Environment:
  JULIA_EDITOR = code
  JULIA_NUM_THREADS = 
@slwu89
Copy link
Contributor Author

slwu89 commented Feb 11, 2023

I noticed this issue JuliaMath/MeasureBase.jl#34 but the Binomial objects in the product measure here are definitely the ones from MeasureTheory.jl, rather than Distributions.jl

@slwu89
Copy link
Contributor Author

slwu89 commented Feb 14, 2023

Looking through the trace, this issue can be "fixed" by changing the definition here https://github.com/cscherrer/MeasureTheory.jl/blob/master/src/parameterized/binomial.jl#L44 to below (passing rng.rng as the first arg to rand).

function Base.rand(
    rng::AbstractRNG,
    ::Type,
    d::Binomial{(:n, :p),Tuple{I,A}},
) where {I<:Integer,A}
    rand(rng.rng, Dists.Binomial(d.n, d.p))
end

@slwu89
Copy link
Contributor Author

slwu89 commented Feb 26, 2023

Closed with #249

@slwu89 slwu89 closed this as completed Feb 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant