sample streams using reservoir sampling
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.`
Create a transform stream that emits an evenly-distributed
sample of sampleCount
items for every new item received.
parameter | type | description |
---|---|---|
sampleCount |
Number | the number of elements to be placed in the sample. |
var streamSample = require('stream-sample');
var sampler = streamSample(10);
sampler.on('data', function(sample) {
// sample is n items from the stream
});
for (var i = 0; i < 100; i++) sampler.push(Math.random());
Returns Stream.Transform
, a transform stream that samples the input.
Requires nodejs.
$ npm install stream-sample
$ npm test