gps.util
Class PowerLaw

java.lang.Object
  extended by gps.util.PowerLaw

public class PowerLaw
extends java.lang.Object

provides power law selection. Modified by Weishuai Yang this file is based on T J Finney's Manuscripts Simulation Tool, 2001


Constructor Summary
PowerLaw()
          constructs a power law object using an internal random generator
PowerLaw(java.util.Random r)
          constructs a power law object using an external random generator
 
Method Summary
 double getRand()
          get uniformly distributed double in [0, 1]
 int getRandInt(int N)
          get uniformly distributed integer in [0, N - 1]
static void main(java.lang.String[] args)
          test purpose main
 int select(double[] nums, double p)
          selects item using power law probability of selecting array item: p(ni) = k * (ni^p) k is a normalisation constant p(ni) = 0 if ni is zero, even when p < 0
 int zipf(int size)
          select item using Zipf's law
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PowerLaw

public PowerLaw(java.util.Random r)
constructs a power law object using an external random generator

Parameters:
r - random generator passed in

PowerLaw

public PowerLaw()
constructs a power law object using an internal random generator

Method Detail

getRand

public double getRand()
get uniformly distributed double in [0, 1]


getRandInt

public int getRandInt(int N)
get uniformly distributed integer in [0, N - 1]


select

public int select(double[] nums,
                  double p)
selects item using power law probability of selecting array item: p(ni) = k * (ni^p) k is a normalisation constant p(ni) = 0 if ni is zero, even when p < 0

Parameters:
nums - array of numbers ni
p - exponent p
Returns:
index in [0, array size - 1]

zipf

public int zipf(int size)
select item using Zipf's law

Parameters:
size - of ranked array
Returns:
index in [0, array size - 1]

main

public static void main(java.lang.String[] args)
test purpose main

Parameters:
args - command line inputs