superblockify.metrics package#

Submodules#

superblockify.metrics.distances module#

Distance calculation for the network metrics.

superblockify.metrics.distances.calculate_euclidean_distance_matrix_haversine(graph, node_order=None, plot_distributions=False)[source]#

Calculate the Euclidean distances between all nodes in the graph.

Uses the Haversine formula to calculate the distances between all nodes in the graph. The coordinates are in degrees.

Parameters:
graphnetworkx.Graph

The graph to calculate the distance matrix for

node_orderlist, optional

The order of the nodes in the distance matrix. If None, the ordering is produced by graph.nodes().

plot_distributionsbool, optional

If True, plot the distributions of the Euclidean distances and coordinates. Sanity check for the coordinate values.

Returns:
dist_matrixndarray

The distance matrix for the partitioning. dist_matrix[i, j] is the Euclidean distance between node i and node j.

Raises:
ValueError

If coordinates are not numeric or not in the range [-90, 90] for latitude and [-180, 180] for longitude.

superblockify.metrics.distances.calculate_euclidean_distance_matrix_projected(graph, node_order=None, plot_distributions=False)[source]#

Calculate the Euclidean distances between all nodes in the graph.

Uses the x and y coordinates of the nodes of a projected graph. The coordinates are in meters.

Parameters:
graphnetworkx.Graph

The graph to calculate the distance matrix for. The graph should be projected.

node_orderlist, optional

The order of the nodes in the distance matrix. If None, the ordering is produced by graph.nodes().

plot_distributionsbool, optional

If True, plot the distributions of the Euclidean distances and coordinates. Sanity check for the coordinate values.

Returns:
dist_matrixndarray

The distance matrix for the partitioning. dist_matrix[i, j] is the Euclidean distance between node i and node j.

Raises:
ValueError

If the graph is not projected.

superblockify.metrics.distances.calculate_partitioning_distance_matrix(partitioner, weight=None, unit_symbol=None, node_order=None, plot_distributions=False, check_overlap=True, max_mem_factor=0.2)[source]#

Calculate the distance matrix for the partitioning.

This is the pairwise distance between all pairs of nodes, where the shortest paths are only allowed to traverse edges in the start and goal partitions and unpartitioned edges. For this we calculate the distances and predecessors on the sparsified graph and the subgraphs separately. Then we combine the distances and predecessors to get a full distance matrix. We cannot do one big calculation, because the restrictions, to only enter/leave, are dynamic and depend on the start and goal node.

Parameters:
partitionerBasePartitioner

The partitioner to calculate the distance matrix for

weightstr, optional

The edge attribute to use as weight. If None, all edges have weight 1.

unit_symbolstr, optional

The unit symbol to use for the weight.

node_orderlist, optional

The order of the nodes in the distance matrix. If None, the ordering is produced by graph.nodes().

plot_distributionsbool, optional

If True, plot the distributions of the Euclidean distances and coordinates.

check_overlapbool, optional

If True, check that the partitions do not overlap node-wise.

max_mem_factorfloat, optional

The maximal memory factor to use for filling up the restricted distance matrices as tensor. Otherwise, using vectorized version.

Returns:
dist_matrixndarray

The distance matrix for the partitioning. dist_matrix[i, j] is the distance between node i and node j for the given rules of the partitioning. In the order of node_order if given, otherwise as produced by graph.nodes().

predecessorsndarray

The predecessor matrix for the partitioning. predecessors[i, j] is the predecessor of node j on the shortest path from node i for the given rules of the partitioning.

Raises:
ValueError

If partitions don’t have unique names.

ValueError

If the partitions overlap node-wise. For nodes considered to be in the partition, see BasePartitioner.get_partition_nodes().

superblockify.metrics.distances.calculate_path_distance_matrix(graph, weight=None, unit_symbol=None, node_order=None, plot_distributions=False, log_debug=True)[source]#

Calculate the distance matrix for the partitioning.

