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

AliasTable method is not working for unbalanced values #832

Closed
s271 opened this issue Feb 20, 2019 · 1 comment · Fixed by #1848
Closed

AliasTable method is not working for unbalanced values #832

s271 opened this issue Feb 20, 2019 · 1 comment · Fixed by #1848
Labels

Comments

@s271
Copy link

s271 commented Feb 20, 2019

Here is comparison of AliasTable and sample. sample working properly, AliasTable produce wrong result for values ~1e5 and more

using StatsBase
using Distributions
Random.seed!(1)

priorities = collect(1:1000) .* 1.
priorities[1:50] .= 1e8

isample = sample(1:1000, Weights(priorities), 16; replace=false)
_at = Distributions.AliasTable(priorities)
iat = rand(_at, 16)

println("sample ", priorities[isample])
println("AliasTable ", priorities[iat]) 

Results:
sample [1.0e8, 1.0e8, 1.0e8, 1.0e8, 1.0e8, 1.0e8, 1.0e8, 1.0e8, 1.0e8, 1.0e8, 1.0e8, 1.0e8, 1.0e8, 1.0e8, 1.0e8, 1.0e8]
AliasTable [94.0, 923.0, 388.0, 529.0, 334.0, 930.0, 630.0, 407.0, 396.0, 959.0, 215.0, 688.0, 704.0, 825.0, 524.0, 565.0]
AliasTable ignoring high-probability samples.

@simonbyrne
Copy link
Member

The priorities need to be normalised first:

_at = Distributions.AliasTable(priorities / sum(priorities))

gives the correct result.

We should check this.

LilithHafner added a commit to LilithHafner/Distributions.jl that referenced this issue Apr 8, 2024
devmotion added a commit that referenced this issue Apr 20, 2024
* switch to AliasTables.jl

* retune heuristic

* add test for #832

* add more tests

* move alias table import and tighten from using to import

* Back out multinomial heuristic adjustment at @adienes's request

* Update test/univariate/discrete/categorical.jl (style)

Co-authored-by: David Widmann <devmotion@users.noreply.github.com>

---------

Co-authored-by: David Widmann <devmotion@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants