org.cicirello.replication.arxiv2019may.CompareKendallTauSequenceDistAlgsInts Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jpt-examples Show documentation
Show all versions of jpt-examples Show documentation
This package contains several example programs of
the usage of the JavaPermutationTools (JPT) library. JPT is a Java
library that enables representing and generating permutations and
sequences, as well as performing computation on permutations and
sequences. It includes implementations of a variety of permutation
distance metrics as well as distance metrics on sequences (i.e.,
Strings, arrays, and other ordered data types). In addition to
programs demonstrating the usage of the JPT library, the
jpt-examples package also contains programs for replicating the
experiments from a few published papers that utilized the library
or implementations on which the library is based. JPT's source code
is maintained on GitHub, and the prebuilt jars of the library can
be imported from Maven Central using maven or other build tools.
The purpose of the package jpt-examples is to demonstrate usage of
the major functionality of the JPT library. You can find out
more about the JPT library itself from its
website: https://jpt.cicirello.org/.
The newest version!
/*
* Example programs for JavaPermutationTools library.
* Copyright (C) 2019-2023 Vincent A. Cicirello
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
package org.cicirello.replication.arxiv2019may;
import java.lang.management.*;
import java.lang.ref.WeakReference;
import java.util.concurrent.ThreadLocalRandom;
import org.cicirello.examples.jpt.ExamplesShared;
import org.cicirello.sequences.distance.KendallTauSequenceDistance;
/**
* This program replicates the data for the paper:
* V.A. Cicirello, "Kendall Tau Sequence Distance: Extending Kendall Tau from Ranks to Sequences,"
* arXiv preprint arXiv:1905.02752 [cs.DM], May 2019.
*
* @author Vincent A. Cicirello, https://www.cicirello.org/
*/
public class CompareKendallTauSequenceDistAlgsInts {
private static int toTime(KendallTauSequenceDistance d, int[][] a, int[][] b) {
// Summing and returning the sum of distances is
// just to prevent the Java JIT from considering this dead code and optimizing it away.
int total = 0;
for (int i = 0; i < a.length; i++) {
int distance = d.distance(a[i], b[i]);
total += distance;
}
return total;
}
/**
* Runs the replication program.
*
* @param args Ignored, because there are no command line arguments.
*/
public static void main(String[] args) {
ExamplesShared.printCopyrightAndLicense();
KendallTauSequenceDistance dHash = new KendallTauSequenceDistance();
KendallTauSequenceDistance dSort = new KendallTauSequenceDistance(true);
final int MIN_L = 256;
final int MAX_L = 131072;
final int N = 100;
int[] alphabetSize = {1, 4, 16, 64, 256, 1024, 4096, 16384, 65536};
ThreadMXBean bean = ManagementFactory.getThreadMXBean();
bean.setThreadCpuTimeEnabled(true);
// WARM UP THE JAVA JIT.
int[][] iArrays = new int[N * N][];
int[][] iShuffled = new int[N * N][];
for (int i = 0; i < iArrays.length; i++) {
iArrays[i] = randIntSequence(1000, 100);
iShuffled[i] = shuffleCopy(iArrays[i]);
}
toTime(dHash, iArrays, iShuffled);
toTime(dSort, iArrays, iShuffled);
// force garbage collection of extra large arrays used during warmup
WeakReference ref1 = new WeakReference