yawning_titan.experiment_helpers.graph_metrics#

Collection of functions to help generating metrics and summary statistics for networkx graphs.

Functions

flatten_list

Take a list of lists and flattens them into a single list.

geometric_mean_overflow

Calculate the geometric mean accounting for the potential of overflow through using logs.

get_assortativity_metrics

Get assortativity metrics for an input graph using networkx's in-built algorithms.

get_func_summary_statistics

Generate a list of summary statistics based on the output of a networkx in-build algorithm.

get_graph_metric_bundle

Generate a graph metric bundle.

pprint_metric_table

Pretty prints graph metrics to the terminal using the tabulate module.

yawning_titan.experiment_helpers.graph_metrics.geometric_mean_overflow(input_list)[source]#

Calculate the geometric mean accounting for the potential of overflow through using logs.

Parameters:

input_list – A list of values

Returns:

Geometric mean as a float

Note: There is actually a function included in the ‘statistics’ python module that does this but is only available in python 3.8 onwards

yawning_titan.experiment_helpers.graph_metrics.flatten_list(list_input)[source]#

Take a list of lists and flattens them into a single list.

Parameters:

list_input – The input list of lists to be processed

Returns:

A single list containing all elements

yawning_titan.experiment_helpers.graph_metrics.get_assortativity_metrics(graph)[source]#

Get assortativity metrics for an input graph using networkx’s in-built algorithms.

Parameters:

graph – A networkx graph

Returns:

A two-tuple with the metrics

yawning_titan.experiment_helpers.graph_metrics.get_func_summary_statistics(func)[source]#

Generate a list of summary statistics based on the output of a networkx in-build algorithm.

Parameters:

func – A networkx algorithm function

Returns:

  • Arithmetic Mean

  • Geometric Mean

  • Harmonic Mean

  • Standard Deviation

  • Variance

  • Median

Return type:

A list containing

Example

> generate_summary_statistics(nx.degree_centrality(graph)) > (3.3095238095238098, 2.5333333333333337, 2.9015675801088014, 1.9824913893491538, 2.620181405895692, 3.0)

yawning_titan.experiment_helpers.graph_metrics.get_graph_metric_bundle(graph)[source]#

Generate a graph metric bundle.

A graph metric bundle includes the summary statistics for a collection of networkx in-built algorithms.

Algorithms used:
  • Average Degree Connectivity

  • Closeness Centrality

  • Degree Centrality

  • Eigenvector Centrality

  • Communicability Between-ness Centrality

Parameters:

graph – A networkx graph

Returns:

A list of lists containing the metrics

yawning_titan.experiment_helpers.graph_metrics.pprint_metric_table(metric_output, headers=None)[source]#

Pretty prints graph metrics to the terminal using the tabulate module.

Parameters:
  • metric_output – A list of lists containing the values to be printed.

  • headers – A list of heading names (optional)

Returns:

A formatted table to terminal