Graphs¶
Graphs are composed of two sets, one of vertices, and one of edges that connect exactly two (possibly not distinct) vertices. The degree of a vertex is the number of edges attached to it.
Setup¶
Establish a connection to the ATK REST Server. This handle will be used for the remainder of the script.
Get server URL and credentials file from the TAP administrator.
atk_server_uri = os.getenv("ATK_SERVER_URI", ia.server.uri)
credentials_file = os.getenv("ATK_CREDENTIALS", "")
Set the server, and use the credentials to connect to the ATK REST server.
ia.server.uri = atk_server_uri
ia.connect(credentials_file)
Build a Graph¶
The example below shows how to build a frame using a vertexlist and an edgelist.
vertex_frame = ia.Frame(
ia.UploadRows([["vertex1"],
["vertex2"],
["vertex3"],
["vertex4"],
["vertex5"]],
[("vertex_name", str)]))
edge_frame = ia.Frame(
ia.UploadRows([["vertex2", "vertex3"],
["vertex2", "vertex1"],
["vertex2", "vertex4"],
["vertex2", "vertex5"]],
[("from", str), ("to", str)]))
The graph is a center vertex (vertex2), with four vertices each attached to the center vertex. This is known as a star graph. It can be visualized as a plus sign.
To create a graph define the vertices, then define the edges.
The degree of a vertex is how many edges are connected to the vertex.
degrees = graph.annotate_degrees("degree")
degree_list = degrees["vertex"].take(5)
known_list = [[4, u'vertex', u'vertex4', 1],
[1, u'vertex', u'vertex1', 1],
[5, u'vertex', u'vertex5', 1],
[2, u'vertex', u'vertex2', 4],
[3, u'vertex', u'vertex3', 1]]
for i in known_list:
self.assertIn(i, degree_list)