Package com.softsynth.jmsl.util
Class WeightedIntegerSequence
java.lang.Object
com.softsynth.jmsl.util.SequencerGeneratorAdapter
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.
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: nick@didkovsky.com, (c) 2004 Nick Didkovsky, all rights reserved.
-
Constructor Summary
Constructors Constructor Description WeightedIntegerSequence(double[] weights)
Loaded with indexes 0..weights.length, where each int is assigned the weight in weights[i] -
Method Summary
Modifier and Type Method Description 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)
UNIMPLEMENTEDMethods 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 Details
-
WeightedIntegerSequence
public WeightedIntegerSequence(double[] weights)Loaded with indexes 0..weights.length, where each int is assigned the weight in weights[i]
-
-
Method Details
-
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 interfaceSequenceGenerator
- Overrides:
getNext
in classSequencerGeneratorAdapter
- Returns:
- next without changing current state
-
main
public static void main(java.lang.String[] args)
-