com.softsynth.jmsl.util
Class WeightedIntegerSequence

java.lang.Object
  extended by com.softsynth.jmsl.util.SequencerGeneratorAdapter
      extended by com.softsynth.jmsl.util.WeightedIntegerSequence
All Implemented Interfaces:
SequenceGenerator

public class WeightedIntegerSequence
extends SequencerGeneratorAdapter

Define an array of weights where the weight of int i is associated with the value weights[i]
next() chooses an int 0..weights.length-1, following a weighted distribution


For example, the weight array { 1.0, 1.0 } will generate values 0 and 1 with a 50/50 distribution
The weight array { 1, 2, 1 } will generate ints 0, 1, 2, with the probability of 1 being chosen twice as high as the probability of 0 or 2 being chosen.


Author:
Nick Didkovsky, email: didkovn@mail.rockefeller.edu, (c) 2004 Nick Didkovsky, all rights reserved.

Constructor Summary
WeightedIntegerSequence(double[] weights)
          Loaded with indexes 0..weights.length, where each int is assigned the weight in weights[i]
 
Method Summary
 int[] getDistribution()
           
 int getNext()
          Peek ahead.
 double[] getWeights()
           
static void main(java.lang.String[] args)
           
 int next()
          Return next value in sequence, then generate a new one.
 void setNext(int next)
          UNIMPLEMENTED
 
Methods inherited from class com.softsynth.jmsl.util.SequencerGeneratorAdapter
getSeed, randomize, reset, setSeed
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WeightedIntegerSequence

public WeightedIntegerSequence(double[] weights)
Loaded with indexes 0..weights.length, where each int is assigned the weight in weights[i]

Method Detail

getDistribution

public int[] getDistribution()
Returns:
hit count for each int chosen in range 0..weights.length

getWeights

public double[] getWeights()

next

public int next()
Description copied from interface: SequenceGenerator
Return next value in sequence, then generate a new one.

Returns:
next int in range 0..weights.length(), weighted random choice

setNext

public void setNext(int next)
UNIMPLEMENTED

See Also:
SequenceGenerator.setNext(int)

getNext

public int getNext()
Peek ahead. @return next() without actually advancing the sequence

Specified by:
getNext in interface SequenceGenerator
Overrides:
getNext in class SequencerGeneratorAdapter
Returns:
next without changing current state

main

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