Use cythonized scipy.sparse.csgraph functions to calculate the distance matrix.

Generally Dijkstra’s algorithm with a Fibonacci heap is used. It’s approximate computational cost is O[N(N*k + N*log(N))] where N is the number of nodes and k is the average number of edges per node. We use this, because our graphs are usually sparse. For dense graphs, the Floyd-Warshall algorithm can be implemented with O[N^3] computational cost. [1]

Runtime comparison:

  • Scheveningen, NL (N = 1002, E = 2329):
    • Dijkstra: 172ms

    • Floyd-Warshall: 193ms

  • Liechtenstein, LI (N = 1797, E = 4197):
    • Dijkstra: 498ms

    • Floyd-Warshall: 917ms

  • Copenhagen, DK (N = 7806, E = 19565):
    • Dijkstra: 14.65s

    • Floyd-Warshall: 182.03s

  • Barcelona, ES (N = 8812, E = 16441):
    • Dijkstra: 18.21s

    • Floyd-Warshall: 134.69s

(simple, one-time execution)

The input graph will be converted to a scipy sparse matrix in CSR format. Compressed Sparse Row format is a sparse matrix format that is efficient for arithmetic operations. [2]

Parameters:
graphnetworkx.Graph

The graph to calculate the distance matrix for

weightstr, optional

The edge attribute to use as weight. If None, all edge weights are 1.

unit_symbolstr, optional

The unit symbol to use for the distance matrix, like ‘s’ for seconds.

node_orderlist, optional

The order of the nodes in the distance matrix. If None, the ordering is produced by graph.nodes().

plot_distributionsbool, optional

If True, a histogram of the distribution of the shortest path lengths is plotted.

log_debugbool, optional

If True, log runtime and graph information at debug level.

Returns:
dist_matrixndarray

The distance matrix for the partitioning. dist_matrix[i, j] is the shortest path length from node i to node j.

predecessorsndarray

The predecessors for the distance matrix. predecessors[i, j] is the node before node j on the shortest path from node i to node j. [1]

Raises:
ValueError

If the graph has negative edge weights.

References

[1] (1,2)

SciPy 1.10.0 Reference Guide, scipy.sparse.csgraph.shortest_path https://docs.scipy.org/doc/scipy-1.10.0/reference/generated/scipy.sparse.csgraph.shortest_path.html (accessed February 21, 2023)

[2]

SciPy 1.10.0 Reference Guide, scipy.sparse.csr_matrix https://docs.scipy.org/doc/scipy-1.10.0/reference/generated/scipy.sparse.csr_matrix.html (accessed February 21, 2023)

superblockify.metrics.distances.shortest_paths_restricted(graph, partitions, weight, node_order, max_mem_factor=0.2)[source]#

Calculate restricted shortest paths.

Shortest distances and predecessors with restrictions of not passing through partitions. The passed partitions is a dictionary with the partition names as keys and the partition as value. The partition is a dictionary with the keys subgraph, nodes and nodelist. The dict needs to have a special partition, called sparsified, which is the sparsified graph. The nodes key is a list of nodes that are exclusive to the partition, i.e. nodes that are not shared with the sparsified graph or on partition boundaries. The nodelist key is a list of nodes that are exclusive to the partition and nodes that are shared with the sparsified graph. The subgraphs all need to be graphs views of a shared graph. The Partitioner class produces such partitions, after passing the integrated is_valid_partitioning() checks.

Parameters:
graphnetworkx.MultiDiGraph

The graph to calculate the shortest paths for.

partitionsdict

The partitions to calculate the shortest paths for. The keys are the partition names and the values are dictionaries with the keys subgraph, nodes and nodelist.

weightstr or None, optional

The edge attribute to use as weight. If None, all edge weights are 1.

node_orderlist

The order of the nodes in the distance matrix.

max_mem_factorfloat, optional

The maximum fraction to use in the fully vectorized calculation. Defaults to 0.2. Otherwise, the calculation is iterated over the partition indices.

