Handbook
Glossary
<reservoir-sampler> ( k -- sampler )
Reservoir Sampling
Next:
reservoir-sample ( obj sampler -- )
Vocabulary
reservoir-sampling
Inputs
k
an
integer
Outputs
sampler
an
object
Word description
Creates an object that will hold k samples from everything it sees with equal probability. To show a reservoir-sampler an object, call
reservoir-sample
.
Definition
USING:
accessors
kernel
;
IN:
reservoir-sampling
:
<reservoir-sampler>
( k -- sampler )
reservoir-sampler
new
V{
}
clone
>>sampled
0
>>iteration
swap
>>k
;
inline