stream-sample
sample streams using reservoir sampling
stream-sample
Stream sampling uses a reservoir.
This implements the reservoir sampling algorithm that allows you to glean a statistically valid fixed-size sample from an unknown-size input while keeping only the sample in memory.
This module is different than the reservoir-stream module that requires the full input to be concatenated in memory.`
streamSample(sampleCount)
Create a transform stream that emits an evenly-distributed
sample of sampleCount
items for every new item received.
Parameters
parameter | type | description |
---|---|---|
sampleCount |
Number | the number of elements to be placed in the sample. |
Example
var streamSample = ; var sampler = ; sampler; for var i = 0; i < 100; i++ sampler;
Returns Stream.Transform
, a transform stream that samples the input.
Installation
Requires nodejs.
$ npm install stream-sample
Tests
$ npm test