diff --git a/.muse.toml b/.muse.toml new file mode 100644 index 00000000..72d0f660 --- /dev/null +++ b/.muse.toml @@ -0,0 +1,21 @@ +# don't run eslint... it is for js and will detect false positives +# in javadoc directories. + +disableTools = ["eslint"] + +# Ignore warnings not relevant to this specific project: +# +# 1) FindSecBugs identifies our use of ThreadLocalRandom as predictable. +# We make extensive use of this class for randomness. Our use of randomness +# in this library is NOT at all security related, and rather, we simply need +# a fast pseudorandom number generator since we need to generate large +# numbers of random numbers. So ignore predictable random warnings. + +ignore = ["PREDICTABLE_RANDOM"] + +# Ignore results from these directories + +ignoreFiles = """ +docs/api/jquery/ +tests/ +""" \ No newline at end of file diff --git a/src/org/cicirello/math/MathFunctions.java b/src/org/cicirello/math/MathFunctions.java index 29c6c685..f3e9b030 100644 --- a/src/org/cicirello/math/MathFunctions.java +++ b/src/org/cicirello/math/MathFunctions.java @@ -26,7 +26,7 @@ * MathFunctions is a class of utility methods that implement various mathematical functions. * * @author Vincent A. Cicirello, https://www.cicirello.org/ - * @version 2.12.2021 + * @version 5.13.2021 * */ public final class MathFunctions { @@ -92,7 +92,7 @@ public static double logGamma(double n) { // This check doesn't seem to be necessary given addition of first check in block. // if (z == 0.0) return Double.POSITIVE_INFINITY; // ln(PI) - final double LOG_PI = 1.14472988584940017414; + final double LOG_PI = 1.1447298858494002; return LOG_PI - Math.log(z) - logGamma(n); } else if (n < 13.0) { double z = 1.0; @@ -117,13 +117,13 @@ public static double logGamma(double n) { n * evaluatePolynomial(n, POLY_APPROX_2) / evaluatePolynomial(n, POLY_APPROX_3); } else { // ln(sqrt(2pi)) - final double LOG_SQRT_PI2 = 0.91893853320467274178; + final double LOG_SQRT_PI2 = 0.9189385332046727; double q = (n - 0.5) * Math.log(n) - n + LOG_SQRT_PI2; if (n > 1.0e8) return q; double p = 1.0 / (n * n); if (n >= 1000.0) { - q = q + ((7.9365079365079365079365e-4 * p - 2.7777777777777777777778e-3) - * p + 0.0833333333333333333333) / n; + q = q + ((7.936507936507937E-4 * p - 0.002777777777777778) + * p + 0.08333333333333333) / n; } else { q += evaluatePolynomial(p, STIRLING_EXPANSION_LN_GAMMA) / n; } @@ -142,21 +142,22 @@ private static double evaluatePolynomial(double x, double polynomial[]) { } private static final double[] STIRLING_EXPANSION_LN_GAMMA = { - 8.11614167470508450300E-4, -5.95061904284301438324E-4, - 7.93650340457716943945E-4, -2.77777777730099687205E-3, - 8.33333333333331927722E-2 + 8.116141674705085E-4, -5.950619042843014E-4, + 7.936503404577169E-4, -0.002777777777300997, + 0.08333333333333319 }; private static final double[] POLY_APPROX_2 = { - -1.37825152569120859100E3, -3.88016315134637840924E4, - -3.31612992738871184744E5, -1.16237097492762307383E6, - -1.72173700820839662146E6, -8.53555664245765465627E5 + -1378.2515256912086, -38801.631513463784, + -331612.9927388712, -1162370.974927623, + -1721737.0082083966, -853555.6642457654 }; private static final double[] POLY_APPROX_3 = { - 1.0, -3.51815701436523470549E2, -1.70642106651881159223E4, - -2.20528590553854454839E5, -1.13933444367982507207E6, - -2.53252307177582951285E6, -2.01889141433532773231E6 + 1.0, + -351.81570143652345, -17064.210665188115, + -220528.59055385445, -1139334.4436798252, + -2532523.0717758294, -2018891.4143353277, }; // HELPERS FOR logGamma END HERE diff --git a/src/org/cicirello/math/la/MatrixOps.java b/src/org/cicirello/math/la/MatrixOps.java index 7d79f692..25af34b3 100644 --- a/src/org/cicirello/math/la/MatrixOps.java +++ b/src/org/cicirello/math/la/MatrixOps.java @@ -27,7 +27,7 @@ * represented as 2-D Java arrays. * * @author Vincent A. Cicirello, https://www.cicirello.org/ - * @version 2.13.2021 + * @version 5.13.2021 */ public final class MatrixOps { @@ -235,7 +235,7 @@ public static double[][] difference(double[][] A, double[][] B) { * @return A reference to the C matrix. */ public static int[][] product(int[][] A, int[][] B, int[][] C) { - if (A.length == 0 && B.length > 0 || A.length > 0 && B.length == 0) { + if ((A.length == 0 && B.length > 0) || (A.length > 0 && B.length == 0)) { throw new IllegalArgumentException("If either matrix has 0 rows, both must."); } else if (A.length == 0) { if (C==null) return new int[0][0]; @@ -267,7 +267,7 @@ public static int[][] product(int[][] A, int[][] B, int[][] C) { * @return A reference to the C matrix. */ public static double[][] product(double[][] A, double[][] B, double[][] C) { - if (A.length == 0 && B.length > 0 || A.length > 0 && B.length == 0) { + if ((A.length == 0 && B.length > 0) || (A.length > 0 && B.length == 0)) { throw new IllegalArgumentException("If either matrix has 0 rows, both must."); } else if (A.length == 0) { if (C==null) return new double[0][0]; diff --git a/src/org/cicirello/math/rand/RandomIndexer.java b/src/org/cicirello/math/rand/RandomIndexer.java index d20627a4..11d69060 100644 --- a/src/org/cicirello/math/rand/RandomIndexer.java +++ b/src/org/cicirello/math/rand/RandomIndexer.java @@ -33,7 +33,7 @@ * from the motivating case, the case of efficiently generating random indexes into an array. * * @author Vincent A. Cicirello, https://www.cicirello.org/ - * @version 2.13.2021 + * @version 5.13.2021 * */ public final class RandomIndexer { @@ -152,7 +152,7 @@ public static int nextInt(int bound, Random gen) { */ public static int nextBiasedInt(int bound) { if (bound < 1) throw new IllegalArgumentException("bound must be positive"); - return (int)((long)(ThreadLocalRandom.current().nextInt() & 0x7fffffff) * (long)bound >> 31); + return (int)(((long)(ThreadLocalRandom.current().nextInt() & 0x7fffffff) * (long)bound) >> 31); } /** @@ -178,7 +178,7 @@ public static int nextBiasedInt(int bound) { */ public static int nextBiasedInt(int bound, SplittableRandom gen) { if (bound < 1) throw new IllegalArgumentException("bound must be positive"); - return (int)((long)(gen.nextInt() & 0x7fffffff) * (long)bound >> 31); + return (int)(((long)(gen.nextInt() & 0x7fffffff) * (long)bound) >> 31); } /** @@ -211,7 +211,7 @@ public static int nextBiasedInt(int bound, SplittableRandom gen) { */ public static int nextBiasedInt(int bound, Random gen) { if (bound < 1) throw new IllegalArgumentException("bound must be positive"); - return (int)((long)(gen.nextInt() & 0x7fffffff) * (long)bound >> 31); + return (int)(((long)(gen.nextInt() & 0x7fffffff) * (long)bound) >> 31); } diff --git a/src/org/cicirello/math/stats/Statistics.java b/src/org/cicirello/math/stats/Statistics.java index 7076ea61..7e81ab05 100644 --- a/src/org/cicirello/math/stats/Statistics.java +++ b/src/org/cicirello/math/stats/Statistics.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2020 Vincent A. Cicirello, . + * Copyright 2018-2021 Vincent A. Cicirello, . * * This file is part of JavaPermutationTools (https://jpt.cicirello.org/). * @@ -26,7 +26,7 @@ * Utility class of basic statistics. * * @author Vincent A. Cicirello, https://www.cicirello.org/ - * @version 09-18-2020 + * @version 5.13.2021 */ public final class Statistics { @@ -39,11 +39,9 @@ private Statistics() {} * @return the mean of the data. */ public static double mean(int[] data) { - double mean = 0; int sum = 0; for (int e : data) sum = sum + e; - mean = 1.0 * sum / data.length; - return mean; + return 1.0 * sum / data.length; } /** diff --git a/src/org/cicirello/permutations/distance/KendallTauDistance.java b/src/org/cicirello/permutations/distance/KendallTauDistance.java index 49ed5899..1233801c 100644 --- a/src/org/cicirello/permutations/distance/KendallTauDistance.java +++ b/src/org/cicirello/permutations/distance/KendallTauDistance.java @@ -48,7 +48,7 @@ * M. G. Kendall, "A new measure of rank correlation," Biometrika, vol. 30, no. 1/2, pp. 81–93, June 1938.

