Table Of Contents

Graph annotate_weighted_degrees


annotate_weighted_degrees(self, output_property_name, degree_option=None, input_edge_labels=None, edge_weight_property=None, edge_weight_default=None)

Calculates the weighted degree of each vertex with respect to an (optional) set of labels.

Parameters:

output_property_name : unicode

property name of where to store output

degree_option : unicode (default=None)

choose from ‘out’, ‘in’, ‘undirected’

input_edge_labels : list (default=None)

labels of edge types that should be included

edge_weight_property : unicode (default=None)

property name of edge weight, if not provided all edges are weighted equally

edge_weight_default : float64 (default=None)

default edge weight

Returns:

: dict

Pulls graph from underlying store, calculates weighted degrees and writes them into the property specified, and then writes the output graph to the underlying store.

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 toolkit provides a routine annotate_degrees for calculating the degrees of vertices. This calculation could be performed with a Gremlin query on smaller datasets because Gremlin queries cannot be executed on a distributed scale. 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 this routine for the distributed calculation of weighted vertex degrees.

Examples

Given a directed graph with three nodes and two edges like this:

>>> g.query.gremlin('g.V')
Out[23]: {u'results': [{u'_id': 28304, u'_label': u'vertex', u'_type': u'vertex', u'_vid': 4, u'source': 2}, {u'_id': 21152, u'_label': u'vertex', u'_type': u'vertex', u'_vid': 1, u'source': 1}, {u'_id': 28064, u'_label': u'vertex', u'_type': u'vertex', u'_vid': 3, u'source': 3}], u'run_time_seconds': 1.245}

>>> g.query.gremlin('g.E')
Out[24]: {u'results': [{u'_eid': 3, u'_id': u'34k-gbk-bth-lnk', u'_inV': 28064, u'_label': u'edge', u'_outV': 21152, u'_type': u'edge', u'weight': 0.01}, {u'_eid': 4, u'_id': u'1xw-gbk-bth-lu8', u'_inV': 28304, u'_label': u'edge', u'_outV': 21152, u'_type': u'edge', u'weight': 0.1}], u'run_time_seconds': 1.359}

>>> h = g.annotate_weighted_degrees('weight',  edge_weight_property = 'weight')