Graph annotate_degrees¶
-
annotate_degrees
(self, output_property_name, degree_option=None, input_edge_labels=None)¶ Make new graph with degrees.
Parameters: output_property_name : unicode
The name of the new property. The degree is stored in this property.
degree_option : unicode (default=None)
Indicator for the definition of degree to be used for the calculation. Permitted values:
- “out” (default value) : Degree is calculated as the out-degree.
- “in” : Degree is calculated as the in-degree.
- “undirected” : Degree is calculated as the undirected degree. (Assumes that the edges are all undirected.)
Any prefix of the strings “out”, “in”, “undirected” will select the corresponding option.
input_edge_labels : list (default=None)
If this list is provided, only edges whose labels are included in the given set will be considered in the degree calculation. In the default situation (when no list is provided), all edges will be used in the degree calculation, regardless of label.
Returns: : dict
Dictionary containing the vertex type as the key and the corresponding vertex’s frame with a column storing the annotated degree for the vertex in a user specified property. Call dictionary_name[‘label’] to get the handle to frame whose vertex type is label.
Creates a new graph which is the same as the input graph, with the addition that every vertex of the graph has its degree stored in a user-specified property.
Degree Calculation
A fundamental quantity in graph analysis is the degree of a vertex: The degree of a vertex is the number of edges adjacent to it.
For a directed edge relation, a vertex has both an out-degree (the number of edges leaving the vertex) and an in-degree (the number of edges entering the vertex).
The Trusted Analytics Platform routine
annotate_degrees
can be executed at distributed scale.In the presence of edge weights, vertices can have weighted degrees: The weighted degree of a vertex is the sum of weights of edges adjacent to it. Analogously, the weighted in-degree of a vertex is the sum of the weights of the edges entering it, and the weighted out-degree is the sum of the weights of the edges leaving the vertex.
The toolkit provides annotate_weighted_degrees for the distributed calculation of weighted vertex degrees.
Examples
>>> graph = ta.Graph()
>>> graph.define_vertex_type('source') [===Job Progress===] >>> graph.vertices['source'].add_vertices(vertex_frame, 'source', 'label') [===Job Progress===] >>> graph.define_edge_type('edges','source', 'source', directed=False) [===Job Progress===] >>> graph.edges['edges'].add_edges(edge_frame, 'source', 'dest', ['weight']) [===Job Progress===] >>> result = graph.annotate_degrees("outEdgesCount",degree_option="out") [===Job Progress===] >>> result['source'].inspect() [#] _vid _label source label outEdgesCount =============================================== [0] 1 source 1 1.0 3 [1] 2 source 2 1.0 2 [2] 3 source 3 5.0 2 [3] 4 source 4 5.0 2 [4] 5 source 5 5.0 1 >>> result = graph.annotate_degrees("inEdgesCount",degree_option="in") [===Job Progress===] >>> result['source'].inspect() [#] _vid _label source label inEdgesCount ============================================== [0] 1 source 1 1.0 3 [1] 2 source 2 1.0 2 [2] 3 source 3 5.0 2 [3] 4 source 4 5.0 2 [4] 5 source 5 5.0 1