/** * Make up the Q and A arrays for Walker's Alias method for sampling * from a discrete distribution with M terms. * Methodology: sort the distribution from low to high, move * probability from the highest to the lowest to bring the latter up * to 1/M; remove that cell and repeat with M-1 cells. */ import java.util.*; import static java.lang.System.err; public class walkerAlias { static Random rndm; static long seed; static int nTrials = 20000; //ggg double[] Q = null; int[] A = null; //ccc=== public walkerAlias(double[] targ) { int M = targ.length; Q = new double[M]; A = new int[M]; ArrayList rTarg = new ArrayList(); //remaining to allocate for( int i=0; i data, int rank[]) { int gap, len=data.size(); boolean done; int temp=0; for( int i=0; i=1 ) { do { done=true; for( int i=0; i dnr2[0] ) { temp = rank[i]; rank[i] = rank[i+gap]; rank[i+gap] = temp; done = false; } //end of if } //end of for } while(!done); //end of do.while gap = gap/2; } //end of while //err.println("Sorted data:"); //for( int k=0; k