|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object
|
+--cern.colt.PersistentObject
|
+--cern.jet.random.sampling.RandomSamplingAssistant
Conveniently computes a stable Simple Random Sample Without Replacement (SRSWOR) subsequence of n elements from a given input sequence of N elements; Example: Computing a sublist of n=3 random elements from a list (1,...,50) may yield the sublist (7,13,47). The subsequence is guaranteed to be stable, i.e. elements never change position relative to each other. Each element from the N elements has the same probability to be included in the n chosen elements. This class is a convenience adapter for RandomSampler using blocks.
RandomSampler,
Serialized Form| Field Summary | |
protected long[] |
buffer
|
protected int |
bufferPosition
|
protected long |
n
|
protected RandomSampler |
sampler
|
protected long |
skip
|
| Constructor Summary | |
RandomSamplingAssistant(long n,
long N,
RandomElement randomGenerator)
Constructs a random sampler that samples n random elements from an input sequence of N elements. |
|
| Method Summary | |
java.lang.Object |
clone()
Returns a deep copy of the receiver. |
protected void |
fetchNextBlock()
Not yet commented. |
RandomElement |
getRandomGenerator()
Returns the used random generator. |
static void |
main(java.lang.String[] args)
Tests random sampling. |
static int[] |
sampleArray(int n,
int[] elements)
Just shows how this class can be used; samples n elements from and int[] array. |
boolean |
sampleNextElement()
Returns whether the next element of the input sequence shall be sampled (picked) or not. |
static void |
test(long n,
long N)
Tests the methods of this class. |
static void |
testArraySampling(int n,
int N)
Tests the methods of this class. |
| Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
protected RandomSampler sampler
protected long[] buffer
protected int bufferPosition
protected long skip
protected long n
| Constructor Detail |
public RandomSamplingAssistant(long n,
long N,
RandomElement randomGenerator)
n - the total number of elements to choose (must be >= 0).N - number of elements to choose from (must be >= n).randomGenerator - a random number generator. Set this parameter to null to use the default random number generator.| Method Detail |
public java.lang.Object clone()
clone in class PersistentObjectprotected void fetchNextBlock()
public RandomElement getRandomGenerator()
public static void main(java.lang.String[] args)
public static int[] sampleArray(int n,
int[] elements)
public boolean sampleNextElement()
public static void test(long n,
long N)
public static void testArraySampling(int n,
int N)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||