09.02.2015 Views

Sage Reference Manual: Graph Theory - Mirrors

Sage Reference Manual: Graph Theory - Mirrors

Sage Reference Manual: Graph Theory - Mirrors

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Sage</strong> <strong>Reference</strong> <strong>Manual</strong>: <strong>Graph</strong> <strong>Theory</strong>, Release 6.1.1<br />

clustering_average()<br />

Returns the average clustering coefficient.<br />

The clustering coefficient of a node i is the fraction of existing triangles containing node i and all possible<br />

triangles containing i: c i = T (i)/ ( k i<br />

)<br />

2<br />

where T (i) is the number of existing triangles through i, and ki is<br />

the degree of vertex i.<br />

A coefficient for the whole graph is the average of the c i .<br />

See also section “Clustering” in chapter “Algorithms” of [HSSNX].<br />

EXAMPLES:<br />

sage: (graphs.Frucht<strong>Graph</strong>()).clustering_average()<br />

0.25<br />

clustering_coeff(nodes=None, weight=False, return_vertex_weights=True)<br />

Returns the clustering coefficient for each vertex in nodes as a dictionary keyed by vertex.<br />

For an unweighted graph, the clustering coefficient of a node i is the fraction of existing triangles containing<br />

node i and all possible triangles containing i: c i = T (i)/ ( k i<br />

)<br />

2<br />

where T (i) is the number of existing<br />

triangles through i, and k i is the degree of vertex i.<br />

For weighted graphs the clustering is defined as the geometric average of the subgraph edge weights,<br />

normalized by the maximum weight in the network.<br />

The value of c i is assigned 0 if k i < 2.<br />

See also section “Clustering” in chapter “Algorithms” of [HSSNX].<br />

INPUT:<br />

•nodes - the vertices to inspect (default None, returns data on all vertices in graph)<br />

•weight - string or boolean (default is False). If it is a string it used the indicated edge property as<br />

weight. weight = True is equivalent to weight = ’weight’<br />

•return_vertex_weights is a boolean ensuring backwards compatibility with deprecated features<br />

of NetworkX 1.2. It should be set to False for all production code.<br />

EXAMPLES:<br />

sage: (graphs.Frucht<strong>Graph</strong>()).clustering_coeff().values()<br />

[0.3333333333333333, 0.3333333333333333, 0.0, 0.3333333333333333,<br />

0.3333333333333333, 0.3333333333333333, 0.3333333333333333,<br />

0.3333333333333333, 0.0, 0.3333333333333333, 0.3333333333333333,<br />

0.0]<br />

sage: (graphs.Frucht<strong>Graph</strong>()).clustering_coeff()<br />

{0: 0.3333333333333333, 1: 0.3333333333333333, 2: 0.0,<br />

3: 0.3333333333333333, 4: 0.3333333333333333,<br />

5: 0.3333333333333333, 6: 0.3333333333333333,<br />

7: 0.3333333333333333, 8: 0.0, 9: 0.3333333333333333,<br />

10: 0.3333333333333333, 11: 0.0}<br />

sage: (graphs.Frucht<strong>Graph</strong>()).clustering_coeff(weight=True,<br />

... return_vertex_weights=False)<br />

{0: 0.3333333333333333, 1: 0.3333333333333333, 2: 0.0,<br />

3: 0.3333333333333333, 4: 0.3333333333333333,<br />

5: 0.3333333333333333, 6: 0.3333333333333333,<br />

7: 0.3333333333333333, 8: 0.0, 9: 0.3333333333333333,<br />

10: 0.3333333333333333, 11: 0.0}<br />

sage: (graphs.Frucht<strong>Graph</strong>()).clustering_coeff(nodes=[0,1,2])<br />

{0: 0.3333333333333333, 1: 0.3333333333333333, 2: 0.0}<br />

1.1. Generic graphs 27

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!