Skip to content

thara/elixir_alias_method

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AliasMethod

Hex.pm Elixir CI

Implementation of Walker's Alias method by Elixir. The algorithm is principally useful when you need to random sampling with replacement by O(1).

Installation

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

Example

iex> weights = [1, 1, 8]
iex> table = AliasMethod.generate_table(weights)
iex> table
%AliasMethod.Table{alias_table: %{0 => 2, 1 => 2, 2 => 0}, length: 3, probability_table: %{0 => 0.3, 1 => 0.3, 2 => 1.0}}

iex> n = AliasMethod.choice(table)
iex> 0 <= n && n <= table.length
true

License

This project is licensed under the MIT License - see the LICENSE file for details

Author

Tomochika Hara - thara

About

Implementation of Walker's Alias method in Elixir

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages