Skip to content

Commit df10c32

Browse files
committed
Added arxiv:1905.02752 replication programs
1 parent 4941f85 commit df10c32

File tree

4 files changed

+475
-0
lines changed

4 files changed

+475
-0
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
* Copyright 2018-2019 Vincent A. Cicirello, <https://www.cicirello.org/>.
3+
*
4+
* This file is part of JavaPermutationTools (https://jpt.cicirello.org/).
5+
*
6+
* JavaPermutationTools is free software: you can
7+
* redistribute it and/or modify it under the terms of the GNU
8+
* General Public License as published by the Free Software
9+
* Foundation, either version 3 of the License, or (at your
10+
* option) any later version.
11+
*
12+
* JavaPermutationTools is distributed in the hope
13+
* that it will be useful, but WITHOUT ANY WARRANTY; without even
14+
* the implied warranty of MERCHANTABILITY or FITNESS FOR A
15+
* PARTICULAR PURPOSE. See the GNU General Public License for more
16+
* details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with JavaPermutationTools. If not, see <http://www.gnu.org/licenses/>.
20+
*
21+
*/
22+
package org.cicirello.replication.arxiv2019may;
23+
24+
import org.cicirello.sequences.distance.KendallTauSequenceDistance;
25+
import java.util.concurrent.ThreadLocalRandom;
26+
import java.lang.management.*;
27+
28+
/**
29+
* <p>This program replicates the data for the paper:<br>
30+
* V.A. Cicirello, <a href="https://www.cicirello.org/publications/cicirello2019arXiv.html">"Kendall Tau
31+
* Sequence Distance: Extending Kendall Tau from Ranks to Sequences,"</a>
32+
* arXiv preprint arXiv:1905.02752 [cs.DM], May 2019.</p>
33+
*
34+
* @author <a href=https://www.cicirello.org/>Vincent A. Cicirello</a>, <a href=https://www.cicirello.org/>https://www.cicirello.org/</a>
35+
*/
36+
public class CompareKendallTauSequenceDistAlgsDoubles {
37+
38+
public static void main(String[] args) {
39+
KendallTauSequenceDistance dHash = new KendallTauSequenceDistance();
40+
KendallTauSequenceDistance dSort = new KendallTauSequenceDistance(true);
41+
final int MIN_L = 256;
42+
final int MAX_L = 131072;
43+
final int N = 100;
44+
int[] alphabetSize = {1, 4, 16, 64, 256, 1024, 4096, 16384, 65536};
45+
ThreadMXBean bean = ManagementFactory.getThreadMXBean();
46+
System.out.printf("%8s\t%8s\t%8s\t%8s\n", "L", "Alphabet", "TimeHash", "TimeSort");
47+
for (int L = MIN_L; L <= MAX_L; L *= 2) {
48+
for (int j = 0; j < alphabetSize.length; j++) {
49+
int R = alphabetSize[j];
50+
//if (R < 1) R = 1;
51+
double[][] iArrays = new double[N][];
52+
double[][] iShuffled = new double[N][];
53+
for (int i = 0; i < N; i++) {
54+
iArrays[i] = randDoubleSequence(L, R);
55+
iShuffled[i] = shuffleCopy(iArrays[i]);
56+
}
57+
System.out.printf("%8d\t%8d", L, R);
58+
long start = bean.getCurrentThreadCpuTime();
59+
for (int i = 0; i < N; i++) {
60+
int d = dHash.distance(iArrays[i], iShuffled[i]);
61+
}
62+
long end = bean.getCurrentThreadCpuTime();
63+
double seconds = 1.0*(end-start)/1000000000/N;
64+
System.out.printf("\t%8.6f", seconds);
65+
start = bean.getCurrentThreadCpuTime();
66+
for (int i = 0; i < N; i++) {
67+
int d = dSort.distance(iArrays[i], iShuffled[i]);
68+
}
69+
end = bean.getCurrentThreadCpuTime();
70+
seconds = 1.0*(end-start)/1000000000/N;
71+
System.out.printf("\t%8.6f", seconds);
72+
System.out.println();
73+
}
74+
}
75+
}
76+
77+
78+
public static double[] shuffleCopy(double[] s) {
79+
double[] r = s.clone();
80+
for (int i = s.length-1; i > 0; i--) {
81+
int j = ThreadLocalRandom.current().nextInt(i+1);
82+
if (i==j) continue;
83+
double temp = r[i];
84+
r[i] = r[j];
85+
r[j] = temp;
86+
}
87+
return r;
88+
}
89+
90+
91+
92+
public static double[] randDoubleSequence(int length, int range) {
93+
double[] s = new double[length];
94+
for (int i = 0; i < length; i++) {
95+
s[i] = 1.0*ThreadLocalRandom.current().nextInt(range);
96+
}
97+
return s;
98+
}
99+
100+
101+
102+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
* Copyright 2018-2019 Vincent A. Cicirello, <https://www.cicirello.org/>.
3+
*
4+
* This file is part of JavaPermutationTools (https://jpt.cicirello.org/).
5+
*
6+
* JavaPermutationTools is free software: you can
7+
* redistribute it and/or modify it under the terms of the GNU
8+
* General Public License as published by the Free Software
9+
* Foundation, either version 3 of the License, or (at your
10+
* option) any later version.
11+
*
12+
* JavaPermutationTools is distributed in the hope
13+
* that it will be useful, but WITHOUT ANY WARRANTY; without even
14+
* the implied warranty of MERCHANTABILITY or FITNESS FOR A
15+
* PARTICULAR PURPOSE. See the GNU General Public License for more
16+
* details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with JavaPermutationTools. If not, see <http://www.gnu.org/licenses/>.
20+
*
21+
*/
22+
package org.cicirello.replication.arxiv2019may;
23+
24+
import org.cicirello.sequences.distance.KendallTauSequenceDistance;
25+
import java.util.concurrent.ThreadLocalRandom;
26+
import java.lang.management.*;
27+
28+
/**
29+
* <p>This program replicates the data for the paper:<br>
30+
* V.A. Cicirello, <a href="https://www.cicirello.org/publications/cicirello2019arXiv.html">"Kendall Tau
31+
* Sequence Distance: Extending Kendall Tau from Ranks to Sequences,"</a>
32+
* arXiv preprint arXiv:1905.02752 [cs.DM], May 2019.</p>
33+
*
34+
* @author <a href=https://www.cicirello.org/>Vincent A. Cicirello</a>, <a href=https://www.cicirello.org/>https://www.cicirello.org/</a>
35+
*/
36+
public class CompareKendallTauSequenceDistAlgsInts {
37+
38+
public static void main(String[] args) {
39+
KendallTauSequenceDistance dHash = new KendallTauSequenceDistance();
40+
KendallTauSequenceDistance dSort = new KendallTauSequenceDistance(true);
41+
final int MIN_L = 256;
42+
final int MAX_L = 131072;
43+
final int N = 100;
44+
int[] alphabetSize = {1, 4, 16, 64, 256, 1024, 4096, 16384, 65536};
45+
ThreadMXBean bean = ManagementFactory.getThreadMXBean();
46+
System.out.printf("%8s\t%8s\t%8s\t%8s\n", "L", "Alphabet", "TimeHash", "TimeSort");
47+
for (int L = MIN_L; L <= MAX_L; L *= 2) {
48+
for (int j = 0; j < alphabetSize.length; j++) {
49+
int R = alphabetSize[j];
50+
//if (R < 1) R = 1;
51+
int[][] iArrays = new int[N][];
52+
int[][] iShuffled = new int[N][];
53+
for (int i = 0; i < N; i++) {
54+
iArrays[i] = randIntSequence(L, R);
55+
iShuffled[i] = shuffleCopy(iArrays[i]);
56+
}
57+
System.out.printf("%8d\t%8d", L, R);
58+
long start = bean.getCurrentThreadCpuTime();
59+
for (int i = 0; i < N; i++) {
60+
int d = dHash.distance(iArrays[i], iShuffled[i]);
61+
}
62+
long end = bean.getCurrentThreadCpuTime();
63+
double seconds = 1.0*(end-start)/1000000000/N;
64+
System.out.printf("\t%8.6f", seconds);
65+
start = bean.getCurrentThreadCpuTime();
66+
for (int i = 0; i < N; i++) {
67+
int d = dSort.distance(iArrays[i], iShuffled[i]);
68+
}
69+
end = bean.getCurrentThreadCpuTime();
70+
seconds = 1.0*(end-start)/1000000000/N;
71+
System.out.printf("\t%8.6f", seconds);
72+
System.out.println();
73+
}
74+
}
75+
}
76+
77+
78+
public static int[] shuffleCopy(int[] s) {
79+
int[] r = s.clone();
80+
for (int i = s.length-1; i > 0; i--) {
81+
int j = ThreadLocalRandom.current().nextInt(i+1);
82+
if (i==j) continue;
83+
int temp = r[i];
84+
r[i] = r[j];
85+
r[j] = temp;
86+
}
87+
return r;
88+
}
89+
90+
91+
92+
public static int[] randIntSequence(int length, int range) {
93+
int[] s = new int[length];
94+
for (int i = 0; i < length; i++) {
95+
s[i] = ThreadLocalRandom.current().nextInt(range);
96+
}
97+
return s;
98+
}
99+
100+
101+
102+
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
* Copyright 2018-2019 Vincent A. Cicirello, <https://www.cicirello.org/>.
3+
*
4+
* This file is part of JavaPermutationTools (https://jpt.cicirello.org/).
5+
*
6+
* JavaPermutationTools is free software: you can
7+
* redistribute it and/or modify it under the terms of the GNU
8+
* General Public License as published by the Free Software
9+
* Foundation, either version 3 of the License, or (at your
10+
* option) any later version.
11+
*
12+
* JavaPermutationTools is distributed in the hope
13+
* that it will be useful, but WITHOUT ANY WARRANTY; without even
14+
* the implied warranty of MERCHANTABILITY or FITNESS FOR A
15+
* PARTICULAR PURPOSE. See the GNU General Public License for more
16+
* details.
17+
*
18+
* You should have received a copy of the GNU General Public License
19+
* along with JavaPermutationTools. If not, see <http://www.gnu.org/licenses/>.
20+
*
21+
*/
22+
package org.cicirello.replication.arxiv2019may;
23+
24+
import org.cicirello.sequences.distance.KendallTauSequenceDistance;
25+
import java.util.concurrent.ThreadLocalRandom;
26+
import java.lang.management.*;
27+
28+
/**
29+
* <p>This program replicates the data for the paper:<br>
30+
* V.A. Cicirello, <a href="https://www.cicirello.org/publications/cicirello2019arXiv.html">"Kendall Tau
31+
* Sequence Distance: Extending Kendall Tau from Ranks to Sequences,"</a>
32+
* arXiv preprint arXiv:1905.02752 [cs.DM], May 2019.</p>
33+
*
34+
* @author <a href=https://www.cicirello.org/>Vincent A. Cicirello</a>, <a href=https://www.cicirello.org/>https://www.cicirello.org/</a>
35+
*/
36+
public class CompareKendallTauSequenceDistAlgsString {
37+
38+
public static void main(String[] args) {
39+
KendallTauSequenceDistance dHash = new KendallTauSequenceDistance();
40+
KendallTauSequenceDistance dSort = new KendallTauSequenceDistance(true);
41+
final int MIN_L = 256;
42+
final int MAX_L = 131072;
43+
final int N = 100;
44+
int[] alphabetSize = {1, 4, 16, 64, 256, 1024, 4096, 16384, 65536};
45+
ThreadMXBean bean = ManagementFactory.getThreadMXBean();
46+
System.out.printf("%8s\t%8s\t%8s\t%8s\n", "L", "Alphabet", "TimeHash", "TimeSort");
47+
for (int L = MIN_L; L <= MAX_L; L *= 2) {
48+
for (int j = 0; j < alphabetSize.length; j++) {
49+
int R = alphabetSize[j];
50+
//if (R < 1) R = 1;
51+
String[] sArray = new String[N];
52+
String[] sShuffled = new String[N];
53+
for (int i = 0; i < N; i++) {
54+
sArray[i] = randString(L, R);
55+
sShuffled[i] = shuffleCopy(sArray[i]);
56+
}
57+
System.out.printf("%8d\t%8d", L, R);
58+
long start = bean.getCurrentThreadCpuTime();
59+
for (int i = 0; i < N; i++) {
60+
int d = dHash.distance(sArray[i], sShuffled[i]);
61+
}
62+
long end = bean.getCurrentThreadCpuTime();
63+
double seconds = 1.0*(end-start)/1000000000/N;
64+
System.out.printf("\t%8.6f", seconds);
65+
start = bean.getCurrentThreadCpuTime();
66+
for (int i = 0; i < N; i++) {
67+
int d = dSort.distance(sArray[i], sShuffled[i]);
68+
}
69+
end = bean.getCurrentThreadCpuTime();
70+
seconds = 1.0*(end-start)/1000000000/N;
71+
System.out.printf("\t%8.6f", seconds);
72+
73+
74+
System.out.println();
75+
}
76+
}
77+
}
78+
79+
80+
81+
82+
public static String shuffleCopy(String s) {
83+
char[] c = s.toCharArray();
84+
for (int i = c.length-1; i > 0; i--) {
85+
int j = ThreadLocalRandom.current().nextInt(i+1);
86+
if (i==j) continue;
87+
char temp = c[i];
88+
c[i] = c[j];
89+
c[j] = temp;
90+
}
91+
return new String(c);
92+
}
93+
94+
95+
96+
public static String randString(int length, int range) {
97+
char[] s = new char[length];
98+
for (int i = 0; i < length; i++) {
99+
s[i] = (char)ThreadLocalRandom.current().nextInt(range);
100+
}
101+
return new String(s);
102+
}
103+
104+
105+
106+
}

0 commit comments

Comments
 (0)