@apocentre/alias-sampling

0.5.3 • Public • Published

Alias Method for Sampling

Library for sampling of random values from a discrete probability distribution, using the Walker-Vose alias method.

Installation

yarn add @apocentre/aliasing

Usage

var s = sample([0.5, 0.25, 0.25], ['A', 'B', 'C']);
s.next(); // => random outcome according to specified probabilities
var s = sample([0.5, 0.25, 0.25], [10, 20, 30]);
s.next(1000); // => 1000 random samples according to specified probabilities
var s = sample([0.5, 0.25, 0.25]);
s.next(); // => random index according to specified probabilities
var rand = Math.rand; // custom random generator function
var s = sample([0.5, 0.25, 0.25], null, rand);
s.next(); // => random index according to specified probabilities

Have fun!

Build Status

Package Sidebar

Install

npm i @apocentre/alias-sampling

Weekly Downloads

22,816

Version

0.5.3

License

GPL

Unpacked Size

24.3 kB

Total Files

6

Last publish

Collaborators

  • antwnic4
  • nikosfotiadis
  • ppoliani