WAM

Pure Elixir implementation of Walker’s Alias Method (WAM). It’s method for performing weighted random sampling.

Installation

If available in Hex, the package can be installed by adding wam to your list of dependencies in mix.exs:

def deps do
  [
    {:wam, "~> 0.1.0"}
  ]
end

Usage

It supports both weights and probabilities.

wam = WAM.new(%{a: 10, b: 4, c: 5})
wam = WAM.new(%{a: 10 / 19, b: 4 / 19, c: 5 / 19})

Also it supports list of tuples and two lists:

wam = WAM.new([{:a, 10}, {:b, 4}, {:c, 5}])
wam = WAM.new([:a, :b, :c], [10, 4, 5])

And provides three functions to work with random sampling:

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/wam.