Degree

In graph theory, the degree of a vertex (node) of a graph is the number of edges that are incident to the node. In Ultipa Graph, all per-node degree operations are conducted in a pure real-time fashion. Only whole-graph degree operations are invoked as tasks (asynchronously) due to computational complexity, especially on large graphs.

Note that in multigraphs, a loop (an edge whose starting node and ending node are identical) is counted as two edges

algo(out_degree)

  Basic     Real-time  

Out Degree is a per-node degree operation that calculates the total number of edges pointing away from a node, weight factor of edge could be applied.

Configuration items for out degree operations:

Item Data Type Specification Description
<node_id> int Ultipa ID To calculate for a specific node
<edge_property_name> string Edge property (numeric type) (Optional) The edge property (must be LTE first) to be used as the weight factor of edge, or use 1 as weight factor if not configured

Validity of write_back():

Not supported.

Example 1: Calculate the Out Degree of node (_id = 12)

algo(out_degree)
  .params( {node_id: 12} )
Figure: Running real-time Algorithm --- Out Degree

Example 2: To verify the result of Example 1, spread from node (_id = 12) via right-directed edges.

spread()
  .src(12).depth(1)
  .direction(right).limit(1000)
Figure: Verifying Algorithm Calculation Results with spread()

Note: A khop() query is NOT a proper way to verify a degree operation, since that khop() query returns a bunch of 'de-duplicated' neighbors that do not reflect the number of incident edges.

Example 3: Same as Example 1, but using edge property 'rank' as weight factor, return the sum of all edges' rank values

algo(out_degree)
  .params( {node_id: 12, edge_property_name: "rank"} )
Figure: Out Degree by Edge Property

The result shows that the Out Degree weighted by property 'rank' is 569 instead of 10 for a weightless Out Degree of node id=12.

algo(in_degree)

  Basic     Real-time  

In Degree is comparable to Out Degree, but with calculations done against the inbound edges of node.

Configuration items for in degree operations:

Item Data Type Specification Description
<node_id> int Ultipa ID To calculate for a specific node
<edge_property_name> string Edge property (numeric type) (Optional) The edge property (must be LTE first) to be used as the weight factor of edge, or use 1 as weight factor if not configured

Validity of write_back():

Not supported.

Example 1: Calculate the In Degree of node (_id = 12)

algo(in_degree)
  .params( {node_id: 12} )
Figure: Running Real-Time Algorithm - In Degree

Example 2: Calculate the In Degree with edge property 'rank' of node (_id = 12)

algo(in_degree)
  .params( {node_id: 12, edge_property_name: "rank"} )
Figure: In Degree by Edge Property

algo(degree)

  Basic     Real-time  

Degree is the summed total of In Degree and Out Degree of node.

Configuration items for degree operations:

Item Data Type Specification Description
<node_id> int Ultipa ID To calculate for a specific node
<edge_property_name> string Edge property (numeric type) (Optional) The edge property (must be LTE first) to be used as the weight factor of edge, or use 1 as weight factor if not configured

Validity of write_back():

Not supported.

Example 1: Calculate the degree of node id=12

algo(degree)
  .params( {node_id: 12} )

Example 2: Calculate the degree of node id=12 using edge property 'rank' as weight factor

algo(degree)
  .params( {node_id: 12, edge_property_name: "rank"} )
Figure: Real-Time Algorithm - Degree with Edge Property

The above result is also verified by the results from previous examples.

algo(out_degree_all)

  Basic  

Out Degree All is a degree calculation algorithm on out-degrees (weighted or not) for multiple nodes, or all nodes, in the graphset, the results can be ordered and partially returned.

Configuration items for whole-graph out degree operations:

Item Data Type Specification Description
<ids> []int Ultipa ID (Optional) To calculate for a group of nodes, or calculate for all nodes if not configured
<edge_property_name> string Edge property (numeric type) (Optional) The edge property (must be LTE first) to be used as the weight factor of edge, or use 1 as weight factor if not configured
<limit> int >0; -1 The maximum number of results to return; -1: return all the results
<order> string 'ASC' or 'DESC' (Optional) To arrange the results in ascending or descending order, or leave them un-ordered if not configured

Validity of write_back():

Approach Destination
To database node property #out_degree_all
To disk file /

Example 1: Calculate the out degrees for nodes (id=1,2,3,4,5,6,7), arrange the results in descending order and return the top 3.

algo(out_degree_all)
  .params( {ids: [1,2,3,4,5,6,7], limit: 3, order: 'DESC'} )
Figure: Real-Time Algorithm - Out Degree All Top 3

Example 2: Calculate the whole graph out degrees with edge property 'rank' being the weight factor, and write back to the database.

algo(out_degree_all)
  .params( {edge_property_name: "rank", limit: -1} )
  .write_back()
Figure: Algorithm Writing Back to Graphset

As seen from above, after running the graph-wide out-degrees with write_back() included, a new node property is created, which will simply be updated (refreshed) if this algorithm is invoked again.

algo(in_degree_all)

  Basic  

Similar to Out Degree All, the In Degree All calculates the nodes in-degrees for selective nodes or all nodes.

Configuration items for whole-graph in degree operations:

Item Data Type Specification Description
<ids> []int Ultipa ID (Optional) To calculate for a group of nodes, or calculate for all nodes if not configured
<edge_property_name> string Edge property (numeric type) (Optional) The edge property (must be LTE first) to be used as the weight factor of edge, or use 1 as weight factor if not configured
<limit> int >0; -1 The maximum number of results to return; -1: return all the results
<order> string 'ASC' or 'DESC' (Optional) To arrange the results in ascending or descending order, or leave them un-ordered if not configured

Validity of write_back():

Approach Destination
To database node property #in_degree_all
To disk file /

Example 1: Calculate In Degree for nodes (id=1,2,3,4,5,6,7), arrange the results in descending order and return the top 3.

algo(in_degree_all)
  .params( {ids: [1,2,3,4,5,6,7], limit: 3, order: 'DESC'} )

Example 2: Calculate all nodes' In Degree for node property 'rank'

algo(in_degree_all)
  .params( {edge_property_name: "rank", limit: -1} )

algo(degree_all)

  Basic  

Degree All is the summed total of In Degree All and Out Degree All that applied to selective nodes or graph-wide all nodes.

Configuration items for whole-graph degree operations:

Item Data Type Specification Description
<ids> []int Ultipa ID (Optional) To calculate for a group of nodes, or calculate for all nodes if not configured
<edge_property_name> string Edge property (numeric type) (Optional) The edge property (must be LTE first) to be used as the weight factor of edge, or use 1 as weight factor if not configured
<limit> int >0; -1 The maximum number of results to return; -1: return all the results
<order> string 'ASC' or 'DESC' (Optional) To arrange the results in ascending or descending order, or leave them un-ordered if not configured

Validity of write_back():

Approach Destination
To database node property #degree_all
To disk file /

Example 1: Calculate degrees for nodes (id=1,2,3,4,5,6,7), arrange the results in descending order and return the top 3.

algo(degree_all)
  .params( {ids: [1,2,3,4,5,6,7], limit: 3, order: 'DESC'} )

Example 2: Calculate all nodes' degree based on edge property 'rank'

algo(degree_all)
  .params( {edge_property_name: "rank", limit: -1} )