You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ah...@apache.org on 2020/02/13 12:13:43 UTC

[commons-rng] branch master updated (e92e01a -> e92c4ce)

This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-rng.git.


    from e92e01a  Update the package name of the MersenneTwister in the LICENSE.txt
     new 88110c2  Disable PMD for the JMH module.
     new e92c4ce  Fix spotbugs for the JMH module.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 commons-rng-examples/examples-jmh/pom.xml          |  2 ++
 .../EnumeratedDistributionSamplersPerformance.java | 36 +++++++++++++---------
 pom.xml                                            |  3 ++
 .../resources/spotbugs/spotbugs-exclude-filter.xml | 10 ++++++
 4 files changed, 36 insertions(+), 15 deletions(-)


[commons-rng] 02/02: Fix spotbugs for the JMH module.

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-rng.git

commit e92c4cebf7a79854e79d91c73d801d4d54be1110
Author: aherbert <ah...@apache.org>
AuthorDate: Thu Feb 13 11:41:55 2020 +0000

    Fix spotbugs for the JMH module.
---
 .../EnumeratedDistributionSamplersPerformance.java | 36 +++++++++++++---------
 .../resources/spotbugs/spotbugs-exclude-filter.xml | 10 ++++++
 2 files changed, 31 insertions(+), 15 deletions(-)

