Repository: commons-rng
Updated Branches:
  refs/heads/master 77bc452db -> c5a185866


Formatting.


Project: http://git-wip-us.apache.org/repos/asf/commons-rng/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-rng/commit/6294d7a7
Tree: http://git-wip-us.apache.org/repos/asf/commons-rng/tree/6294d7a7
Diff: http://git-wip-us.apache.org/repos/asf/commons-rng/diff/6294d7a7

Branch: refs/heads/master
Commit: 6294d7a7de7ae88cbaf7e71e6fbb79d3d2947bab
Parents: 77bc452
Author: Gilles <er...@apache.org>
Authored: Tue Nov 22 13:05:05 2016 +0100
Committer: Gilles <er...@apache.org>
Committed: Tue Nov 22 13:05:05 2016 +0100

----------------------------------------------------------------------
 .../RejectionInversionZipfSampler.java           | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-rng/blob/6294d7a7/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/RejectionInversionZipfSampler.java
----------------------------------------------------------------------
diff --git 
a/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/RejectionInversionZipfSampler.java
 
b/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/RejectionInversionZipfSampler.java
index faa0311..92523d0 100644
--- 
a/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/RejectionInversionZipfSampler.java
+++ 
b/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/RejectionInversionZipfSampler.java
@@ -98,14 +98,13 @@ public class RejectionInversionZipfSampler
             // u is uniformly distributed in (hIntegralX1, 
hIntegralNumberOfElements]
 
             double x = hIntegralInverse(u);
-            int k = (int)(x + 0.5);
+            int k = (int) (x + 0.5);
 
-            // Limit k to the range [1, numberOfElements]
-            // (k could be outside due to numerical inaccuracies)
+            // Limit k to the range [1, numberOfElements] if it would be 
outside
+            // due to numerical inaccuracies.
             if (k < 1) {
                 k = 1;
-            }
-            else if (k > numberOfElements) {
+            } else if (k > numberOfElements) {
                 k = numberOfElements;
             }
 
@@ -173,12 +172,12 @@ public class RejectionInversionZipfSampler
      * </ul>
      * H(x) is an integral function of h(x), the derivative of H(x) is h(x).
      *
-     * @param x free parameter
+     * @param x Free parameter.
      * @return {@code H(x)}.
      */
     private double hIntegral(final double x) {
         final double logX = Math.log(x);
-        return helper2((1d-exponent)*logX)*logX;
+        return helper2((1 - exponent) * logX) * logX;
     }
 
     /**
@@ -219,8 +218,7 @@ public class RejectionInversionZipfSampler
     private static double helper1(final double x) {
         if (Math.abs(x) > 1e-8) {
             return Math.log1p(x) / x;
-        }
-        else {
+        } else {
             return 1 - x * (0.5 - x * (0.33333333333333333 - 0.25 * x));
         }
     }
@@ -237,8 +235,7 @@ public class RejectionInversionZipfSampler
     private static double helper2(final double x) {
         if (Math.abs(x) > 1e-8) {
             return Math.expm1(x) / x;
-        }
-        else {
+        } else {
             return 1 + x * 0.5 * (1 + x * 0.33333333333333333 * (1 + 0.25 * 
x));
         }
     }

Reply via email to