Sampler for Categorical Rational Distributions

With the new Distributions update (this did not appear to happen several versions ago), this works

rand(Categorical([0.5, 0.5]))

and this works

Categorical([1//2, 1//2])

but this causes an error (“ArgumentError: Sampler for this object is not defined”)

rand(Categorical([1//2, 1//2]))

What am I doing wrong here?

What versions are you using? These versions seem to work:

julia> rand(Categorical([1//2,1//2]))
2

(jl_waVJwl) pkg> st
      Status `/tmp/jl_waVJwl/Project.toml`
  [31c24e10] Distributions v0.24.12

julia> versioninfo()
Julia Version 1.6.0-rc1
Commit a58bdd9010 (2021-02-06 15:49 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-11.0.1 (ORCJIT, skylake)
Environment:
  JULIA_REVISE_INCLUDE = 1
2 Likes

I am on version 0.21.12 of Distributions, which is why it’s probably not working.
However Pkg.update(“Distributions”) is leading to no changes. Is this due to me being on 1.6 beta?

It actually was due to a seperate package (ClassImbalance) that Distributions of higher versions required be uninstalled. It told me this when I tried to get the Github version. It is working as expected now

1 Like