Returns:
dist_matrixndarray

The distance matrix for the partitioning.

pred_matrixndarray

The predecessor matrix for the partitioning.

Notes

For usage with a Partitioner, see calculate_partitioning_distance_matrix().

superblockify.metrics.measures module#

Measures for the metrics module.

superblockify.metrics.measures.add_ltn_means(components, edge_attr)[source]#

Add mean of attributes to each Superblock.

Writes the mean of the specified edge attribute(s) to each Superblock in the list of components. The mean is calculated as the mean of each attribute in the Superblock subgraph. Works in-place and adds mean_{attr} to each Superblock.

Parameters:
componentslist of dict

List of dictionaries of Superblock components.

edge_attrkey or list of keys

Edge attribute(s) to calculate the mean of.

superblockify.metrics.measures.add_relative_changes(components, attr_pairs)[source]#

Add relative difference of attributes to each Superblock.

Measured in terms of percentual increase using superblockify.utils.percentual_increase().

Write the relative percentual change of the specified edge attribute(s) to each Superblock in the list of components. The relative change is the percentual change of the first to the second attribute. Works in-place and adds change_{attr1} to each Superblock. If attr1 has a value of 2 and attr2 has a value of 1, the relative change is -0.5, a 50% decrease. If attr1 has a value of 4 and attr2 has a value of 6, the relative change is 0.5, a 50% increase.

Parameters:
componentslist of dict

List of dictionaries of Superblock components.

attr_pairslist of tuples with two keys

List of attribute pairs to calculate the relative change of.

Raises:
KeyError

If any key cannot be found in the Superblocks.

superblockify.metrics.measures.betweenness_centrality(graph, node_order, dist_matrix, predecessors, weight='length', attr_suffix=None, k=None, seed=None, max_range=None)[source]#

Calculate several types of betweenness centrality for the nodes and edges.

Uses the predecessors to calculate the betweenness centrality of the nodes and edges. The normalized betweenness centrality is calculated, length-scaled, and linearly scaled betweenness centrality is calculated for the nodes and edges. When passing a k, the summation is only done over k random nodes. [1] [2] [3]

Parameters:
graphnx.MultiDiGraph

The graph to calculate the betweenness centrality for, distances and predecessors must be calculated for this graph

node_orderlist

Indicating the order of the nodes in the distance matrix

dist_matrixnp.ndarray

The distance matrix for the network measures, as returned by superblockify.metrics.distances.calculate_path_distance_matrix()

predecessorsnp.ndarray

Predecessors matrix of the graph, as returned by superblockify.metrics.distances.calculate_path_distance_matrix()

weightstr, optional

The edge attribute to use as weight to decide which multi-edge to attribute the betweenness centrality to, by default “length”. If None, the first edge of the multi-edge is used.

attr_suffixstr, optional

The suffix to append to the attribute names, by default None

kint, optional

The number of nodes to calculate the betweenness centrality for, by default None

seedint, random_state, or None (default)

Indicator of random number generation state. See Randomness for additional details.

max_rangefloat, optional

The maximum path length to consider, by default None, which means no maximum path length. It is measured in unit of the weight attribute.

Raises:
ValueError

If weight is not None, and the graph does not have the weight attribute on all edges.

Notes

Works in-place on the graph.

It Does not include endpoints.

Modified from networkx.algorithms.centrality.betweenness.

The weight attribute is not used to determine the shortest paths, these are taken from the predecessor matrix. It is only used for parallel edges to decide which edge to attribute the betweenness centrality to.

If there are \(<=\) 2 nodes, node betweenness is 0 for all nodes. If there are \(<=\) 1 edges, edge betweenness is 0 for all edges.

References

[1]

Linton C. Freeman: A Set of Measures of Centrality Based on Betweenness. Sociometry, Vol. 40, No. 1 (Mar., 1977), pp. 35-41 https://doi.org/10.2307/3033543

[2]