diff --git a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/sampling/distribution/EnumeratedDistributionSamplersPerformance.java b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/sampling/distribution/EnumeratedDistributionSamplersPerformance.java
index 41bce62..4e74c11 100644
--- a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/sampling/distribution/EnumeratedDistributionSamplersPerformance.java
+++ b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/sampling/distribution/EnumeratedDistributionSamplersPerformance.java
@@ -268,6 +268,18 @@ public class EnumeratedDistributionSamplersPerformance {
     public static class KnownDistributionSources extends SamplerSources {
         /** The cumulative probability limit for unbounded distributions. */
         private static final double CUMULATIVE_PROBABILITY_LIMIT = 1 - 1e-9;
+        /** Binomial distribution number of trials. */
+        private static final int BINOM_N = 67;
+        /** Binomial distribution probability of success. */
+        private static final double BINOM_P = 0.7;
+        /** Geometric distribution probability of success. */
+        private static final double GEO_P = 0.2;
+        /** Poisson distribution mean. */
+        private static final double POISS_MEAN = 3.22;
+        /** Bimodal distribution mean 1. */
+        private static final double BIMOD_MEAN1 = 10;
+        /** Bimodal distribution mean 1. */
+        private static final double BIMOD_MEAN2 = 20;
 
         /**
          * The distribution.
@@ -275,7 +287,7 @@ public class EnumeratedDistributionSamplersPerformance {
         @Param({"Binomial_N67_P0.7",
                 "Geometric_P0.2",
                 "4SidedLoadedDie",
-                "Poisson_Mean3.14",
+                "Poisson_Mean3.22",
                 "Poisson_Mean10_Mean20",
                 })
         private String distribution;
@@ -284,13 +296,10 @@ public class EnumeratedDistributionSamplersPerformance {
         @Override
         protected double[] createProbabilities() {
             if ("Binomial_N67_P0.7".equals(distribution)) {
-                final int trials = 67;
-                final double probabilityOfSuccess = 0.7;
-                final BinomialDistribution dist = new BinomialDistribution(null, trials, probabilityOfSuccess);
-                return createProbabilities(dist, 0, trials);
+                final BinomialDistribution dist = new BinomialDistribution(null, BINOM_N, BINOM_P);
+                return createProbabilities(dist, 0, BINOM_N);
             } else if ("Geometric_P0.2".equals(distribution)) {
-                final double probabilityOfSuccess = 0.2;
-                final double probabilityOfFailure = 1 - probabilityOfSuccess;
+                final double probabilityOfFailure = 1 - GEO_P;
                 // https://en.wikipedia.org/wiki/Geometric_distribution
                 // PMF = (1-p)^k * p
                 // k is number of failures before a success
@@ -300,7 +309,7 @@ public class EnumeratedDistributionSamplersPerformance {
                 double sum = 0;
                 int k = 0;
                 while (k < probabilities.length) {
-                    probabilities[k] = p * probabilityOfSuccess;
+                    probabilities[k] = p * GEO_P;
                     sum += probabilities[k++];
                     if (sum > CUMULATIVE_PROBABILITY_LIMIT) {
                         break;
@@ -311,19 +320,16 @@ public class EnumeratedDistributionSamplersPerformance {
                 return Arrays.copyOf(probabilities, k);
             } else if ("4SidedLoadedDie".equals(distribution)) {
                 return new double[] {1.0 / 2, 1.0 / 3, 1.0 / 12, 1.0 / 12};
-            } else if ("Poisson_Mean3.14".equals(distribution)) {
-                final double mean = 3.14;
-                final IntegerDistribution dist = createPoissonDistribution(mean);
+            } else if ("Poisson_Mean3.22".equals(distribution)) {
+                final IntegerDistribution dist = createPoissonDistribution(POISS_MEAN);
                 final int max = dist.inverseCumulativeProbability(CUMULATIVE_PROBABILITY_LIMIT);
                 return createProbabilities(dist, 0, max);
             } else if ("Poisson_Mean10_Mean20".equals(distribution)) {
                 // Create a Bimodel using two Poisson distributions
-                final double mean1 = 10;
-                final double mean2 = 20;
-                final IntegerDistribution dist1 = createPoissonDistribution(mean2);
+                final IntegerDistribution dist1 = createPoissonDistribution(BIMOD_MEAN2);
                 final int max = dist1.inverseCumulativeProbability(CUMULATIVE_PROBABILITY_LIMIT);
                 final double[] p1 = createProbabilities(dist1, 0, max);
-                final double[] p2 = createProbabilities(createPoissonDistribution(mean1), 0, max);
+                final double[] p2 = createProbabilities(createPoissonDistribution(BIMOD_MEAN1), 0, max);
                 for (int i = 0; i < p1.length; i++) {
                     p1[i] += p2[i];
                 }
diff --git a/src/main/resources/spotbugs/spotbugs-exclude-filter.xml b/src/main/resources/spotbugs/spotbugs-exclude-filter.xml
index 7507b3e..3448498 100644
--- a/src/main/resources/spotbugs/spotbugs-exclude-filter.xml
+++ b/src/main/resources/spotbugs/spotbugs-exclude-filter.xml
@@ -43,4 +43,14 @@
     <BugPattern name="RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE"/>
   </Match>
 
+  <Match>
+    <!-- Benchmark state classes can expose internal representations.
+         Unwritten fields can be used for baseline values. -->
+    <Class name="~org.apache.commons.rng.examples.jmh..*(Benchmark|Performance).*"/>
+    <Or>
+      <BugPattern name="EI_EXPOSE_REP"/>
+      <BugPattern name="UWF_UNWRITTEN_FIELD"/>
+    </Or>
+  </Match>
+
 </FindBugsFilter>


[commons-rng] 01/02: Disable PMD for the JMH module.

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-rng.git

commit 88110c2db7e61b8cafff70566001650fbb30ad09
Author: aherbert <ah...@apache.org>
AuthorDate: Thu Feb 13 11:40:19 2020 +0000

    Disable PMD for the JMH module.
---
 commons-rng-examples/examples-jmh/pom.xml | 2 ++
 pom.xml                                   | 3 +++
 2 files changed, 5 insertions(+)

diff --git a/commons-rng-examples/examples-jmh/pom.xml b/commons-rng-examples/examples-jmh/pom.xml
index 6b58813..826e748 100644
--- a/commons-rng-examples/examples-jmh/pom.xml
+++ b/commons-rng-examples/examples-jmh/pom.xml
@@ -69,6 +69,8 @@
     <jmh.version>1.22</jmh.version>
     <uberjar.name>examples-jmh</uberjar.name>
     <project.mainClass>org.openjdk.jmh.Main</project.mainClass>
+    <!-- Disable analysis for benchmarking code. -->
+    <pmd.skip>true</pmd.skip>
   </properties>
 
   <profiles>
diff --git a/pom.xml b/pom.xml
index 7b7a497..a7e7a53 100644
--- a/pom.xml
+++ b/pom.xml
@@ -225,6 +225,9 @@
           <rulesets>
             <ruleset>${rng.parent.dir}/src/main/resources/pmd/pmd-ruleset.xml</ruleset>
           </rulesets>
+          <excludeRoots>
+            <excludeRoot>target/generated-sources</excludeRoot>
+          </excludeRoots>
         </configuration>
       </plugin>
       <plugin>