turicreate.SGraph

class turicreate.SGraph(vertices=None, edges=None, vid_field='__id', src_field='__src_id', dst_field='__dst_id', _proxy=None)

A scalable graph data structure. The SGraph data structure allows arbitrary dictionary attributes on vertices and edges, provides flexible vertex and edge query functions, and seamless transformation to and from SFrame.

There are several ways to create an SGraph. The simplest way is to make an empty SGraph then add vertices and edges with the add_vertices() and add_edges() methods. SGraphs can also be created from vertex and edge lists stored in SFrames. Columns of these SFrames not used as vertex IDs are assumed to be vertex or edge attributes.

Please see the User Guide for a more detailed introduction to creating and working with SGraphs.

Parameters:
vertices : SFrame, optional

Vertex data. Must include an ID column with the name specified by the vid_field parameter. Additional columns are treated as vertex attributes.

edges : SFrame, optional

Edge data. Must include source and destination ID columns as specified by src_field and dst_field parameters. Additional columns are treated as edge attributes.

vid_field : str, optional

The name of vertex ID column in the vertices SFrame.

src_field : str, optional

The name of source ID column in the edges SFrame.

dst_field : str, optional

The name of destination ID column in the edges SFrame.

See also

SFrame

Notes

  • SGraphs are structurally immutable. In the example below, the add_vertices() and add_edges() commands both return a new graph; the old graph gets garbage collected.

Examples

>>> from turicreate import SGraph, Vertex, Edge
>>> g = SGraph()
>>> verts = [Vertex(0, attr={'breed': 'labrador'}),
             Vertex(1, attr={'breed': 'labrador'}),
             Vertex(2, attr={'breed': 'vizsla'})]
>>> g = g.add_vertices(verts)
>>> g = g.add_edges(Edge(1, 2))

Methods

SGraph.add_edges(edges[, src_field, dst_field]) Add edges to the SGraph.
SGraph.add_vertices(vertices[, vid_field]) Add vertices to the SGraph.
SGraph.copy() Returns a shallow copy of the SGraph.
SGraph.get_edge_fields() Return a list of edge attribute fields in the graph.
SGraph.get_edges(self[, src_ids, dst_ids, …]) Return a collection of edges and their attributes.
SGraph.get_fields() Return a list of vertex and edge attribute fields in the SGraph.
SGraph.get_neighborhood(ids[, radius, …]) Retrieve the graph neighborhood around a set of vertices, ignoring edge directions.
SGraph.get_vertex_fields() Return a list of vertex attribute fields in the SGraph.
SGraph.get_vertices(self[, ids, fields, format]) Return a collection of vertices and their attributes.
SGraph.save(filename[, format]) Save the SGraph to disk.
SGraph.select_fields(fields) Return a new SGraph with only the selected fields.
SGraph.summary() Return the number of vertices and edges as a dictionary.
SGraph.triple_apply(triple_apply_fn, …[, …]) Apply a transform function to each edge and its associated source and target vertices in parallel.