JuliaStats / StatsBase.jl

Basic statistics for Julia

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Documentation `sample()`

leoluecken opened this issue · comments

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!

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.

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!!