You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2018/01/12 13:39:55 UTC

[5/5] commons-rng git commit: Make branching explicit (self-documenting code).

Make branching explicit (self-documenting code).


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

Branch: refs/heads/master
Commit: 01a2c09ce1d475fcedbdb06d7c2e3311e9222aca
Parents: daf0f7b
Author: Gilles <er...@apache.org>
Authored: Fri Jan 12 14:38:21 2018 +0100
Committer: Gilles <er...@apache.org>
Committed: Fri Jan 12 14:38:21 2018 +0100

----------------------------------------------------------------------
 .../AhrensDieterMarsagliaTsangGammaSampler.java | 35 ++++++++++----------
 1 file changed, 17 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-rng/blob/01a2c09c/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/AhrensDieterMarsagliaTsangGammaSampler.java
----------------------------------------------------------------------
diff --git a/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/AhrensDieterMarsagliaTsangGammaSampler.java b/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/AhrensDieterMarsagliaTsangGammaSampler.java
index 146888a..7a41197 100644
--- a/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/AhrensDieterMarsagliaTsangGammaSampler.java
+++ b/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/AhrensDieterMarsagliaTsangGammaSampler.java
@@ -114,28 +114,27 @@ public class AhrensDieterMarsagliaTsangGammaSampler
                     }
                 }
             }
-        }
-
-        // Now theta >= 1.
-        while (true) {
-            final double x = gaussian.sample();
-            final double oPcTx = (1 + cOptim * x);
-            final double v = oPcTx * oPcTx * oPcTx;
+        } else {
+            while (true) {
+                final double x = gaussian.sample();
+                final double oPcTx = (1 + cOptim * x);
+                final double v = oPcTx * oPcTx * oPcTx;
 
-            if (v <= 0) {
-                continue;
-            }
+                if (v <= 0) {
+                    continue;
+                }
 
-            final double x2 = x * x;
-            final double u = nextDouble();
+                final double x2 = x * x;
+                final double u = nextDouble();
 
-            // Squeeze.
-            if (u < 1 - 0.0331 * x2 * x2) {
-                return alpha * dOptim * v;
-            }
+                // Squeeze.
+                if (u < 1 - 0.0331 * x2 * x2) {
+                    return alpha * dOptim * v;
+                }
 
-            if (Math.log(u) < 0.5 * x2 + dOptim * (1 - v + Math.log(v))) {
-                return alpha * dOptim * v;
+                if (Math.log(u) < 0.5 * x2 + dOptim * (1 - v + Math.log(v))) {
+                    return alpha * dOptim * v;
+                }
             }
         }
     }