[ 
https://issues.apache.org/jira/browse/RNG-99?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16830987#comment-16830987
 ] 

Gilles commented on RNG-99:
---------------------------

In the [reference|https://en.wikipedia.org/wiki/Alias_method], there is a 
section on efficiency.  Do you intend to provide a "combined" implementation 
that will select the best method according to the input(s)?

> AliasMethodDiscreteSampler
> --------------------------
>
>                 Key: RNG-99
>                 URL: https://issues.apache.org/jira/browse/RNG-99
>             Project: Commons RNG
>          Issue Type: New Feature
>          Components: sampling
>    Affects Versions: 1.3
>            Reporter: Alex D Herbert
>            Assignee: Alex D Herbert
>            Priority: Minor
>             Fix For: 1.3
>
>
> From Wikipedia:
> [Alias Method|https://en.wikipedia.org/wiki/Alias_method]
> {noformat}
> In computing, the alias method is a family of efficient algorithms for 
> sampling from a discrete probability distribution, due to A. J. Walker. That 
> is, it returns integer values 1 ≤ i ≤ n according to some arbitrary 
> probability distribution. The algorithms typically use O(n log n) or O(n) 
> preprocessing time, after which random values can be drawn from the 
> distribution in O(1) time.
> {noformat}
> Create a sampler using the Alias method:
> {code:java}
> package org.apache.commons.rng.sampling.distribution;
> public class AliasMethodDiscreteSampler implements DiscreteSampler {
>     public AliasMethodDiscreteSampler(UniformRandomProvider rng, 
>                                       double[] probabilities) {
>         // Validate probabilities sum to >0
>         // Construct alias tables
>     }
>     @Override
>     public int sample() {
>         // Sample from alias tables
>     }
> }
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to