Brandes, U. (2001). A faster algorithm for betweenness centrality. Journal of Mathematical Sociology, 25(2), 163–177. https://doi.org/10.1080/0022250X.2001.9990249

[3]

Brandes, U. (2008). On variants of shortest-path betweenness centrality and their generic computation. Social Networks, 30(2), 136–145. https://doi.org/10.1016/j.socnet.2007.11.001

superblockify.metrics.measures.calculate_coverage(partitioner, weight)[source]#

Calculate the coverage of the partitioner.

Calculates the coverage of the partitions weighted by the edge attribute self.weight. The coverage is the sum of the weights of the edges between

Parameters:
partitionerPartitioner

The partitioner to calculate the coverage for

weightstr

The edge attribute to use as weight.

Returns:
float

The coverage of the partitioner, between 0 and 1.

Raises:
ValueError

If the partitioner has an empty graph.

superblockify.metrics.measures.calculate_directness(distance_matrix, measure1, measure2)[source]#

Calculate the directness for the given network measures.

The directness is the mean of the ratios between the distances of the two network measures.

If any of the distances is 0 or infinite, it is ignored in the calculation.

Parameters:
distance_matrixdict

The distance matrix for the network measures, as returned by instance attribute superblockify.metrics.metric.Metric.distance_matrix

measure1str

The first network measure

measure2str

The second network measure

Returns:
float

The directness of the network measures

Notes

\[D_{E/S}=\left\langle\frac{d_1(i, j)}{d_2(i, j)}\right\rangle_{i\neq j}\]
superblockify.metrics.measures.calculate_global_efficiency(distance_matrix, measure1, measure2)[source]#

Calculate the global efficiency for the given network measures.

The global efficiency is the ratio between the sums of the inverses of the distances of the two network measures.

If any of the distances is 0 or infinite, it is ignored in the calculation.

Parameters:
distance_matrixdict

The distance matrix for the network measures, as returned by instance attribute superblockify.metrics.metric.Metric.distance_matrix

measure1str

The first network measure

measure2str

The second network measure

Returns:
float

The global efficiency of the network measures

Notes

\[E_{\text{glob},S/E}=\frac{\sum_{i \neq j}\frac{1}{d_S(i, j)}} {\sum_{i \neq j} \frac{1}{d_E(i, j)}}\]
superblockify.metrics.measures.calculate_high_bc_clustering(node_x, node_y, node_betweenness, percentile)[source]#

Calculate the high betweenness clustering coefficient and anisotropy for a given percentile of nodes with the highest betweenness. [1]

Parameters:
node_xlist

List of x coordinates of the nodes.

node_ylist

List of y coordinates of the nodes, ordered by node index.

node_betweennesslist

List of betweenness values for each node, ordered by node index.

percentilefloat

Percentile of nodes with the highest betweenness to calculate the clustering coefficient for. Between 0 and 1.

Returns:
high_bc_clusteringfloat

Clustering coefficient for the nodes with the highest betweenness.

high_bc_anisotropyfloat

Anisotropy for the nodes with the highest betweenness.

Notes

The high betweenness clustering coefficient is calculated as the average clustering coefficient of the nodes with the highest betweenness. The high betweenness anisotropy is calculated as the average anisotropy of the nodes with the highest betweenness.

References

[1]

Kirkley, A., Barbosa, H., Barthelemy, M. & Ghoshal, G. From the betweenness centrality in street networks to structural invariants in random planar graphs. Nat Commun 9, 2501 (2018). https://www.nature.com/articles/s41467-018-04978-z

superblockify.metrics.measures.rel_increase(value_i, value_j)[source]#

Calculate the relative increase of matrix value_i and value_j.

Ignore np.inf values and 0 values in the denominator.

superblockify.metrics.measures.write_relative_increase_to_edges(graph, distance_matrix, node_list, measure1, measure2)[source]#

Write the relative increase of the distance matrix to the edges of the graph.

For each edge, the relative increases to and from every node to the two nodes of the edge are averaged and written to the edge attribute “rel_increase”.

