You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by ok...@apache.org on 2015/06/08 23:27:06 UTC

incubator-tinkerpop git commit: CoinStep with cumulative distribution stub via @mbroecheller help.

Repository: incubator-tinkerpop
Updated Branches:
  refs/heads/master 36a68cac1 -> ca733b534


CoinStep with cumulative distribution stub via @mbroecheller help.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/ca733b53
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/ca733b53
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/ca733b53

Branch: refs/heads/master
Commit: ca733b534a9b0996e675d2c5295104f5ed784936
Parents: 36a68ca
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Mon Jun 8 15:26:45 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Mon Jun 8 15:26:57 2015 -0600

----------------------------------------------------------------------
 .../process/traversal/step/filter/CoinStep.java | 28 ++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/ca733b53/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/CoinStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/CoinStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/CoinStep.java
index e5772b8..db2480d 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/CoinStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/CoinStep.java
@@ -43,13 +43,19 @@ public final class CoinStep<S> extends FilterStep<S> {
     @Override
     protected boolean filter(final Traverser.Admin<S> traverser) {
         long newBulk = 0l;
-        if (traverser.bulk() < 10) {
+        if (traverser.bulk() < 100) {
             for (int i = 0; i < traverser.bulk(); i++) {
                 if (this.probability >= RANDOM.nextDouble())
                     newBulk++;
             }
+        /*} else if (traverser.bulk() < 1000000) {
+            final double cumulative = RANDOM.nextDouble();
+            final long current = Double.valueOf(traverser.bulk() / 2.0d).longValue();
+            final double next = choose(traverser.bulk(), current) * Math.pow(this.probability,current) * Math.pow(1.0d - this.probability,traverser.bulk() - current);
+            if()
+            */
         } else {
-            newBulk = Double.valueOf(RANDOM.nextBoolean() ? Math.floor(this.probability * traverser.bulk()) : Math.ceil(this.probability * traverser.bulk())).longValue();
+            newBulk = Math.round(this.probability * traverser.bulk());
         }
         if (0 == newBulk) return false;
         traverser.setBulk(newBulk);
@@ -70,4 +76,22 @@ public final class CoinStep<S> extends FilterStep<S> {
     public Set<TraverserRequirement> getRequirements() {
         return Collections.singleton(TraverserRequirement.BULK);
     }
+
+    //////
+
+    private static double choose(long x, long y) {
+        if (y < 0 || y > x) return 0;
+        if (y > x / 2) {
+            // choose(n,k) == choose(n,n-k),
+            // so this could save a little effort
+            y = x - y;
+        }
+
+        double denominator = 1.0, numerator = 1.0;
+        for (long i = 1; i <= y; i++) {
+            denominator *= i;
+            numerator *= (x + 1 - i);
+        }
+        return numerator / denominator;
+    }
 }