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 2017/09/22 14:49:58 UTC
[01/11] tinkerpop git commit: added a way to distributed 'terminal
energy' throughout the graph via the implicit teleportation matrix in
PageRankVertexProgram. Everthing looks good except that I'm not get the
appropriate normalization to 1.0 of the resul
Repository: tinkerpop
Updated Branches:
refs/heads/master 6b337324b -> e04245b53
added a way to distributed 'terminal energy' throughout the graph via the implicit teleportation matrix in PageRankVertexProgram. Everthing looks good except that I'm not get the appropriate normalization to 1.0 of the resultant vector and I can't seem to figure out why. Committing what I have so far.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/f7e717de
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/f7e717de
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/f7e717de
Branch: refs/heads/master
Commit: f7e717de2d4b98ca0a49662f545b1b61ed01becd
Parents: 90a89ea
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Fri Sep 15 14:23:10 2017 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Fri Sep 15 14:23:10 2017 -0600
----------------------------------------------------------------------
.../ranking/pagerank/PageRankVertexProgram.java | 57 +++++++++++++++-----
1 file changed, 44 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f7e717de/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgram.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgram.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgram.java
index 7609eba..223f7e5 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgram.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgram.java
@@ -21,12 +21,14 @@ package org.apache.tinkerpop.gremlin.process.computer.ranking.pagerank;
import org.apache.commons.configuration.Configuration;
import org.apache.tinkerpop.gremlin.process.computer.GraphComputer;
import org.apache.tinkerpop.gremlin.process.computer.Memory;
+import org.apache.tinkerpop.gremlin.process.computer.MemoryComputeKey;
import org.apache.tinkerpop.gremlin.process.computer.MessageCombiner;
import org.apache.tinkerpop.gremlin.process.computer.MessageScope;
import org.apache.tinkerpop.gremlin.process.computer.Messenger;
import org.apache.tinkerpop.gremlin.process.computer.VertexComputeKey;
import org.apache.tinkerpop.gremlin.process.computer.VertexProgram;
import org.apache.tinkerpop.gremlin.process.computer.util.AbstractVertexProgramBuilder;
+import org.apache.tinkerpop.gremlin.process.traversal.Operator;
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import org.apache.tinkerpop.gremlin.process.traversal.TraversalSource;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
@@ -59,16 +61,17 @@ public class PageRankVertexProgram implements VertexProgram<Double> {
private static final String TOTAL_ITERATIONS = "gremlin.pageRankVertexProgram.totalIterations";
private static final String EDGE_TRAVERSAL = "gremlin.pageRankVertexProgram.edgeTraversal";
private static final String INITIAL_RANK_TRAVERSAL = "gremlin.pageRankVertexProgram.initialRankTraversal";
+ private static final String TERMINAL_ENERGY = "gremlin.pageRankVertexProgram.terminalEnergy";
private MessageScope.Local<Double> incidentMessageScope = MessageScope.Local.of(__::outE);
private MessageScope.Local<Double> countMessageScope = MessageScope.Local.of(new MessageScope.Local.ReverseTraversalSupplier(this.incidentMessageScope));
private PureTraversal<Vertex, Edge> edgeTraversal = null;
private PureTraversal<Vertex, ? extends Number> initialRankTraversal = null;
- private double vertexCountAsDouble = 1.0d;
private double alpha = 0.85d;
private int totalIterations = 30;
private String property = PAGE_RANK;
private Set<VertexComputeKey> vertexComputeKeys;
+ private Set<MemoryComputeKey> memoryComputeKeys;
private PageRankVertexProgram() {
@@ -83,17 +86,20 @@ public class PageRankVertexProgram implements VertexProgram<Double> {
this.incidentMessageScope = MessageScope.Local.of(() -> this.edgeTraversal.get().clone());
this.countMessageScope = MessageScope.Local.of(new MessageScope.Local.ReverseTraversalSupplier(this.incidentMessageScope));
}
- this.vertexCountAsDouble = configuration.getDouble(VERTEX_COUNT, 1.0d);
this.alpha = configuration.getDouble(ALPHA, 0.85d);
this.totalIterations = configuration.getInt(TOTAL_ITERATIONS, 30);
this.property = configuration.getString(PROPERTY, PAGE_RANK);
- this.vertexComputeKeys = new HashSet<>(Arrays.asList(VertexComputeKey.of(this.property, false), VertexComputeKey.of(EDGE_COUNT, true)));
+ this.vertexComputeKeys = new HashSet<>(Arrays.asList(
+ VertexComputeKey.of(this.property, false),
+ VertexComputeKey.of(EDGE_COUNT, true)));
+ this.memoryComputeKeys = new HashSet<>(Arrays.asList(
+ MemoryComputeKey.of(TERMINAL_ENERGY, Operator.sum, true, true),
+ MemoryComputeKey.of(VERTEX_COUNT, Operator.sum, true, true)));
}
@Override
public void storeState(final Configuration configuration) {
VertexProgram.super.storeState(configuration);
- configuration.setProperty(VERTEX_COUNT, this.vertexCountAsDouble);
configuration.setProperty(ALPHA, this.alpha);
configuration.setProperty(TOTAL_ITERATIONS, this.totalIterations);
configuration.setProperty(PROPERTY, this.property);
@@ -124,6 +130,11 @@ public class PageRankVertexProgram implements VertexProgram<Double> {
}
@Override
+ public Set<MemoryComputeKey> getMemoryComputeKeys() {
+ return this.memoryComputeKeys;
+ }
+
+ @Override
public Set<MessageScope> getMessageScopes(final Memory memory) {
final Set<MessageScope> set = new HashSet<>();
set.add(memory.isInitialIteration() ? this.countMessageScope : this.incidentMessageScope);
@@ -144,28 +155,48 @@ public class PageRankVertexProgram implements VertexProgram<Double> {
@Override
public void setup(final Memory memory) {
-
+ memory.set(TERMINAL_ENERGY, 0.0d);
+ memory.set(VERTEX_COUNT, 0.0d);
}
@Override
public void execute(final Vertex vertex, Messenger<Double> messenger, final Memory memory) {
+ System.out.println(memory.get(TERMINAL_ENERGY).toString());
if (memory.isInitialIteration()) {
messenger.sendMessage(this.countMessageScope, 1.0d);
+ memory.add(VERTEX_COUNT, 1.0d);
} else if (1 == memory.getIteration()) {
- double initialPageRank = (null == this.initialRankTraversal ?
+ final double vertexCount = memory.<Double>get(VERTEX_COUNT);
+ final double initialPageRank = (null == this.initialRankTraversal ?
1.0d :
- TraversalUtil.apply(vertex, this.initialRankTraversal.get()).doubleValue()) / this.vertexCountAsDouble;
- double edgeCount = IteratorUtils.reduce(messenger.receiveMessages(), 0.0d, (a, b) -> a + b);
+ TraversalUtil.apply(vertex, this.initialRankTraversal.get()).doubleValue()) / vertexCount;
+ final double edgeCount = IteratorUtils.reduce(messenger.receiveMessages(), 0.0d, (a, b) -> a + b);
vertex.property(VertexProperty.Cardinality.single, this.property, initialPageRank);
vertex.property(VertexProperty.Cardinality.single, EDGE_COUNT, edgeCount);
- if (!this.terminate(memory)) // don't send messages if this is the last iteration
- messenger.sendMessage(this.incidentMessageScope, initialPageRank / edgeCount);
+ if (!this.terminate(memory)) { // don't send messages if this is the last iteration
+ if (edgeCount > 0.0d)
+ messenger.sendMessage(this.incidentMessageScope, initialPageRank / edgeCount);
+ else
+ memory.add(TERMINAL_ENERGY, initialPageRank);
+ }
} else {
+ final double vertexCount = memory.<Double>get(VERTEX_COUNT);
double newPageRank = IteratorUtils.reduce(messenger.receiveMessages(), 0.0d, (a, b) -> a + b);
- newPageRank = (this.alpha * newPageRank) + ((1.0d - this.alpha) / this.vertexCountAsDouble);
+ newPageRank = (this.alpha * newPageRank) + ((1.0d - this.alpha) / vertexCount);
+ final double terminalEnergy = memory.get(TERMINAL_ENERGY);
+ if (terminalEnergy > 0.0d) {
+ final double localTerminalEnergy = terminalEnergy / vertexCount;
+ newPageRank = newPageRank + localTerminalEnergy;
+ memory.add(TERMINAL_ENERGY, -1.0d * localTerminalEnergy);
+ }
vertex.property(VertexProperty.Cardinality.single, this.property, newPageRank);
- if (!this.terminate(memory)) // don't send messages if this is the last iteration
- messenger.sendMessage(this.incidentMessageScope, newPageRank / vertex.<Double>value(EDGE_COUNT));
+ final double edgeCount = vertex.<Double>value(EDGE_COUNT);
+ if (!this.terminate(memory)) { // don't send messages if this is the last iteration
+ if (edgeCount > 0.0d)
+ messenger.sendMessage(this.incidentMessageScope, newPageRank / edgeCount);
+ else
+ memory.add(TERMINAL_ENERGY, newPageRank);
+ }
}
}
[04/11] tinkerpop git commit: updated toString() for
PageRankVertexProgram>
Posted by ok...@apache.org.
updated toString() for PageRankVertexProgram>
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/735af789
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/735af789
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/735af789
Branch: refs/heads/master
Commit: 735af789d127bb172df40fd3c4b806cd635bbd31
Parents: 3bc830f
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Wed Sep 20 08:25:55 2017 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Wed Sep 20 08:25:55 2017 -0600
----------------------------------------------------------------------
.../process/computer/ranking/pagerank/PageRankVertexProgram.java | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/735af789/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgram.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgram.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgram.java
index 81468d4..28f3e4b 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgram.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgram.java
@@ -215,7 +215,9 @@ public class PageRankVertexProgram implements VertexProgram<Double> {
@Override
public String toString() {
- return StringFactory.vertexProgramString(this, "alpha=" + this.alpha + ", iterations=" + this.totalIterations + ", epsilon=" + this.epsilon);
+ return -1 == this.totalIterations ?
+ StringFactory.vertexProgramString(this, "alpha=" + this.alpha + ", epsilon=" + this.epsilon) :
+ StringFactory.vertexProgramString(this, "alpha=" + this.alpha + ", iterations=" + this.totalIterations);
}
//////////////////////////////
[02/11] tinkerpop git commit: finalized worked on
PageRankVertexProgram fix. Really cool use of Memory to solve the
'teleporatation problem.' Proud of myself. Updated CHANGELOG and made a note
to users about changing PageRank values in UPGRADE docs.
Posted by ok...@apache.org.
finalized worked on PageRankVertexProgram fix. Really cool use of Memory to solve the 'teleporatation problem.' Proud of myself. Updated CHANGELOG and made a note to users about changing PageRank values in UPGRADE docs.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/db7d996b
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/db7d996b
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/db7d996b
Branch: refs/heads/master
Commit: db7d996bd46978b54573d956935e7eea97ef6338
Parents: f7e717d
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Mon Sep 18 10:22:06 2017 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Mon Sep 18 10:22:06 2017 -0600
----------------------------------------------------------------------
CHANGELOG.asciidoc | 1 +
docs/src/upgrade/release-3.3.x.asciidoc | 33 ++++++++++++++++++++
.../ranking/pagerank/PageRankVertexProgram.java | 28 +++++++++--------
.../pagerank/PageRankVertexProgramTest.java | 12 +++----
.../traversal/step/map/PageRankTest.java | 2 +-
.../traversal/step/map/PeerPressureTest.java | 8 ++---
6 files changed, 60 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/db7d996b/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 6afa37f..c8a1c7d 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -28,6 +28,7 @@ TinkerPop 3.3.1 (Release Date: NOT OFFICIALLY RELEASED YET)
This release also includes changes from <<release-3-2-7, 3.2.7>>.
+* Fixed two major bugs in how PageRank was being calculated in `PageRankVertexProgram`.
* Added `Io.requiresVersion(Object)` to allow graph providers a way to check the `Io` type and version being constructed.
* Defaulted `IoCore.gryo()` and `IoCore.graphson()` to both use their 3.0 formats which means that `Graph.io()` will use those by default.
* Bumped Neo4j 3.2.3
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/db7d996b/docs/src/upgrade/release-3.3.x.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/upgrade/release-3.3.x.asciidoc b/docs/src/upgrade/release-3.3.x.asciidoc
index 1b2aa17..e215dca 100644
--- a/docs/src/upgrade/release-3.3.x.asciidoc
+++ b/docs/src/upgrade/release-3.3.x.asciidoc
@@ -32,6 +32,39 @@ Please see the link:https://github.com/apache/tinkerpop/blob/3.3.1/CHANGELOG.asc
Upgrading for Users
~~~~~~~~~~~~~~~~~~~
+PageRankVertexProgram
+^^^^^^^^^^^^^^^^^^^^^
+
+There were two major bugs in the way in which PageRank was being calculated in `PageRankVertexProgram`. First, teleportation
+energy was not being distributed correctly amongst the vertices at each round. Second, terminal vertices (i.e. vertices
+with no outgoing edges) did not have their full gathered energy distributed via teleportation. As a secondary benefit,
+`PageRankVertexProgram` also always calculates the vertex count and no longer requires the user to specify the vertex count.
+
+For users upgrading, note that while the relative rank orders will remain "the same," the actual PageRank values will differ
+from prior TinkerPop versions.
+
+```
+VERTEX iGRAPH TINKERPOP
+marko 0.1119788 0.11375485828040575
+vadas 0.1370267 0.14598540145985406
+lop 0.2665600 0.30472082661863686
+josh 0.1620746 0.14598540145985406
+ripple 0.2103812 0.1757986539008437
+peter 0.1119788 0.11375485828040575
+```
+
+Normalization preserved through computation:
+
+```
+0.11375485828040575 +
+0.14598540145985406 +
+0.30472082661863686 +
+0.14598540145985406 +
+0.1757986539008437 +
+0.11375485828040575
+==>1.00000000000000018
+```
+
IO Defaults
^^^^^^^^^^^
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/db7d996b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgram.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgram.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgram.java
index 223f7e5..e92f0a8 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgram.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgram.java
@@ -61,7 +61,7 @@ public class PageRankVertexProgram implements VertexProgram<Double> {
private static final String TOTAL_ITERATIONS = "gremlin.pageRankVertexProgram.totalIterations";
private static final String EDGE_TRAVERSAL = "gremlin.pageRankVertexProgram.edgeTraversal";
private static final String INITIAL_RANK_TRAVERSAL = "gremlin.pageRankVertexProgram.initialRankTraversal";
- private static final String TERMINAL_ENERGY = "gremlin.pageRankVertexProgram.terminalEnergy";
+ private static final String TELEPORTATION_ENERGY = "gremlin.pageRankVertexProgram.teleportationEnergy";
private MessageScope.Local<Double> incidentMessageScope = MessageScope.Local.of(__::outE);
private MessageScope.Local<Double> countMessageScope = MessageScope.Local.of(new MessageScope.Local.ReverseTraversalSupplier(this.incidentMessageScope));
@@ -93,7 +93,7 @@ public class PageRankVertexProgram implements VertexProgram<Double> {
VertexComputeKey.of(this.property, false),
VertexComputeKey.of(EDGE_COUNT, true)));
this.memoryComputeKeys = new HashSet<>(Arrays.asList(
- MemoryComputeKey.of(TERMINAL_ENERGY, Operator.sum, true, true),
+ MemoryComputeKey.of(TELEPORTATION_ENERGY, Operator.sum, true, true),
MemoryComputeKey.of(VERTEX_COUNT, Operator.sum, true, true)));
}
@@ -155,47 +155,49 @@ public class PageRankVertexProgram implements VertexProgram<Double> {
@Override
public void setup(final Memory memory) {
- memory.set(TERMINAL_ENERGY, 0.0d);
+ memory.set(TELEPORTATION_ENERGY, 0.0d);
memory.set(VERTEX_COUNT, 0.0d);
}
@Override
public void execute(final Vertex vertex, Messenger<Double> messenger, final Memory memory) {
- System.out.println(memory.get(TERMINAL_ENERGY).toString());
if (memory.isInitialIteration()) {
messenger.sendMessage(this.countMessageScope, 1.0d);
memory.add(VERTEX_COUNT, 1.0d);
} else if (1 == memory.getIteration()) {
final double vertexCount = memory.<Double>get(VERTEX_COUNT);
- final double initialPageRank = (null == this.initialRankTraversal ?
- 1.0d :
- TraversalUtil.apply(vertex, this.initialRankTraversal.get()).doubleValue()) / vertexCount;
- final double edgeCount = IteratorUtils.reduce(messenger.receiveMessages(), 0.0d, (a, b) -> a + b);
+ double initialPageRank = null == this.initialRankTraversal ?
+ 1.0d / vertexCount :
+ TraversalUtil.apply(vertex, this.initialRankTraversal.get()).doubleValue();
vertex.property(VertexProperty.Cardinality.single, this.property, initialPageRank);
+ final double edgeCount = IteratorUtils.reduce(messenger.receiveMessages(), 0.0d, (a, b) -> a + b);
vertex.property(VertexProperty.Cardinality.single, EDGE_COUNT, edgeCount);
+ memory.add(TELEPORTATION_ENERGY, (1.0d - this.alpha) * initialPageRank);
+ initialPageRank = this.alpha * initialPageRank;
if (!this.terminate(memory)) { // don't send messages if this is the last iteration
if (edgeCount > 0.0d)
messenger.sendMessage(this.incidentMessageScope, initialPageRank / edgeCount);
else
- memory.add(TERMINAL_ENERGY, initialPageRank);
+ memory.add(TELEPORTATION_ENERGY, initialPageRank);
}
} else {
final double vertexCount = memory.<Double>get(VERTEX_COUNT);
double newPageRank = IteratorUtils.reduce(messenger.receiveMessages(), 0.0d, (a, b) -> a + b);
- newPageRank = (this.alpha * newPageRank) + ((1.0d - this.alpha) / vertexCount);
- final double terminalEnergy = memory.get(TERMINAL_ENERGY);
+ final double terminalEnergy = memory.get(TELEPORTATION_ENERGY);
if (terminalEnergy > 0.0d) {
final double localTerminalEnergy = terminalEnergy / vertexCount;
newPageRank = newPageRank + localTerminalEnergy;
- memory.add(TERMINAL_ENERGY, -1.0d * localTerminalEnergy);
+ memory.add(TELEPORTATION_ENERGY, -localTerminalEnergy);
}
vertex.property(VertexProperty.Cardinality.single, this.property, newPageRank);
+ memory.add(TELEPORTATION_ENERGY, (1.0d - this.alpha) * newPageRank);
+ newPageRank = this.alpha * newPageRank;
final double edgeCount = vertex.<Double>value(EDGE_COUNT);
if (!this.terminate(memory)) { // don't send messages if this is the last iteration
if (edgeCount > 0.0d)
messenger.sendMessage(this.incidentMessageScope, newPageRank / edgeCount);
else
- memory.add(TERMINAL_ENERGY, newPageRank);
+ memory.add(TELEPORTATION_ENERGY, newPageRank);
}
}
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/db7d996b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgramTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgramTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgramTest.java
index 41dfaa0..8612cb6 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgramTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgramTest.java
@@ -49,17 +49,17 @@ public class PageRankVertexProgramTest extends AbstractGremlinProcessTest {
final Double pageRank = v.value(PageRankVertexProgram.PAGE_RANK);
//System.out.println(name + "-----" + pageRank);
if (name.equals("marko"))
- assertTrue(pageRank > 0.14 && pageRank < 0.16);
+ assertTrue(pageRank > 0.10 && pageRank < 0.12);
else if (name.equals("vadas"))
- assertTrue(pageRank > 0.19 && pageRank < 0.20);
+ assertTrue(pageRank > 0.13 && pageRank < 0.15);
else if (name.equals("lop"))
- assertTrue(pageRank > 0.40 && pageRank < 0.41);
+ assertTrue(pageRank > 0.29 && pageRank < 0.31);
else if (name.equals("josh"))
- assertTrue(pageRank > 0.19 && pageRank < 0.20);
+ assertTrue(pageRank > 0.13 && pageRank < 0.15);
else if (name.equals("ripple"))
- assertTrue(pageRank > 0.23 && pageRank < 0.24);
+ assertTrue(pageRank > 0.16 && pageRank < 0.18);
else if (name.equals("peter"))
- assertTrue(pageRank > 0.14 && pageRank < 0.16);
+ assertTrue(pageRank > 0.10 && pageRank < 0.12);
else
throw new IllegalStateException("The following vertex should not exist in the graph: " + name);
});
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/db7d996b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/PageRankTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/PageRankTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/PageRankTest.java
index 57a3b3f..d2cb0eb 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/PageRankTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/PageRankTest.java
@@ -180,7 +180,7 @@ public abstract class PageRankTest extends AbstractGremlinProcessTest {
Vertex vertex = (Vertex) map.get("a");
double pageRank = (Double) map.get("b");
assertEquals(convertToVertexId("marko"), vertex.id());
- assertTrue(pageRank > 0.15d);
+ assertTrue(pageRank > 0.10d);
counter++;
}
assertEquals(2, counter);
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/db7d996b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/PeerPressureTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/PeerPressureTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/PeerPressureTest.java
index 996be6d..f9615d5 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/PeerPressureTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/PeerPressureTest.java
@@ -72,10 +72,10 @@ public abstract class PeerPressureTest extends AbstractGremlinProcessTest {
final Map<Object, Number> map = traversal.next();
assertFalse(traversal.hasNext());
assertEquals(4, map.size());
- assertEquals(1.0d, (double) map.get(convertToVertexId("marko")), 0.001d);
- assertEquals(0.0d, (double) map.get(convertToVertexId("lop")), 0.001d);
- assertEquals(0.0d, (double) map.get(convertToVertexId("ripple")), 0.001d);
- assertEquals(0.0d, (double) map.get(convertToVertexId("peter")), 0.001d);
+ assertEquals(0.583d, (double) map.get(convertToVertexId("marko")), 0.001d);
+ assertEquals(0.138d, (double) map.get(convertToVertexId("lop")), 0.001d);
+ assertEquals(0.138d, (double) map.get(convertToVertexId("ripple")), 0.001d);
+ assertEquals(0.138d, (double) map.get(convertToVertexId("peter")), 0.001d);
}
@Test
[10/11] tinkerpop git commit: added the new PageRankVertexProgram
code to the reference documentation as PageRank serves as our reference
program.
Posted by ok...@apache.org.
added the new PageRankVertexProgram code to the reference documentation as PageRank serves as our reference program.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/94ffe73e
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/94ffe73e
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/94ffe73e
Branch: refs/heads/master
Commit: 94ffe73e778a3eacfd96ec9a38cf8f54f06de256
Parents: dacabbe
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Thu Sep 21 09:51:35 2017 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Thu Sep 21 09:51:35 2017 -0600
----------------------------------------------------------------------
docs/src/reference/the-graphcomputer.asciidoc | 97 +++++++++++++++-------
1 file changed, 66 insertions(+), 31 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/94ffe73e/docs/src/reference/the-graphcomputer.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/the-graphcomputer.asciidoc b/docs/src/reference/the-graphcomputer.asciidoc
index b03c891..278e8bc 100644
--- a/docs/src/reference/the-graphcomputer.asciidoc
+++ b/docs/src/reference/the-graphcomputer.asciidoc
@@ -186,26 +186,30 @@ methods of a `VertexProgram`, the PageRankVertexProgram code is analyzed below.
[source,java]
----
-public class PageRankVertexProgram implements VertexProgram<Double> { <1>
+public class PageRankVertexProgram implements VertexProgram<Double> { <1>
public static final String PAGE_RANK = "gremlin.pageRankVertexProgram.pageRank";
private static final String EDGE_COUNT = "gremlin.pageRankVertexProgram.edgeCount";
private static final String PROPERTY = "gremlin.pageRankVertexProgram.property";
private static final String VERTEX_COUNT = "gremlin.pageRankVertexProgram.vertexCount";
private static final String ALPHA = "gremlin.pageRankVertexProgram.alpha";
- private static final String TOTAL_ITERATIONS = "gremlin.pageRankVertexProgram.totalIterations";
+ private static final String EPSILON = "gremlin.pageRankVertexProgram.epsilon";
+ private static final String MAX_ITERATIONS = "gremlin.pageRankVertexProgram.maxIterations";
private static final String EDGE_TRAVERSAL = "gremlin.pageRankVertexProgram.edgeTraversal";
private static final String INITIAL_RANK_TRAVERSAL = "gremlin.pageRankVertexProgram.initialRankTraversal";
+ private static final String TELEPORTATION_ENERGY = "gremlin.pageRankVertexProgram.teleportationEnergy";
+ private static final String CONVERGENCE_ERROR = "gremlin.pageRankVertexProgram.convergenceError";
private MessageScope.Local<Double> incidentMessageScope = MessageScope.Local.of(__::outE); <2>
private MessageScope.Local<Double> countMessageScope = MessageScope.Local.of(new MessageScope.Local.ReverseTraversalSupplier(this.incidentMessageScope));
private PureTraversal<Vertex, Edge> edgeTraversal = null;
private PureTraversal<Vertex, ? extends Number> initialRankTraversal = null;
- private double vertexCountAsDouble = 1.0d;
private double alpha = 0.85d;
- private int totalIterations = 30;
+ private double epsilon = 0.00001d;
+ private int maxIterations = 20;
private String property = PAGE_RANK; <3>
private Set<VertexComputeKey> vertexComputeKeys;
+ private Set<MemoryComputeKey> memoryComputeKeys;
private PageRankVertexProgram() {
@@ -220,20 +224,26 @@ public class PageRankVertexProgram implements VertexProgram<Double> { <1>
this.incidentMessageScope = MessageScope.Local.of(() -> this.edgeTraversal.get().clone());
this.countMessageScope = MessageScope.Local.of(new MessageScope.Local.ReverseTraversalSupplier(this.incidentMessageScope));
}
- this.vertexCountAsDouble = configuration.getDouble(VERTEX_COUNT, 1.0d);
- this.alpha = configuration.getDouble(ALPHA, 0.85d);
- this.totalIterations = configuration.getInt(TOTAL_ITERATIONS, 30);
+ this.alpha = configuration.getDouble(ALPHA, this.alpha);
+ this.epsilon = configuration.getDouble(EPSILON, this.epsilon);
+ this.maxIterations = configuration.getInt(MAX_ITERATIONS, 20);
this.property = configuration.getString(PROPERTY, PAGE_RANK);
- this.vertexComputeKeys = new HashSet<>(Arrays.asList(VertexComputeKey.of(this.property, false), VertexComputeKey.of(EDGE_COUNT, true))); <5>
+ this.vertexComputeKeys = new HashSet<>(Arrays.asList(
+ VertexComputeKey.of(this.property, false),
+ VertexComputeKey.of(EDGE_COUNT, true))); <5>
+ this.memoryComputeKeys = new HashSet<>(Arrays.asList(
+ MemoryComputeKey.of(TELEPORTATION_ENERGY, Operator.sum, true, true),
+ MemoryComputeKey.of(VERTEX_COUNT, Operator.sum, true, true),
+ MemoryComputeKey.of(CONVERGENCE_ERROR, Operator.sum, false, true)));
}
@Override
public void storeState(final Configuration configuration) {
VertexProgram.super.storeState(configuration);
- configuration.setProperty(VERTEX_COUNT, this.vertexCountAsDouble);
configuration.setProperty(ALPHA, this.alpha);
- configuration.setProperty(TOTAL_ITERATIONS, this.totalIterations);
+ configuration.setProperty(EPSILON, this.epsilon);
configuration.setProperty(PROPERTY, this.property);
+ configuration.setProperty(MAX_ITERATIONS, this.maxIterations);
if (null != this.edgeTraversal)
this.edgeTraversal.storeState(configuration, EDGE_TRAVERSAL);
if (null != this.initialRankTraversal)
@@ -251,7 +261,7 @@ public class PageRankVertexProgram implements VertexProgram<Double> { <1>
}
@Override
- public Set<VertexComputeKey> getVertexComputeKeys() { <6>
+ public Set<VertexComputeKey> getVertexComputeKeys() { <6>
return this.vertexComputeKeys;
}
@@ -261,6 +271,11 @@ public class PageRankVertexProgram implements VertexProgram<Double> { <1>
}
@Override
+ public Set<MemoryComputeKey> getMemoryComputeKeys() {
+ return this.memoryComputeKeys;
+ }
+
+ @Override
public Set<MessageScope> getMessageScopes(final Memory memory) {
final Set<MessageScope> set = new HashSet<>();
set.add(memory.isInitialIteration() ? this.countMessageScope : this.incidentMessageScope);
@@ -281,39 +296,59 @@ public class PageRankVertexProgram implements VertexProgram<Double> { <1>
@Override
public void setup(final Memory memory) {
-
+ memory.set(TELEPORTATION_ENERGY, null == this.initialRankTraversal ? 1.0d : 0.0d);
+ memory.set(VERTEX_COUNT, 0.0d);
+ memory.set(CONVERGENCE_ERROR, 1.0d);
}
@Override
public void execute(final Vertex vertex, Messenger<Double> messenger, final Memory memory) { <7>
if (memory.isInitialIteration()) {
- messenger.sendMessage(this.countMessageScope, 1.0d); <8>
- } else if (1 == memory.getIteration()) {
- double initialPageRank = (null == this.initialRankTraversal ?
- 1.0d :
- TraversalUtil.apply(vertex, this.initialRankTraversal.get()).doubleValue()) / this.vertexCountAsDouble; <9>
- double edgeCount = IteratorUtils.reduce(messenger.receiveMessages(), 0.0d, (a, b) -> a + b);
- vertex.property(VertexProperty.Cardinality.single, this.property, initialPageRank);
- vertex.property(VertexProperty.Cardinality.single, EDGE_COUNT, edgeCount);
- if (!this.terminate(memory)) // don't send messages if this is the last iteration
- messenger.sendMessage(this.incidentMessageScope, initialPageRank / edgeCount);
+ messenger.sendMessage(this.countMessageScope, 1.0d); <8>
+ memory.add(VERTEX_COUNT, 1.0d);
} else {
- double newPageRank = IteratorUtils.reduce(messenger.receiveMessages(), 0.0d, (a, b) -> a + b); <10>
- newPageRank = (this.alpha * newPageRank) + ((1.0d - this.alpha) / this.vertexCountAsDouble);
- vertex.property(VertexProperty.Cardinality.single, this.property, newPageRank);
- if (!this.terminate(memory)) // don't send messages if this is the last iteration
- messenger.sendMessage(this.incidentMessageScope, newPageRank / vertex.<Double>value(EDGE_COUNT));
+ final double vertexCount = memory.<Double>get(VERTEX_COUNT);
+ final double edgeCount;
+ double pageRank;
+ if (1 == memory.getIteration()) {
+ edgeCount = IteratorUtils.reduce(messenger.receiveMessages(), 0.0d, (a, b) -> a + b);
+ vertex.property(VertexProperty.Cardinality.single, EDGE_COUNT, edgeCount);
+ pageRank = null == this.initialRankTraversal ?
+ 0.0d :
+ TraversalUtil.apply(vertex, this.initialRankTraversal.get()).doubleValue(); <9>
+ } else {
+ edgeCount = vertex.value(EDGE_COUNT);
+ pageRank = IteratorUtils.reduce(messenger.receiveMessages(), 0.0d, (a, b) -> a + b); <10>
+ }
+ //////////////////////////
+ final double teleporationEnergy = memory.get(TELEPORTATION_ENERGY);
+ if (teleporationEnergy > 0.0d) {
+ final double localTerminalEnergy = teleporationEnergy / vertexCount;
+ pageRank = pageRank + localTerminalEnergy;
+ memory.add(TELEPORTATION_ENERGY, -localTerminalEnergy);
+ }
+ final double previousPageRank = vertex.<Double>property(this.property).orElse(0.0d);
+ memory.add(CONVERGENCE_ERROR, Math.abs(pageRank - previousPageRank));
+ vertex.property(VertexProperty.Cardinality.single, this.property, pageRank);
+ memory.add(TELEPORTATION_ENERGY, (1.0d - this.alpha) * pageRank);
+ pageRank = this.alpha * pageRank;
+ if (edgeCount > 0.0d)
+ messenger.sendMessage(this.incidentMessageScope, pageRank / edgeCount);
+ else
+ memory.add(TELEPORTATION_ENERGY, pageRank);
}
}
@Override
- public boolean terminate(final Memory memory) {
- return memory.getIteration() >= this.totalIterations; <11>
+ public boolean terminate(final Memory memory) { <11>
+ boolean terminate = memory.<Double>get(CONVERGENCE_ERROR) < this.epsilon || memory.getIteration() >= this.maxIterations;
+ memory.set(CONVERGENCE_ERROR, 0.0d);
+ return terminate;
}
@Override
public String toString() {
- return StringFactory.vertexProgramString(this, "alpha=" + this.alpha + ", iterations=" + this.totalIterations);
+ return StringFactory.vertexProgramString(this, "alpha=" + this.alpha + ", epsilon=" + this.epsilon + ", iterations=" + this.maxIterations);
}
}
----
@@ -328,7 +363,7 @@ public class PageRankVertexProgram implements VertexProgram<Double> { <1>
<8> In order to determine how to distribute the energy to neighbors, a "1"-count is used to determine how many incident vertices exist for the `MessageScope`.
<9> Initially, each vertex is provided an equal amount of energy represented as a double.
<10> Energy is aggregated, computed on according to the PageRank algorithm, and then disseminated according to the defined `MessageScope.Local`.
-<11> The computation is terminated after a pre-defined number of iterations.
+<11> The computation is terminated after epsilon-convergence is met or a pre-defined number of iterations have taken place.
The above `PageRankVertexProgram` is used as follows.
[09/11] tinkerpop git commit: Giraph failed cause I assumed a default
GraphComputer for Giraph in the new energy conservation test... Copied the
model used in the older tests.
Posted by ok...@apache.org.
Giraph failed cause I assumed a default GraphComputer for Giraph in the new energy conservation test... Copied the model used in the older tests.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/dacabbe0
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/dacabbe0
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/dacabbe0
Branch: refs/heads/master
Commit: dacabbe06c3566e5373296490f8c9634a307e01c
Parents: c7f597d
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Wed Sep 20 14:36:29 2017 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Wed Sep 20 14:36:29 2017 -0600
----------------------------------------------------------------------
.../computer/ranking/pagerank/PageRankVertexProgramTest.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/dacabbe0/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgramTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgramTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgramTest.java
index 8b4f977..6550a32 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgramTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgramTest.java
@@ -107,7 +107,7 @@ public class PageRankVertexProgramTest extends AbstractGremlinProcessTest {
@Test
@LoadGraphWith(MODERN)
public void shouldExecutePageRankWithEnergyConservation() throws Exception {
- final ComputerResult result = graph.compute().program(PageRankVertexProgram.build().create(graph)).submit().get();
+ final ComputerResult result = graph.compute(graphProvider.getGraphComputer(graph).getClass()).program(PageRankVertexProgram.build().create(graph)).submit().get();
final double sum = result.graph().traversal().V().values(PageRankVertexProgram.PAGE_RANK).sum().next().doubleValue();
assertEquals(1.0d, sum, 0.01d);
}
[03/11] tinkerpop git commit: Added epsilon-based convergence. If the
user does not specify a times() to iterate,
then it will use epislon which is 10-6 for convergence.
Posted by ok...@apache.org.
Added epsilon-based convergence. If the user does not specify a times() to iterate, then it will use epislon which is 10-6 for convergence.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/3bc830fd
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/3bc830fd
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/3bc830fd
Branch: refs/heads/master
Commit: 3bc830fd09edb5c0c82479d174a447af3aa6ac63
Parents: db7d996
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Tue Sep 19 10:47:20 2017 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Tue Sep 19 10:47:20 2017 -0600
----------------------------------------------------------------------
CHANGELOG.asciidoc | 1 +
docs/src/upgrade/release-3.3.x.asciidoc | 8 +-
.../ranking/pagerank/PageRankVertexProgram.java | 89 +++++++++++---------
.../step/map/PageRankVertexProgramStep.java | 2 +-
.../pagerank/PageRankVertexProgramTest.java | 2 +-
5 files changed, 59 insertions(+), 43 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3bc830fd/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index c8a1c7d..87899ce 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -28,6 +28,7 @@ TinkerPop 3.3.1 (Release Date: NOT OFFICIALLY RELEASED YET)
This release also includes changes from <<release-3-2-7, 3.2.7>>.
+* Added support for epsilon-based convergence in `PageRankVertexProgram` (no longer manually capped by iterations).
* Fixed two major bugs in how PageRank was being calculated in `PageRankVertexProgram`.
* Added `Io.requiresVersion(Object)` to allow graph providers a way to check the `Io` type and version being constructed.
* Defaulted `IoCore.gryo()` and `IoCore.graphson()` to both use their 3.0 formats which means that `Graph.io()` will use those by default.
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3bc830fd/docs/src/upgrade/release-3.3.x.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/upgrade/release-3.3.x.asciidoc b/docs/src/upgrade/release-3.3.x.asciidoc
index e215dca..43d9ccd 100644
--- a/docs/src/upgrade/release-3.3.x.asciidoc
+++ b/docs/src/upgrade/release-3.3.x.asciidoc
@@ -37,8 +37,7 @@ PageRankVertexProgram
There were two major bugs in the way in which PageRank was being calculated in `PageRankVertexProgram`. First, teleportation
energy was not being distributed correctly amongst the vertices at each round. Second, terminal vertices (i.e. vertices
-with no outgoing edges) did not have their full gathered energy distributed via teleportation. As a secondary benefit,
-`PageRankVertexProgram` also always calculates the vertex count and no longer requires the user to specify the vertex count.
+with no outgoing edges) did not have their full gathered energy distributed via teleportation.
For users upgrading, note that while the relative rank orders will remain "the same," the actual PageRank values will differ
from prior TinkerPop versions.
@@ -65,6 +64,11 @@ Normalization preserved through computation:
==>1.00000000000000018
```
+Two other additions to `PageRankVertexProgram` were provided as well.
+
+1. It now calculates the vertex count and thus, no longer requires the user to specify the vertex count.
+2. It now allows the user to leverage an epsilon-based convergence instead of having to specify the number of iterations to execute.
+
IO Defaults
^^^^^^^^^^^
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3bc830fd/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgram.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgram.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgram.java
index e92f0a8..81468d4 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgram.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgram.java
@@ -58,17 +58,20 @@ public class PageRankVertexProgram implements VertexProgram<Double> {
private static final String PROPERTY = "gremlin.pageRankVertexProgram.property";
private static final String VERTEX_COUNT = "gremlin.pageRankVertexProgram.vertexCount";
private static final String ALPHA = "gremlin.pageRankVertexProgram.alpha";
+ private static final String EPSILON = "gremlin.pageRankVertexProgram.epsilon";
private static final String TOTAL_ITERATIONS = "gremlin.pageRankVertexProgram.totalIterations";
private static final String EDGE_TRAVERSAL = "gremlin.pageRankVertexProgram.edgeTraversal";
private static final String INITIAL_RANK_TRAVERSAL = "gremlin.pageRankVertexProgram.initialRankTraversal";
private static final String TELEPORTATION_ENERGY = "gremlin.pageRankVertexProgram.teleportationEnergy";
+ private static final String CONVERGENCE_ERROR = "gremlin.pageRankVertexProgram.convergenceError";
private MessageScope.Local<Double> incidentMessageScope = MessageScope.Local.of(__::outE);
private MessageScope.Local<Double> countMessageScope = MessageScope.Local.of(new MessageScope.Local.ReverseTraversalSupplier(this.incidentMessageScope));
private PureTraversal<Vertex, Edge> edgeTraversal = null;
private PureTraversal<Vertex, ? extends Number> initialRankTraversal = null;
private double alpha = 0.85d;
- private int totalIterations = 30;
+ private double epsilon = 0.00001d;
+ private int totalIterations = -1;
private String property = PAGE_RANK;
private Set<VertexComputeKey> vertexComputeKeys;
private Set<MemoryComputeKey> memoryComputeKeys;
@@ -86,23 +89,26 @@ public class PageRankVertexProgram implements VertexProgram<Double> {
this.incidentMessageScope = MessageScope.Local.of(() -> this.edgeTraversal.get().clone());
this.countMessageScope = MessageScope.Local.of(new MessageScope.Local.ReverseTraversalSupplier(this.incidentMessageScope));
}
- this.alpha = configuration.getDouble(ALPHA, 0.85d);
- this.totalIterations = configuration.getInt(TOTAL_ITERATIONS, 30);
+ this.alpha = configuration.getDouble(ALPHA, this.alpha);
+ this.epsilon = configuration.getDouble(EPSILON, this.epsilon);
+ this.totalIterations = configuration.getInt(TOTAL_ITERATIONS, -1);
this.property = configuration.getString(PROPERTY, PAGE_RANK);
this.vertexComputeKeys = new HashSet<>(Arrays.asList(
VertexComputeKey.of(this.property, false),
VertexComputeKey.of(EDGE_COUNT, true)));
this.memoryComputeKeys = new HashSet<>(Arrays.asList(
MemoryComputeKey.of(TELEPORTATION_ENERGY, Operator.sum, true, true),
- MemoryComputeKey.of(VERTEX_COUNT, Operator.sum, true, true)));
+ MemoryComputeKey.of(VERTEX_COUNT, Operator.sum, true, true),
+ MemoryComputeKey.of(CONVERGENCE_ERROR, Operator.sum, false, true)));
}
@Override
public void storeState(final Configuration configuration) {
VertexProgram.super.storeState(configuration);
configuration.setProperty(ALPHA, this.alpha);
- configuration.setProperty(TOTAL_ITERATIONS, this.totalIterations);
+ configuration.setProperty(EPSILON, this.epsilon);
configuration.setProperty(PROPERTY, this.property);
+ configuration.setProperty(TOTAL_ITERATIONS, this.totalIterations);
if (null != this.edgeTraversal)
this.edgeTraversal.storeState(configuration, EDGE_TRAVERSAL);
if (null != this.initialRankTraversal)
@@ -155,8 +161,9 @@ public class PageRankVertexProgram implements VertexProgram<Double> {
@Override
public void setup(final Memory memory) {
- memory.set(TELEPORTATION_ENERGY, 0.0d);
+ memory.set(TELEPORTATION_ENERGY, null == this.initialRankTraversal ? 1.0d : 0.0d);
memory.set(VERTEX_COUNT, 0.0d);
+ memory.set(CONVERGENCE_ERROR, 1.0d);
}
@Override
@@ -164,52 +171,51 @@ public class PageRankVertexProgram implements VertexProgram<Double> {
if (memory.isInitialIteration()) {
messenger.sendMessage(this.countMessageScope, 1.0d);
memory.add(VERTEX_COUNT, 1.0d);
- } else if (1 == memory.getIteration()) {
- final double vertexCount = memory.<Double>get(VERTEX_COUNT);
- double initialPageRank = null == this.initialRankTraversal ?
- 1.0d / vertexCount :
- TraversalUtil.apply(vertex, this.initialRankTraversal.get()).doubleValue();
- vertex.property(VertexProperty.Cardinality.single, this.property, initialPageRank);
- final double edgeCount = IteratorUtils.reduce(messenger.receiveMessages(), 0.0d, (a, b) -> a + b);
- vertex.property(VertexProperty.Cardinality.single, EDGE_COUNT, edgeCount);
- memory.add(TELEPORTATION_ENERGY, (1.0d - this.alpha) * initialPageRank);
- initialPageRank = this.alpha * initialPageRank;
- if (!this.terminate(memory)) { // don't send messages if this is the last iteration
- if (edgeCount > 0.0d)
- messenger.sendMessage(this.incidentMessageScope, initialPageRank / edgeCount);
- else
- memory.add(TELEPORTATION_ENERGY, initialPageRank);
- }
} else {
final double vertexCount = memory.<Double>get(VERTEX_COUNT);
- double newPageRank = IteratorUtils.reduce(messenger.receiveMessages(), 0.0d, (a, b) -> a + b);
- final double terminalEnergy = memory.get(TELEPORTATION_ENERGY);
- if (terminalEnergy > 0.0d) {
- final double localTerminalEnergy = terminalEnergy / vertexCount;
- newPageRank = newPageRank + localTerminalEnergy;
- memory.add(TELEPORTATION_ENERGY, -localTerminalEnergy);
+ final double edgeCount;
+ double pageRank;
+ if (1 == memory.getIteration()) {
+ edgeCount = IteratorUtils.reduce(messenger.receiveMessages(), 0.0d, (a, b) -> a + b);
+ vertex.property(VertexProperty.Cardinality.single, EDGE_COUNT, edgeCount);
+ pageRank = null == this.initialRankTraversal ?
+ 0.0d :
+ TraversalUtil.apply(vertex, this.initialRankTraversal.get()).doubleValue();
+ } else {
+ edgeCount = vertex.value(EDGE_COUNT);
+ pageRank = IteratorUtils.reduce(messenger.receiveMessages(), 0.0d, (a, b) -> a + b);
}
- vertex.property(VertexProperty.Cardinality.single, this.property, newPageRank);
- memory.add(TELEPORTATION_ENERGY, (1.0d - this.alpha) * newPageRank);
- newPageRank = this.alpha * newPageRank;
- final double edgeCount = vertex.<Double>value(EDGE_COUNT);
- if (!this.terminate(memory)) { // don't send messages if this is the last iteration
- if (edgeCount > 0.0d)
- messenger.sendMessage(this.incidentMessageScope, newPageRank / edgeCount);
- else
- memory.add(TELEPORTATION_ENERGY, newPageRank);
+ //////////////////////////
+ final double teleporationEnergy = memory.get(TELEPORTATION_ENERGY);
+ if (teleporationEnergy > 0.0d) {
+ final double localTerminalEnergy = teleporationEnergy / vertexCount;
+ pageRank = pageRank + localTerminalEnergy;
+ memory.add(TELEPORTATION_ENERGY, -localTerminalEnergy);
}
+ final double previousPageRank = vertex.<Double>property(this.property).orElse(0.0d);
+ memory.add(CONVERGENCE_ERROR, Math.abs(pageRank - previousPageRank));
+ vertex.property(VertexProperty.Cardinality.single, this.property, pageRank);
+ memory.add(TELEPORTATION_ENERGY, (1.0d - this.alpha) * pageRank);
+ pageRank = this.alpha * pageRank;
+ if (edgeCount > 0.0d)
+ messenger.sendMessage(this.incidentMessageScope, pageRank / edgeCount);
+ else
+ memory.add(TELEPORTATION_ENERGY, pageRank);
}
}
@Override
public boolean terminate(final Memory memory) {
- return memory.getIteration() >= this.totalIterations;
+ // System.out.println(memory.<Double>get(CONVERGENCE_ERROR));
+ memory.set(CONVERGENCE_ERROR, 0.0d);
+ return -1 == this.totalIterations ?
+ memory.<Double>get(CONVERGENCE_ERROR) < this.epsilon :
+ memory.getIteration() >= this.totalIterations;
}
@Override
public String toString() {
- return StringFactory.vertexProgramString(this, "alpha=" + this.alpha + ", iterations=" + this.totalIterations);
+ return StringFactory.vertexProgramString(this, "alpha=" + this.alpha + ", iterations=" + this.totalIterations + ", epsilon=" + this.epsilon);
}
//////////////////////////////
@@ -239,6 +245,11 @@ public class PageRankVertexProgram implements VertexProgram<Double> {
return this;
}
+ public Builder epsilon(final double epsilon) {
+ this.configuration.setProperty(EPSILON, epsilon);
+ return this;
+ }
+
public Builder edges(final Traversal.Admin<Vertex, Edge> edgeTraversal) {
PureTraversal.storeState(this.configuration, EDGE_TRAVERSAL, edgeTraversal);
return this;
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3bc830fd/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/PageRankVertexProgramStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/PageRankVertexProgramStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/PageRankVertexProgramStep.java
index 364d092..d67faf3 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/PageRankVertexProgramStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/PageRankVertexProgramStep.java
@@ -47,7 +47,7 @@ public final class PageRankVertexProgramStep extends VertexProgramStep implement
private PureTraversal<Vertex, Edge> edgeTraversal;
private String pageRankProperty = PageRankVertexProgram.PAGE_RANK;
- private int times = 30;
+ private int times = -2;
private final double alpha;
public PageRankVertexProgramStep(final Traversal.Admin traversal, final double alpha) {
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3bc830fd/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgramTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgramTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgramTest.java
index 8612cb6..459c688 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgramTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgramTest.java
@@ -38,7 +38,7 @@ public class PageRankVertexProgramTest extends AbstractGremlinProcessTest {
@LoadGraphWith(MODERN)
public void shouldExecutePageRank() throws Exception {
if (graphProvider.getGraphComputer(graph).features().supportsResultGraphPersistCombination(GraphComputer.ResultGraph.NEW, GraphComputer.Persist.VERTEX_PROPERTIES)) {
- final ComputerResult result = graph.compute(graphProvider.getGraphComputer(graph).getClass()).program(PageRankVertexProgram.build().create(graph)).submit().get();
+ final ComputerResult result = graph.compute(graphProvider.getGraphComputer(graph).getClass()).program(PageRankVertexProgram.build().iterations(30).create(graph)).submit().get();
result.graph().traversal().V().forEachRemaining(v -> {
assertEquals(3, v.keys().size()); // name, age/lang, pageRank
assertTrue(v.keys().contains("name"));
[08/11] tinkerpop git commit: tweaked the terminate condition to
ensure Memory isn't set prior to examination.
Posted by ok...@apache.org.
tweaked the terminate condition to ensure Memory isn't set prior to examination.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/c7f597dd
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/c7f597dd
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/c7f597dd
Branch: refs/heads/master
Commit: c7f597ddea9f27e0986d19b56e08e09c110fe51b
Parents: 2d551c1
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Wed Sep 20 12:13:28 2017 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Wed Sep 20 12:13:28 2017 -0600
----------------------------------------------------------------------
.../process/computer/ranking/pagerank/PageRankVertexProgram.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/c7f597dd/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgram.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgram.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgram.java
index 217060e..ce0b5f2 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgram.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgram.java
@@ -206,9 +206,9 @@ public class PageRankVertexProgram implements VertexProgram<Double> {
@Override
public boolean terminate(final Memory memory) {
- // System.out.println(memory.<Double>get(CONVERGENCE_ERROR));
+ boolean terminate = memory.<Double>get(CONVERGENCE_ERROR) < this.epsilon || memory.getIteration() >= this.maxIterations;
memory.set(CONVERGENCE_ERROR, 0.0d);
- return memory.<Double>get(CONVERGENCE_ERROR) < this.epsilon || memory.getIteration() >= this.maxIterations;
+ return terminate;
}
@Override
[07/11] tinkerpop git commit: added a test for iterations break,
epsilon break, and for energy conservation.
Posted by ok...@apache.org.
added a test for iterations break, epsilon break, and for energy conservation.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/2d551c18
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/2d551c18
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/2d551c18
Branch: refs/heads/master
Commit: 2d551c18a80f528d3fe296144a2d7a68467b0fff
Parents: 87a7391
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Wed Sep 20 08:55:52 2017 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Wed Sep 20 08:55:52 2017 -0600
----------------------------------------------------------------------
.../pagerank/PageRankVertexProgramTest.java | 50 ++++++++++++++++----
1 file changed, 41 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/2d551c18/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgramTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgramTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgramTest.java
index 6fb3cb7..8b4f977 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgramTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgramTest.java
@@ -36,7 +36,7 @@ public class PageRankVertexProgramTest extends AbstractGremlinProcessTest {
@Test
@LoadGraphWith(MODERN)
- public void shouldExecutePageRank() throws Exception {
+ public void shouldExecutePageRankWithIterationsBreak() throws Exception {
if (graphProvider.getGraphComputer(graph).features().supportsResultGraphPersistCombination(GraphComputer.ResultGraph.NEW, GraphComputer.Persist.VERTEX_PROPERTIES)) {
final ComputerResult result = graph.compute(graphProvider.getGraphComputer(graph).getClass()).
program(PageRankVertexProgram.build().epsilon(0.0d).iterations(30).create(graph)).submit().get(); // by using epsilon 0.0, we guarantee iterations 30
@@ -69,14 +69,46 @@ public class PageRankVertexProgramTest extends AbstractGremlinProcessTest {
}
}
- /*@Test
+ @Test
@LoadGraphWith(MODERN)
- public void shouldExecutePageRankWithNormalizedValues() throws Exception {
- final ComputerResult result = graph.compute().program(PageRankVertexProgram.build().vertexCount(6).create()).submit().get();
- final double sum = result.graph().traversal().V().values(PageRankVertexProgram.PAGE_RANK).sum().next();
- System.out.println(sum);
- assertEquals(1.0d,sum,0.01);
- }*/
-
+ public void shouldExecutePageRankWithEpsilonBreak() throws Exception {
+ if (graphProvider.getGraphComputer(graph).features().supportsResultGraphPersistCombination(GraphComputer.ResultGraph.NEW, GraphComputer.Persist.VERTEX_PROPERTIES)) {
+ final ComputerResult result = graph.compute(graphProvider.getGraphComputer(graph).getClass()).
+ program(PageRankVertexProgram.build().epsilon(0.00001d).iterations(30).create(graph)).submit().get(); // by using epsilon 0.00001, we should get iterations 11
+ result.graph().traversal().V().forEachRemaining(v -> {
+ assertEquals(3, v.keys().size()); // name, age/lang, pageRank
+ assertTrue(v.keys().contains("name"));
+ assertTrue(v.keys().contains(PageRankVertexProgram.PAGE_RANK));
+ assertEquals(1, IteratorUtils.count(v.values("name")));
+ assertEquals(1, IteratorUtils.count(v.values(PageRankVertexProgram.PAGE_RANK)));
+ final String name = v.value("name");
+ final Double pageRank = v.value(PageRankVertexProgram.PAGE_RANK);
+ //System.out.println(name + "-----" + pageRank);
+ if (name.equals("marko"))
+ assertTrue(pageRank > 0.10 && pageRank < 0.12);
+ else if (name.equals("vadas"))
+ assertTrue(pageRank > 0.13 && pageRank < 0.15);
+ else if (name.equals("lop"))
+ assertTrue(pageRank > 0.29 && pageRank < 0.31);
+ else if (name.equals("josh"))
+ assertTrue(pageRank > 0.13 && pageRank < 0.15);
+ else if (name.equals("ripple"))
+ assertTrue(pageRank > 0.16 && pageRank < 0.18);
+ else if (name.equals("peter"))
+ assertTrue(pageRank > 0.10 && pageRank < 0.12);
+ else
+ throw new IllegalStateException("The following vertex should not exist in the graph: " + name);
+ });
+ assertEquals(result.memory().getIteration(), 11);
+ assertEquals(result.memory().asMap().size(), 0);
+ }
+ }
+ @Test
+ @LoadGraphWith(MODERN)
+ public void shouldExecutePageRankWithEnergyConservation() throws Exception {
+ final ComputerResult result = graph.compute().program(PageRankVertexProgram.build().create(graph)).submit().get();
+ final double sum = result.graph().traversal().V().values(PageRankVertexProgram.PAGE_RANK).sum().next().doubleValue();
+ assertEquals(1.0d, sum, 0.01d);
+ }
}
\ No newline at end of file
[11/11] tinkerpop git commit: Merge branch 'TINKERPOP-1783'
Posted by ok...@apache.org.
Merge branch 'TINKERPOP-1783'
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/e04245b5
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/e04245b5
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/e04245b5
Branch: refs/heads/master
Commit: e04245b534119ac5c5b8a7181b33bbd1821aad29
Parents: 6b33732 94ffe73
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Fri Sep 22 08:49:47 2017 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Fri Sep 22 08:49:47 2017 -0600
----------------------------------------------------------------------
CHANGELOG.asciidoc | 3 +
docs/src/reference/the-graphcomputer.asciidoc | 97 +++++++++++++-------
docs/src/upgrade/release-3.3.x.asciidoc | 39 ++++++++
.../ranking/pagerank/PageRankVertexProgram.java | 96 +++++++++++++------
.../step/map/PageRankVertexProgramStep.java | 2 +-
.../pagerank/PageRankVertexProgramTest.java | 65 +++++++++----
.../traversal/step/map/PageRankTest.java | 2 +-
.../traversal/step/map/PeerPressureTest.java | 8 +-
8 files changed, 232 insertions(+), 80 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e04245b5/CHANGELOG.asciidoc
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e04245b5/docs/src/upgrade/release-3.3.x.asciidoc
----------------------------------------------------------------------
[05/11] tinkerpop git commit: totalIterations is now maxIterations.
If the espilon convergence is not met after maxIterations,
PageRank terminates. However, if convergence occurs before maxIterations,
then PageRank terminates (prior to maxIterations). Gi
Posted by ok...@apache.org.
totalIterations is now maxIterations. If the espilon convergence is not met after maxIterations, PageRank terminates. However, if convergence occurs before maxIterations, then PageRank terminates (prior to maxIterations). Given that PageRank is monotonic, this is exactly what you would want.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/f926dac0
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/f926dac0
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/f926dac0
Branch: refs/heads/master
Commit: f926dac0b74658c2b88ec79bf088a3339f5b9572
Parents: 735af78
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Wed Sep 20 08:38:26 2017 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Wed Sep 20 08:38:26 2017 -0600
----------------------------------------------------------------------
CHANGELOG.asciidoc | 3 ++-
.../ranking/pagerank/PageRankVertexProgram.java | 18 +++++++-----------
.../step/map/PageRankVertexProgramStep.java | 2 +-
.../pagerank/PageRankVertexProgramTest.java | 3 ++-
4 files changed, 12 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f926dac0/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 87899ce..0367fd6 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -28,7 +28,8 @@ TinkerPop 3.3.1 (Release Date: NOT OFFICIALLY RELEASED YET)
This release also includes changes from <<release-3-2-7, 3.2.7>>.
-* Added support for epsilon-based convergence in `PageRankVertexProgram` (no longer manually capped by iterations).
+* `PageRankVertexProgram` supports `maxIterations` but will break out early if epsilon-based convergence occurs.
+* Added support for epsilon-based convergence in `PageRankVertexProgram`.
* Fixed two major bugs in how PageRank was being calculated in `PageRankVertexProgram`.
* Added `Io.requiresVersion(Object)` to allow graph providers a way to check the `Io` type and version being constructed.
* Defaulted `IoCore.gryo()` and `IoCore.graphson()` to both use their 3.0 formats which means that `Graph.io()` will use those by default.
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f926dac0/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgram.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgram.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgram.java
index 28f3e4b..217060e 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgram.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgram.java
@@ -59,7 +59,7 @@ public class PageRankVertexProgram implements VertexProgram<Double> {
private static final String VERTEX_COUNT = "gremlin.pageRankVertexProgram.vertexCount";
private static final String ALPHA = "gremlin.pageRankVertexProgram.alpha";
private static final String EPSILON = "gremlin.pageRankVertexProgram.epsilon";
- private static final String TOTAL_ITERATIONS = "gremlin.pageRankVertexProgram.totalIterations";
+ private static final String MAX_ITERATIONS = "gremlin.pageRankVertexProgram.maxIterations";
private static final String EDGE_TRAVERSAL = "gremlin.pageRankVertexProgram.edgeTraversal";
private static final String INITIAL_RANK_TRAVERSAL = "gremlin.pageRankVertexProgram.initialRankTraversal";
private static final String TELEPORTATION_ENERGY = "gremlin.pageRankVertexProgram.teleportationEnergy";
@@ -71,7 +71,7 @@ public class PageRankVertexProgram implements VertexProgram<Double> {
private PureTraversal<Vertex, ? extends Number> initialRankTraversal = null;
private double alpha = 0.85d;
private double epsilon = 0.00001d;
- private int totalIterations = -1;
+ private int maxIterations = 20;
private String property = PAGE_RANK;
private Set<VertexComputeKey> vertexComputeKeys;
private Set<MemoryComputeKey> memoryComputeKeys;
@@ -91,7 +91,7 @@ public class PageRankVertexProgram implements VertexProgram<Double> {
}
this.alpha = configuration.getDouble(ALPHA, this.alpha);
this.epsilon = configuration.getDouble(EPSILON, this.epsilon);
- this.totalIterations = configuration.getInt(TOTAL_ITERATIONS, -1);
+ this.maxIterations = configuration.getInt(MAX_ITERATIONS, 20);
this.property = configuration.getString(PROPERTY, PAGE_RANK);
this.vertexComputeKeys = new HashSet<>(Arrays.asList(
VertexComputeKey.of(this.property, false),
@@ -108,7 +108,7 @@ public class PageRankVertexProgram implements VertexProgram<Double> {
configuration.setProperty(ALPHA, this.alpha);
configuration.setProperty(EPSILON, this.epsilon);
configuration.setProperty(PROPERTY, this.property);
- configuration.setProperty(TOTAL_ITERATIONS, this.totalIterations);
+ configuration.setProperty(MAX_ITERATIONS, this.maxIterations);
if (null != this.edgeTraversal)
this.edgeTraversal.storeState(configuration, EDGE_TRAVERSAL);
if (null != this.initialRankTraversal)
@@ -208,16 +208,12 @@ public class PageRankVertexProgram implements VertexProgram<Double> {
public boolean terminate(final Memory memory) {
// System.out.println(memory.<Double>get(CONVERGENCE_ERROR));
memory.set(CONVERGENCE_ERROR, 0.0d);
- return -1 == this.totalIterations ?
- memory.<Double>get(CONVERGENCE_ERROR) < this.epsilon :
- memory.getIteration() >= this.totalIterations;
+ return memory.<Double>get(CONVERGENCE_ERROR) < this.epsilon || memory.getIteration() >= this.maxIterations;
}
@Override
public String toString() {
- return -1 == this.totalIterations ?
- StringFactory.vertexProgramString(this, "alpha=" + this.alpha + ", epsilon=" + this.epsilon) :
- StringFactory.vertexProgramString(this, "alpha=" + this.alpha + ", iterations=" + this.totalIterations);
+ return StringFactory.vertexProgramString(this, "alpha=" + this.alpha + ", epsilon=" + this.epsilon + ", iterations=" + this.maxIterations);
}
//////////////////////////////
@@ -233,7 +229,7 @@ public class PageRankVertexProgram implements VertexProgram<Double> {
}
public Builder iterations(final int iterations) {
- this.configuration.setProperty(TOTAL_ITERATIONS, iterations);
+ this.configuration.setProperty(MAX_ITERATIONS, iterations);
return this;
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f926dac0/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/PageRankVertexProgramStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/PageRankVertexProgramStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/PageRankVertexProgramStep.java
index d67faf3..2f67aeb 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/PageRankVertexProgramStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/step/map/PageRankVertexProgramStep.java
@@ -47,7 +47,7 @@ public final class PageRankVertexProgramStep extends VertexProgramStep implement
private PureTraversal<Vertex, Edge> edgeTraversal;
private String pageRankProperty = PageRankVertexProgram.PAGE_RANK;
- private int times = -2;
+ private int times = 20;
private final double alpha;
public PageRankVertexProgramStep(final Traversal.Admin traversal, final double alpha) {
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f926dac0/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgramTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgramTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgramTest.java
index 459c688..6fb3cb7 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgramTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgramTest.java
@@ -38,7 +38,8 @@ public class PageRankVertexProgramTest extends AbstractGremlinProcessTest {
@LoadGraphWith(MODERN)
public void shouldExecutePageRank() throws Exception {
if (graphProvider.getGraphComputer(graph).features().supportsResultGraphPersistCombination(GraphComputer.ResultGraph.NEW, GraphComputer.Persist.VERTEX_PROPERTIES)) {
- final ComputerResult result = graph.compute(graphProvider.getGraphComputer(graph).getClass()).program(PageRankVertexProgram.build().iterations(30).create(graph)).submit().get();
+ final ComputerResult result = graph.compute(graphProvider.getGraphComputer(graph).getClass()).
+ program(PageRankVertexProgram.build().epsilon(0.0d).iterations(30).create(graph)).submit().get(); // by using epsilon 0.0, we guarantee iterations 30
result.graph().traversal().V().forEachRemaining(v -> {
assertEquals(3, v.keys().size()); // name, age/lang, pageRank
assertTrue(v.keys().contains("name"));
[06/11] tinkerpop git commit: add See: tag to upgrade docs.
Posted by ok...@apache.org.
add See: tag to upgrade docs.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/87a73917
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/87a73917
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/87a73917
Branch: refs/heads/master
Commit: 87a739172b7d836862491b5ba0305b2968ab0090
Parents: f926dac
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Wed Sep 20 08:49:27 2017 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Wed Sep 20 08:49:27 2017 -0600
----------------------------------------------------------------------
docs/src/upgrade/release-3.3.x.asciidoc | 2 ++
1 file changed, 2 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/87a73917/docs/src/upgrade/release-3.3.x.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/upgrade/release-3.3.x.asciidoc b/docs/src/upgrade/release-3.3.x.asciidoc
index 43d9ccd..9c64244 100644
--- a/docs/src/upgrade/release-3.3.x.asciidoc
+++ b/docs/src/upgrade/release-3.3.x.asciidoc
@@ -69,6 +69,8 @@ Two other additions to `PageRankVertexProgram` were provided as well.
1. It now calculates the vertex count and thus, no longer requires the user to specify the vertex count.
2. It now allows the user to leverage an epsilon-based convergence instead of having to specify the number of iterations to execute.
+See: link:https://issues.apache.org/jira/browse/TINKERPOP-1783[TINKERPOP-1783]
+
IO Defaults
^^^^^^^^^^^