Parameters:
graphnx.Graph

The graph to write the relative increase to

distance_matrixdict

The distance matrix for the network measures, as returned by instance attribute superblockify.metrics.metric.Metric.distance_matrix

node_listlist

Indicating the order of the nodes in the distance matrix

measure1str

The first network measure

measure2str

The second network measure

superblockify.metrics.metric module#

Metric object for the superblockify package.

class superblockify.metrics.metric.Metric(unit='time')[source]#

Bases: object

Metric object to be used with partitioners.

A metric object is used to calculate the quality of a partitioning. It holds the information on several network metrics, which can be read, and can be used to calculate them when passing a Partitioner object.

There are different network measures - \(d_E(i, j)\): Euclidean - \(d_S(i, j)\): Shortest path on full graph - \(d_N(i, j)\): Shortest path with ban through Superblocks

We define several types of combinations of these metrics: (i, j are nodes in the graph)

The network metrics are the following:

  • Coverage (fraction of network covered by a partition):

    C = sum(1 if i in partition else 0) / len(graph.nodes)

  • Components (number of connected components):

    C = len(graph.components)

  • Average path length:
    • \(A(E) = \mathrm{mean}(d_E(i, j))\) where \(i \neq j\)

    • \(A(S) = \mathrm{mean}(d_S(i, j))\) where \(i \neq j\)

    • \(A(N) = \mathrm{mean}(d_N(i, j))\) where \(i \neq j\)

  • Directness:
    • \(D(E, S) = \mathrm{mean}(d_E(i, j) / d_S(i, j))\) where \(i \neq j\)

    • \(D(E, N) = \mathrm{mean}(d_E(i, j) / d_N(i, j))\) where \(i \neq j\)

    • \(D(S, N) = \mathrm{mean}(d_S(i, j) / d_N(i, j))\) where \(i \neq j\)

  • Global efficiency:
    • \(G(i; S/E) = \sum(1/d_S(i, j)) / \sum(1/d_E(i, j))\) where for each sum \(i \neq j\)

    • \(G(i; N/E) = \sum(1/d_N(i, j)) / \sum(1/d_E(i, j))\) where for each sum \(i \neq j\)

    • \(G(i; N/S) = \sum(1/d_N(i, j)) / \sum(1/d_S(i, j))\) where for each sum \(i \neq j\)

Attributes:
coveragefloat

The coverage of the partitioning takes of the whole graph

num_componentsint

The number of components in the graph

avg_path_lengthdict

The average path length of the graph for each network measure {“E”: float, “S”: float, “N”: float}

directnessdict

The directness of the graph for the network measure ratios {“ES”: float, “EN”: float, “SN”: float}

global_efficiencydict

The global efficiency of the graph for each network measure {“SE”: float, “NE”: float, “NS”: float}

local_efficiencydict

The local efficiency of the graph for each network measure {“SE”: float, “NE”: float, “NS”: float}

high_bc_clusteringfloat

The clustering coefficient of the nodes with the highest betweenness centrality

high_bc_anisotropyfloat

The anisotropy of the nodes with the highest betweenness centrality

distance_matrixdict

The distance matrices for each network measure

predecessor_matrixdict

The predecessor matrices for each network measure

unitstr

The unit to use for the shortest distance calculation, either “time”, “distance”, None for hops, or a custom unit string found as edge attribute in the graph

node_listlist

The list of nodes in the graph, used for the distance matrices

graph_statsdict

The general graph statistics, see superblockify.metrics.graph_stats.basic_graph_stats()

Methods

calculate_all(partitioner[, ...])

Calculate all metrics for the partitioning.

calculate_all_measure_sums()

Based on the distance matrix, calculate the network measures.

calculate_before(partitioner[, ...])

Calculate metrics on unrestricted graph

calculate_general_stats(graph)

Calculate general graph metrics

calculate_high_bc_clustering(graph, percentile)

