mirror of https://github.com/jlizier/jidt
add generateRotatedSurrogates method in RandomGenerator
This commit is contained in:
parent
1a994140b2
commit
191a81f1bc
|
|
@ -657,6 +657,39 @@ public class RandomGenerator {
|
|||
return setNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate numberOfRotations rotations of [0..n-1],
|
||||
* which are not necessarily distinct.
|
||||
* Could have double-ups even where the caller has asked for less
|
||||
* than the number of distinct rotations that exist.
|
||||
*
|
||||
* @param n
|
||||
* @param numberOfRotations
|
||||
* @return an array of dimensions [numberOfRotations][n], with each row
|
||||
* being one rotation of the elements
|
||||
*/
|
||||
public int[][] generateRotatedSurrogates(int n, int numberOfRotations) {
|
||||
|
||||
int[][] sets = new int[numberOfRotations][n];
|
||||
|
||||
// Use an array list because it gives RandomAccess to
|
||||
// the Collections.rotate method:
|
||||
ArrayList<Integer> list = new ArrayList<Integer>();
|
||||
for (int i = 0; i < n; i++) {
|
||||
list.add(i);
|
||||
}
|
||||
for (int s = 0; s < numberOfRotations; s++) {
|
||||
// Perform linear time rotations
|
||||
// Note: the rotations are all equal likelihood, no exclusion window for autocorrelation time
|
||||
int rotationAmount = random.nextInt(n);
|
||||
Collections.rotate(list, rotationAmount);
|
||||
for (int j = 0; j < n; j++) {
|
||||
sets[s][j] = list.get(j);
|
||||
}
|
||||
}
|
||||
return sets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate numberOfPerturbations perturbations of [0..n-1],
|
||||
* which are not necessarily distinct.
|
||||
|
|
@ -702,6 +735,7 @@ public class RandomGenerator {
|
|||
return sets;
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
// This code demonstrates that the Hashtable is hashing the
|
||||
// pointer rather than the array values -
|
||||
|
|
|
|||
Loading…
Reference in New Issue