Skip to content

tmcw-up-for-adoption/stream-sample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

stream-sample

build status

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 = 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.

Installation

Requires nodejs.

$ npm install stream-sample

Tests

$ npm test

About

sample streams using reservoir sampling

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published