* * @author Vincent A. Cicirello, https://www.cicirello.org/ - * @version 4.2.2021 + * @version 5.13.2021 * */ public final class KendallTauDistance implements NormalizedPermutationDistanceMeasurer { @@ -83,7 +83,7 @@ public int distance(Permutation p1, Permutation p2) { @Override public int max(int length) { if (length <= 1) return 0; - return length*(length - 1)>>1; + return (length*(length - 1))>>1; } private int countInversions(int[] array) { diff --git a/src/org/cicirello/permutations/distance/ReversalDistance.java b/src/org/cicirello/permutations/distance/ReversalDistance.java index 8c8b5610..93676ce5 100644 --- a/src/org/cicirello/permutations/distance/ReversalDistance.java +++ b/src/org/cicirello/permutations/distance/ReversalDistance.java @@ -48,7 +48,7 @@ *

We have not used this for N > 10. Warning: time to construct distance measure increases factorially.

* * @author Vincent A. Cicirello, https://www.cicirello.org/ -* @version 4.2.2021 +* @version 5.13.2021 */ public final class ReversalDistance implements NormalizedPermutationDistanceMeasurer { @@ -128,7 +128,7 @@ public int distance(Permutation p1, Permutation p2) { for (int i = 0; i < inv1.length; i++) { r2[i] = inv1[p2.get(i)]; } - return dist[(new Permutation(r2)).toInteger()]; + return dist[new Permutation(r2).toInteger()]; } /** diff --git a/src/org/cicirello/sequences/distance/KendallTauSequenceDistance.java b/src/org/cicirello/sequences/distance/KendallTauSequenceDistance.java index ab79aa45..cc65b70f 100644 --- a/src/org/cicirello/sequences/distance/KendallTauSequenceDistance.java +++ b/src/org/cicirello/sequences/distance/KendallTauSequenceDistance.java @@ -20,7 +20,6 @@ */ package org.cicirello.sequences.distance; - import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -77,7 +76,7 @@ * Industrial Networks and Intelligent Systems, 7(23), Article e1, April 2020.

* * @author Vincent A. Cicirello, https://www.cicirello.org/ - * @version 4.2.2021 + * @version 5.13.2021 */ public final class KendallTauSequenceDistance implements SequenceDistanceMeasurer {