Calculate the high betweenness node clustering and anisotropy.

load(name)

Load a partitioning from a file.

make_all_plots(partitioner)

Make all plots for the metrics.

save(folder, name[, dismiss_distance_matrix])

Save the metric to a file.

unit_symbol()

Return unit string represented by the unit attribute.

calculate_all(partitioner, replace_max_speeds=True, make_plots=False)[source]#

Calculate all metrics for the partitioning.

If calculate_before() has been called before partitioning, only the remaining metrics are calculated.

Parameters:
partitionerBasePartitioner

The partitioner object to calculate the metrics for

replace_max_speedsbool, optional

If True and unit is “time”, calculate the quickest paths in the restricted graph with the max speeds V_MAX_LTN and V_MAX_SPARSE set in superblockify.config. Default is True.

make_plotsbool, optional

Whether to make plots of the distributions of the distances for each network measure, by default False

calculate_all_measure_sums()[source]#

Based on the distance matrix, calculate the network measures.

Calculate the directness, global and local efficiency for each network measure and write them to the corresponding attributes.

calculate_before(partitioner, betweenness_range=None, make_plots=False)[source]#

Calculate metrics on unrestricted graph

Metrics that should be available to partitioners for use in their partitioning algorithm. This includes

  • Shortest paths and distances on the unrestricted graph

  • Betweenness centralities on the unrestricted graph

Parameters:
partitionerBasePartitioner

The partitioner object to calculate the metrics for

betweenness_rangeint, optional

The range to use for calculating the betweenness centrality, by default None, which uses the whole graph. If it is not None, two types of betweenness centralities are calculated. The whole one is always needed for other statistics. Its unit is determined by the unit attribute. For convenience, when using the “time” unit, the range is interpreted as meter able to travel at 30 km/h, and converted to seconds.

make_plotsbool, optional

Whether to plot the distributions of the shortest paths and distances, by default False.

calculate_general_stats(graph)[source]#

Calculate general graph metrics

Parameters:
graphGraph

The graph to calculate the metrics for

Notes

These metrics are only dependent on the graph, not on the partitioning. This way it is not necessary to calculate them for each partitioning, but only once per graph/city.

calculate_high_bc_clustering(graph, percentile)[source]#

Calculate the high betweenness node clustering and anisotropy.

High betweenness nodes are the nodes above the given percentile of the betweenness centrality distribution.

Parameters:
graphnetworkx.Graph

The graph to calculate the high betweenness node clustering for, needs to have x, y, and node_betweenness_normal attribute for each node.

percentilefloat or int

The percentile of the betweenness centrality to use as a threshold for high betweenness nodes. 0.0 < percentile < 100.0.

Raises:
ValueError

If percentile is not a float between 0.0 and 100.0.

classmethod load(name)[source]#

Load a partitioning from a file.

Parameters:
pathstr

The path to the file to load the partitioning from.

Returns:
partitioningPartitioning

The loaded partitioning.

make_all_plots(partitioner)[source]#

Make all plots for the metrics.

Parameters:
partitionerBasePartitioner

The partitioner object to calculate the metrics for

save(folder, name, dismiss_distance_matrix=False)[source]#

Save the metric to a file.

Will be saved as a pickle file at folder/name.metrics.

Parameters:
folderstr

The folder to save the metric to.

namestr

The name of the file to save the metric to.

dismiss_distance_matrixbool, optional

If True, the distance matrix will not be saved. Default is False.

unit_symbol()[source]#

Return unit string represented by the unit attribute.

Returns:
str

The unit symbol, either “s”, “m”, “hops” or the unit string in brackets.

superblockify.metrics.plot module#

Plotting functions for the network measures.

superblockify.metrics.plot.plot_component_wise_travel_increase(partitioner, distance_matrix, node_list, measure1, measure2, unit, **pg_kwargs)[source]#

Calculate and plot the component-wise travel increase.

