libpysal.graph.GraphSummary

class libpysal.graph.GraphSummary(graph, asymmetries=False)[source]

Graph Summary

An object containing the statistical attributes summarising the Graph and its basic properties.

n_nodes[source]

number of Graph nodes

Type:

int

n_edges[source]

number of Graph edges

Type:

int

n_components[source]

number of connected components

Type:

int

n_isolates[source]

number of isolates (nodes with no neighbors)

Type:

int

nonzero[source]

number of edges with nonzero weight

Type:

int

pct_nonzero[source]

percentage of nonzero weights

Type:

float

n_asymmetries[source]

number of intrinsic asymmetries

Type:

int

cardinalities_mean[source]

mean number of neighbors

Type:

float

cardinalities_std[source]

standard deviation of number of neighbors

Type:

float

cardinalities_min[source]

minimal number of neighbors

Type:

float

cardinalities_25[source]

25th percentile of number of neighbors

Type:

float

cardinalities_50[source]

50th percentile (median) of number of neighbors

Type:

float

cardinalities_75[source]

75th percentile of number of neighbors

Type:

float

cardinalities_max[source]

maximal number of neighbors

Type:

float

weights_mean[source]

mean edge weight

Type:

float

weights_std[source]

standard deviation of edge weights

Type:

float

weights_min[source]

minimal edge weight

Type:

float

weights_25[source]

25th percentile of edge weights

Type:

float

weights_50[source]

50th percentile (median) of edge weights

Type:

float

weights_75[source]

75th percentile of edge weights

Type:

float

weights_max[source]

maximal edge weight

Type:

float

s0[source]

S0 (global) sum of weights

s0 is defined as

\[s0=\sum_i \sum_j w_{i,j}\]

s0, s1, and s2 reflect interaction between observations and are used to compute standard errors for spatial autocorrelation estimators.

Type:

float

s1[source]

S1 sum of weights

s1 is defined as

\[s1=1/2 \sum_i \sum_j \Big(w_{i,j} + w_{j,i}\Big)^2\]

s0, s1, and s2 reflect interaction between observations and are used to compute standard errors for spatial autocorrelation estimators.

Type:

float

s2[source]

S2 sum of weights

s2 is defined as

\[s2=\sum_j \Big(\sum_i w_{i,j} + \sum_i w_{j,i}\Big)^2\]

s0, s1, and s2 reflect interaction between observations and are used to compute standard errors for spatial autocorrelation estimators.

Type:

float

diag_g2[source]

diagonal of \(GG\)

Type:

np.ndarray

diag_gtg[source]

diagonal of \(G^{'}G\)

Type:

np.ndarrray

diag_gtg_gg[source]

diagonal of \(G^{'}G + GG\)

Type:

np.ndarray

trace_g2[source]

trace of \(GG\)

Type:

np.ndarray

trace_gtg[source]

trace of \(G^{'}G\)

Type:

np.ndarrray

trace_gtg_gg[source]

trace of \(G^{'}G + GG\)

Type:

np.ndarray

Examples

>>> import geopandas as gpd
>>> from geodatasets import get_path
>>> nybb = gpd.read_file(get_path("nybb")).set_index("BoroName")
>>> nybb
                BoroCode  ...                                           geometry
BoroName                 ...
Staten Island         5  ...  MULTIPOLYGON (((970217.022 145643.332, 970227....
Queens                4  ...  MULTIPOLYGON (((1029606.077 156073.814, 102957...
Brooklyn              3  ...  MULTIPOLYGON (((1021176.479 151374.797, 102100...
Manhattan             1  ...  MULTIPOLYGON (((981219.056 188655.316, 980940....
Bronx                 2  ...  MULTIPOLYGON (((1012821.806 229228.265, 101278...
[5 rows x 4 columns]
>>> contiguity = graph.Graph.build_contiguity(nybb)
>>> contiguity
<Graph of 5 nodes and 10 nonzero edges indexed by
    ['Staten Island', 'Queens', 'Brooklyn', 'Manhattan', 'Bronx']>
>>> summary = contiguity.summary(asymmetries=True)
>>> summary
Graph Summary Statistics
========================
Graph indexed by:
['Staten Island', 'Queens', 'Brooklyn', 'Manhattan', 'Bronx']
==============================================================
number of nodes:                                             5
number of edges:                                            10
number of connected components:                              2
number of isolates:                                          1
number of non-zero edges:                                   10
Percentage of non-zero edges:                           44.00%
number of asymmetries:                                       0
--------------------------------------------------------------
Cardinalities
==============================================================
Mean:                       2    25%:                        2
Standard deviation:         1    50%:                        2
Min:                        0    75%:                        3
Max:                        3
--------------------------------------------------------------
Weights
==============================================================
Mean:                       1    25%:                        1
Standard deviation:         0    50%:                        1
Min:                        1    75%:                        1
Max:                        1
--------------------------------------------------------------
Sum of weights
==============================================================
S0:                                                         10
S1:                                                         20
S2:                                                        104
--------------------------------------------------------------
Traces
==============================================================
GG:                                                         10
G'G:                                                        10
G'G + GG:                                                   20
>>> summary.s1
20

Create GraphSummary

Parameters:
graph : Graph

asymmetries : bool

whether to compute n_asymmetries, which is considerably more expensive than the other attributes. By default False.