Project

vose

0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
Vose: Sample random values from a discrete probability distribution.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

 Project Readme

Vose: Sample random values from a discrete probability distribution.

Vose is a Ruby implementation of the Vose Alias Method. It allows for sampling of random values from a discrete probability distribution. In simpler terms, this gem simulates a loaded die. This implementation runs in O(1) time after after a O(n) initialization.

For more information on the theory, have a look at Darts, Dice, and Coins: Sampling from a Discrete Distribution

Installation

To track the latest officially released gem:

gem 'vose' # for the latest officially released gem

OR To track the git repo

gem 'vose', :git => "git://github.com/thunderboltlabs/vose.git"

And then execute:

$ bundle

Or install it yourself as:

$ gem install vose

Usage

probabilities = [0.4, 0.1, 0.2, 0.3]
vose = Vose::AliasMethod.new probabilities
choice = vose.next # => an int

The choice will be an index of the probabilities array.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request