For every component of the partitioner, calculate the relative travel increase. This is the mean of the relative travel increase for all pairs of nodes in the component. Relative travel increase is the percentual increase of the travel between measure 1 and measure 2.

Mean of d_1(i, j) / d_1(i, j) if i in the concerning component.

Parameters:
partitionerPartitioner

The partitioner to calculate the component-wise travel increase for.

distance_matrixdict

The distance matrix to calculate the component-wise travel increase for.

node_listlist

The list of nodes the distance matrices are sorted by.

measure1str

The name of the first measure. Key for the distance matrix.

measure2str

The name of the second measure. Key for the distance matrix.

unitstr

The unit of the distance matrices.

pg_kwargsdict

Keyword arguments for the plot_graph function.

Returns:
fig, axesmatplotlib.figure.Figure, matplotlib.axes.Axes

The figure and axes of the plot.

superblockify.metrics.plot.plot_distance_distributions(dist_matrix, dist_title, coords, coord_title, labels, distance_unit='m')[source]#

Plot the distributions of the Euclidean distances and coordinates.

Parameters:
dist_matrixndarray

The distance matrix for the partitioning. dist_matrix[i, j] is the Euclidean distance between node i and node j.

dist_titlestr

The title of the histogram of the Euclidean distances.

coordstuple

The coordinates of the nodes. coords[0] is the x-coordinates, coords[1] is the y-coordinates. Can be either angular or Euclidean coordinates.

coord_titlestr

The title of the scatter plot of the coordinates.

labelstuple

The labels of the coordinates. labels[0] is the label of the x-coordinate, labels[1] is the label of the y-coordinate.

distance_unitstr, optional

The unit of the distance. Defaults to “m”.

superblockify.metrics.plot.plot_distance_matrices(metric, name=None)[source]#

Show the distance matrices for the network measures.

Plots all available distance matrices in a single figure.

Parameters:
metricmetrics.Metric

The metric to plot the distance matrices for.

namestr

The name to put into the title of the plot.

Returns:
fig, axesmatplotlib.figure.Figure, matplotlib.axes.Axes

The figure and axes of the plot.

Raises:
ValueError

If no distance matrices are available.

superblockify.metrics.plot.plot_distance_matrices_pairwise_relative_difference(metric, name=None)[source]#

Show the pairwise relative difference between the distance matrices.

Plots the pairwise relative difference between the distance matrices in a single figure. Only plots the lower triangle of the distance matrices. On the diagonal the distance matrices are plotted as in plot_distance_matrices.

Parameters:
metricmetrics.Metric

The metric to plot the distance matrices for.

namestr

The name to put into the title of the plot.

Returns:
fig, axesmatplotlib.figure.Figure, matplotlib.axes.Axes

The figure and axes of the plot.

Raises:
ValueError

If no distance matrices are available.

superblockify.metrics.plot.plot_relative_difference(metric, key_i, key_j, title=None)[source]#

Plot the relative difference between two distance matrices.

Parameters:
metricMetric

The metric to plot the relative difference for.

key_istr

The key of the first distance matrix. This is the baseline.

key_jstr

The key of the second distance matrix. This is the comparison.

titlestr, optional

The title of the plot.

Returns:
fig, axematplotlib.figure.Figure, matplotlib.axes.Axes

The figure and axe of the plot.

superblockify.metrics.plot.plot_relative_increase_on_graph(graph, unit_symbol, **pg_kwargs)[source]#

Plot the relative increase edge wise from attribute rel_increase.

Use :func:metric.measures.write_relative_increase_to_edges to write the relative increase to the edges.

Parameters:
graphnetworkx.Graph

The graph to plot the relative increase on, must have the attribute rel_increase on the edges.

unit_symbolstr

The unit symbol of the metric.

pg_kwargsdict

Keyword arguments for the plot_graph function.

Returns:
fig, axesmatplotlib.figure.Figure, matplotlib.axes.Axes

The figure and axes of the plot.

Module contents#

Metrics init, subpackage for metric calculations.