Skip to content

AverageWeightedPath

AverageWeightedPath(in_graph, label_name, out_folder=None, cohort=None, iterations=1000, weight=‘membership’, method=PathLengthsMethods.Dijkstra, distribution=None, processes=1, verbose=False, save_parameters=False, overwrite=False)

Average Weighted Path

AverageWeightedPath is a script that computes the average weighted shortest path length for a group of nodes. The script will compare the result against a null distribution generated by randomly selecting the same number of nodes and computing the average weighted shortest path length. The script will also compute the p-value for the comparison.

Null Distribution

The null distribution is generated by randomly selecting the same number of nodes as the group of interest and computing the average weighted shortest path length. This process is repeated for a number of iterations (default: 5000) and the resulting distribution is used to compute the p-value. Please note that for large graphs, the null distribution could take a long time to compute. It is recommended to use the –distribution option to provide a pre-computed null distribution of this script has already been run on for the same number of nodes (see below). One could also reduce the number of iterations to speed up the process and have a rough estimate of the p-value.

Cohort Selection

In some case, the graph network file can contain data from multiple cohort at the same time. It might be useful to single out a specific cohort to compute the AWP metric. Using –cohort, the script will fetch data from the specified cohort and filter the –label-name. The AWP will be computed only on subject with the –label-name for the specified cohort. In order for the script to run successfully, your graph network needs to contain the cohort attributes. If it does not, please add it using the AddNodesAttributes script.

Multiprocessing

By default, AverageWeightedPath will use 4 CPUs to compute the null distribution. This can be changed by setting the –processes option.

Method To Compute The Weighted Path

AverageWeightedPath can use different methods to compute the weighted path. The default method is Dijkstra. The other methods are Bellman-Ford and Floyd-Warshall. Please note that the Floyd-Warshall method is not recommended for large graphs. For more details, see [1].

Reference

[1] NetworkX Algorithm (https://networkx.org/documentation/stable/reference/algorithms/generated/networkx.algorithms.shortest_paths.generic.average_shortest_path_length.html#networkx.algorithms.shortest_paths.generic.average_shortest_path_length)

Example Usage

AverageWeightedPath --in-graph ./graph.gml --label-name Group1
--label-name Group2 --out-folder ./results --iterations 5000
--weight membership --method Dijkstra

Parameters

in_graph : Input graph file (.gml).

label_name : Label(s) name(s) to select group(s) of nodes. Can be multiple.

out_folder : Output folder where files will be exported.

cohort: int, optional : Cohort identifier. If your graph contains data from multiple cohort, you can specify the cohort you want to compute the AWP.

iterations : Number of iterations to perform to generate the null distribution.

weight : Name of the edge attributes to use during the weighted path computation

method : Method to use for the estimation of the weighted path.

distribution : Pre-computed null distribution, needs to be an .xlsx file containing label name as –label-name.

processes : Number of processes to use to compute the null distribution.

verbose : If true, produce verbose output.

save_parameters : If true, will save input parameters to .txt file.

overwrite : If true, force overwriting of existing output files.