[1]:
import matplotlib.pyplot as plt
import straph as sg
[2]:
plt.rcParams["figure.figsize"] = (12,9)

Stream Graph Theory Properties

Most of the concepts described in the stream graph formalism are implemented in Straph. However some concepts also refer to graph theory to avoid any confusion in this section we focus on specific stream graph theory properties.

[3]:
path_directory = "examples/"
S = sg.read_stream_graph(path_nodes=path_directory + "example_nodes.sg",
                         path_links=path_directory + "example_links.sg")

Uniformity and Coverage

The uniformity is defined by

\frac{\sum_{uv\in V \times V}|T_u \cap T_v|}{\sum_{uv\in V \times V}|T_u \cup T_v|}

[10]:
unif = S.uniformity()
unif
[10]:
0.23795180722891565

The coverage is defined by \Large \frac{|W|}{|T \times V|}.

[11]:
cov = S.coverage()
cov
[11]:
0.7333333333333333

Degrees and Expected Degrees

[15]:
degrees = S.graph_property(sg.nx_degree)
_ = S.plot(degrees,title="Degree")
../_images/notebooks_Stream_Graph_Theory_Properties_33_0.png
[16]:
nodes_degree = S.degrees()
nodes_degree
[16]:
Counter({0: 0.5, 1: 0.6, 2: 0.2, 4: 1.2000000000000002, 3: 0.6, 5: 0.9})
[17]:
nodes_expected_degree = S.expected_node_degrees()
nodes_expected_degree
[17]:
Counter({0: 0.625,
         1: 0.6,
         2: 0.6666666666666666,
         3: 1.2,
         4: 1.2000000000000002,
         5: 1.125})
[18]:
d_bar = S.average_degree()
print("Average degree of S :\t", d_bar)
print("Degree of S :\t \t", S.stream_graph_degree())
print("Expected degree of S :\t", S.expected_stream_graph_degree())
Average degree of S :    0.7454545454545456
Degree of S :            0.3333333333333333
Expected degree of S :   0.9090909090909091

Neighbors and Neighborhood

The neighborhood is defined by TODO

[19]:
Ngh = S.neighborhood()
Ngh
[19]:
{0: {1: [0.0, 4.0, 8.0, 9.0]},
 1: {0: [0.0, 4.0, 8.0, 9.0], 2: [4.0, 5.0], 4: [7.0, 7.0]},
 2: {1: [4.0, 5.0], 3: [0.0, 1.0], 4: [5.0, 5.0]},
 3: {2: [0.0, 1.0], 4: [2.0, 4.0, 8.0, 10.0], 5: [3.0, 4.0]},
 4: {1: [7.0, 7.0],
  2: [5.0, 5.0],
  3: [2.0, 4.0, 8.0, 10.0],
  5: [0.0, 4.0, 6.0, 10.0]},
 5: {3: [3.0, 4.0], 4: [0.0, 4.0, 6.0, 10.0]}}
[20]:
nb_neighbors = S.nb_neighbors()
nb_neighbors
[20]:
Counter({0: 1, 1: 3, 2: 3, 4: 4, 3: 3, 5: 2})

Clustering Coefficient

[21]:
cc = S.clustering_coefficient()
print("Clustering coefficient :", cc)
cc_bar = S.average_clustering(cc=cc)
print("Average clustering : \t", cc_bar)
Clustering coefficient : Counter({3: 1.0, 5: 1.0, 4: 0.25, 0: 0, 1: 0, 2: 0})
Average clustering :     0.3522727272727273