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

Documentation sample() #876

Closed
leoluecken opened this issue Jul 4, 2023 · 2 comments
Closed

Documentation sample() #876

leoluecken opened this issue Jul 4, 2023 · 2 comments

Comments

@leoluecken
Copy link

Hi! I think the documentation of sample is a bit misleading. I'm referring to this page.

There, we have as a third variant of the function

sample([rng], a, [wv::AbstractWeights], dims::Dims; replace=true, ordered=false)

However, if I understand the source code correctly, there is no implementation of sample with weights, which supports the keyword flags. But I might be mistaken - in this case I appreciate correction.

Functions efraimidis_a_wsample_norep and efraimidis_ares_wsample_norep should should serve for the no-replacement version, right?

Thanks already!

@ararslan
Copy link
Member

ararslan commented Jul 5, 2023

if I understand the source code correctly, there is no implementation of sample with weights, which supports the keyword flags.

Is this not what you're after?:

julia> sample(1:10, uweights(10), 4; replace=true, ordered=true)
4-element Vector{Int64}:
 4
 5
 7
 9

Functions efraimidis_a_wsample_norep and efraimidis_ares_wsample_norep should should serve for the no-replacement version, right?

I'm surprised those functions are included in the manual as I didn't think they were intended to be user-facing; they aren't exported and the names are quite obscure. Efraimidis-Spirakis is used internally for weighted sampling without replacement but AFAIK that's an implementation detail.

@leoluecken
Copy link
Author

Yes, sorry for the invalid report! Your code works (replacement=false was, what I needed, but it works as well). I can't reproduce my non-working example, but probably I misinterpreted the error message, which said that no method ... exists, and overlooked the method definition in sampling.jl
Thank you for looking that up!!

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

2 participants