16.5 Executing Builtin Algorithms
The graph server (PGX) contains a set of builtin algorithms that are available as Java APIs.
The following table provides an overview of the available algorithms, grouped by category. Note that these algorithms can be invoked through the Analyst Class.
Note:
See the supported BuiltIn Algorithms on GitHub for more details.Table 1611 Overview of BuiltIn Algorithms
Category  Algorithms 

Classic graph algorithms  Prim's Algorithm 
Community detection  Conductance Minimization (Soman and Narang Algorithm), Infomap, Label Propagation, Louvain 
Connected components  Strongly Connected Components, Weakly Connected Components (WCC) 
Link predition  WTF (Whom To Follow) Algorithm 
Matrix factorization  Matrix Factorization 
Other  Graph Traversal Algorithms 
Path finding  All Vertices and Edges on Filtered Path, BellmanFord Algorithms, Bidirectional Dijkstra Algorithms, Compute Distance Index, Compute HighDegree Vertices, Dijkstra Algorithms, Enumerate Simple Paths, Fast Path Finding, Fattest Path, Filtered Fast Path Finding, Hop Distance Algorithms 
Ranking and walking  Closeness Centrality Algorithms, Degree Centrality Algorithms, Eigenvector Centrality, HyperlinkInduced Topic Search (HITS), PageRank Algorithms, Random Walk with Restart, Stochastic Approach for LinkStructure Analysis (SALSA) Algorithms, Vertex Betweenness Centrality Algorithms 
Structure evaluation  AdamicAdar index, Bipartite Check, Conductance, Cycle Detection Algorithms, Degree Distribution Algorithms, Eccentricity Algorithms, KCore, Local Clustering Coefficient (LCC), Modularity, Partition Conductance, Reachability Algorithms, Topological Ordering Algorithms, Triangle Counting Algorithms 
This following topics describe the use of the graph server (PGX) using Triangle Counting and PageRank analytics as examples.
 About BuiltIn Algorithms in the Graph Server (PGX)
 Running the Triangle Counting Algorithm
 Running the PageRank Algorithm
Parent topic: Developing Applications with Graph Analytics
16.5.1 About BuiltIn Algorithms in the Graph Server (PGX)
The graph server (PGX) contains a set of builtin algorithms that are available as
Java APIs. The details of the APIs are documented in the Javadoc that is included in the
product documentation library. Specifically, see the BuiltinAlgorithms
interface Method Summary for a list of the supported inmemory analyst methods.
For example, this is the PageRank procedure signature:
/**
* Classic pagerank algorithm. Time complexity: O(E * K) with E = number of edges, K is a given constant (max
* iterations)
*
* @param graph
* graph
* @param e
* maximum error for terminating the iteration
* @param d
* damping factor
* @param max
* maximum number of iterations
* @return Vertex Property holding the result as a double
*/
public <ID extends Comparable<ID>> VertexProperty<ID, Double> pagerank(PgxGraph graph, double e, double d, int max);
Parent topic: Executing Builtin Algorithms
16.5.2 Running the Triangle Counting Algorithm
For triangle counting, the sortByDegree
boolean parameter of countTriangles()
allows you to control whether the graph should first be sorted by degree (true
) or not (false
). If true
, more memory will be used, but the algorithm will run faster; however, if your graph is very large, you might want to turn this optimization off to avoid running out of memory.
opg4j> analyst.countTriangles(graph, true)
==> 1
import oracle.pgx.api.*; Analyst analyst = session.createAnalyst(); long triangles = analyst.countTriangles(graph, true);
The algorithm finds one triangle in the sample graph.
Tip:
When using the graph shell, you can increase the amount of log output during execution by changing the logging level. See information about the:loglevel
command with :h
:loglevel
.
Parent topic: Executing Builtin Algorithms
16.5.3 Running the PageRank Algorithm
PageRank computes a rank value between 0
and 1
for each vertex (node) in the graph and stores the values in a double
property. The algorithm therefore creates a vertex property of type double
for the output.
In the graph server (PGX), there are two types of vertex and edge properties:

Persistent Properties: Properties that are loaded with the graph from a data source are fixed, inmemory copies of the data on disk, and are therefore persistent. Persistent properties are readonly, immutable and shared between sessions.

Transient Properties: Values can only be written to transient properties, which are private to a session. You can create transient properties by calling
createVertexProperty
andcreateEdgeProperty
onPgxGraph
objects, or by copying existing properties usingclone()
on Property objects.Transient properties hold the results of computation by algorithms. For example, the PageRank algorithm computes a rank value between 0 and 1 for each vertex in the graph and stores these values in a transient property named
pg_rank
. Transient properties are destroyed when the Analyst object is destroyed.
This example obtains the top three vertices with the highest PageRank values. It uses a transient vertex property of type double
to hold the computed PageRank values. The PageRank algorithm uses the following default values for the input parameters: error (tolerance = 0.001), damping factor = 0.85, and maximum number of iterations = 100.
opg4j> rank = analyst.pagerank(graph, 0.001, 0.85, 100);
==> ...
opg4j> rank.getTopKValues(3)
==> 128=0.1402019732468347
==> 333=0.12002296283541904
==> 99=0.09708583862990475
import java.util.Map.Entry;
import oracle.pgx.api.*;
Analyst analyst = session.createAnalyst();
VertexProperty<Integer, Double> rank = analyst.pagerank(graph, 0.001, 0.85, 100);
for (Entry<Integer, Double> entry : rank.getTopKValues(3)) {
System.out.println(entry.getKey() + "=" + entry.getValue());
}
Parent topic: Executing Builtin Algorithms