Package cern.jet.random.sampling
Class WeightedRandomSampler
- java.lang.Object
-
- cern.colt.PersistentObject
-
- cern.jet.random.sampling.WeightedRandomSampler
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
public class WeightedRandomSampler extends PersistentObject
Conveniently computes a stable subsequence of elements from a given input sequence; Picks (samples) exactly one random element from successive blocks of weight input elements each. For example, if weight==2 (a block is 2 elements), and the input is 5*2=10 elements long, then picks 5 random elements from the 10 elements such that one element is randomly picked from the first block, one element from the second block, ..., one element from the last block. weight == 1.0 --> all elements are picked (sampled). weight == 10.0 --> Picks one random element from successive blocks of 10 elements each. Etc. The subsequence is guaranteed to be stable, i.e. elements never change position relative to each other.- Version:
- 1.0, 02/05/99
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected Uniform
generator
protected int
nextSkip
protected int
nextTriggerPos
protected int
skip
(package private) static int
UNDEFINED
protected int
weight
-
Fields inherited from class cern.colt.PersistentObject
serialVersionUID
-
-
Constructor Summary
Constructors Constructor Description WeightedRandomSampler()
Calls BlockedRandomSampler(1,null).WeightedRandomSampler(int weight, RandomEngine randomGenerator)
Chooses exactly one random element from successive blocks of weight input elements each.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
clone()
Returns a deep copy of the receiver.int
getWeight()
Not yet commented.boolean
sampleNextElement()
Chooses exactly one random element from successive blocks of weight input elements each.void
setWeight(int weight)
Not yet commented.static void
test(int weight, int size)
Not yet commented.private void
xsampleNextElements(BooleanArrayList acceptList)
Chooses exactly one random element from successive blocks of weight input elements each.
-
-
-
Field Detail
-
skip
protected int skip
-
nextTriggerPos
protected int nextTriggerPos
-
nextSkip
protected int nextSkip
-
weight
protected int weight
-
generator
protected Uniform generator
-
UNDEFINED
static final int UNDEFINED
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
WeightedRandomSampler
public WeightedRandomSampler()
Calls BlockedRandomSampler(1,null).
-
WeightedRandomSampler
public WeightedRandomSampler(int weight, RandomEngine randomGenerator)
Chooses exactly one random element from successive blocks of weight input elements each. For example, if weight==2, and the input is 5*2=10 elements long, then chooses 5 random elements from the 10 elements such that one is chosen from the first block, one from the second, ..., one from the last block. weight == 1.0 --> all elements are consumed (sampled). 10.0 --> Consumes one random element from successive blocks of 10 elements each. Etc.- Parameters:
weight
- the weight.randomGenerator
- a random number generator. Set this parameter to null to use the default random number generator.
-
-
Method Detail
-
clone
public java.lang.Object clone()
Returns a deep copy of the receiver.- Overrides:
clone
in classPersistentObject
- Returns:
- a copy of the receiver.
-
getWeight
public int getWeight()
Not yet commented.- Parameters:
weight
- int
-
sampleNextElement
public boolean sampleNextElement()
Chooses exactly one random element from successive blocks of weight input elements each. For example, if weight==2, and the input is 5*2=10 elements long, then chooses 5 random elements from the 10 elements such that one is chosen from the first block, one from the second, ..., one from the last block.- Returns:
- true if the next element shall be sampled (picked), false otherwise.
-
setWeight
public void setWeight(int weight)
Not yet commented.- Parameters:
weight
- int
-
test
public static void test(int weight, int size)
Not yet commented.
-
xsampleNextElements
private void xsampleNextElements(BooleanArrayList acceptList)
Chooses exactly one random element from successive blocks of weight input elements each. For example, if weight==2, and the input is 5*2=10 elements long, then chooses 5 random elements from the 10 elements such that one is chosen from the first block, one from the second, ..., one from the last block.- Parameters:
acceptList
- a bitvector which will be filled with true where sampling shall occur and false where it shall not occur.
-
-