Python implementation of inflow and outflow centrality — two novel, node-feature-aware centrality metrics inspired by the aggregation approach used in graph convolutional networks (GCNs).
The package also includes two baseline node-weighted metrics — weighted degree centrality and weighted closeness centrality — used in the accompanying paper for comparison.
📄 Paper: Inflow and outflow centrality: novel centrality metrics inspired by graph convolution, published in Applied Network Science. DOI: 10.1007/s41109-026-00782-7
Requires Python ≥ 3.9.
git clone https://github.com/AramPapaz/Inflow-and-Outflow-Centrality.git
cd Inflow-and-Outflow-Centrality
pip install .This installs the inflow_outflow_centrality package along with its dependencies (pandas, numpy, networkx).
For development (editable install):
pip install -e .from inflow_outflow_centrality import utilities
import pickle
# 1. Load your network
interactions = utilities.read_interactions_csv("example/AirportNetwork.csv")
# or for .ea/.ea.gz files:
# interactions = utilities.read_interactions_ea("example/4efm_intsc.ea")
# 2. Provide node features as a dict {node_id: value}
# (or load real features from your own data)
with open("example/population.pkl", "rb") as f:
features = pickle.load(f)
# 3. Compute inflow/outflow centrality
result = utilities.flow_metric(interactions, features, flow_type="both")
print(result.head())
# Other available metrics for comparison:
deg_centrality = utilities.node_weighted_degree_centrality(interactions, features)
close_centrality = utilities.node_weighted_closeness_centrality(interactions, features)python -m inflow_outflow_centrality.utilities <flow_type> <interactions_file> [features_csv]flow_type—in,out, orbothinteractions_file— network file;.ea/.ea.gzfiles are parsed withread_interactions_ea, everything else withread_interactions_csvfeatures_csv(optional) — 2-column CSV ofnode_id, feature_value; if omitted, every node defaults to a feature value of1
The result is written to <flow_type>_output.csv in the same directory as interactions_file.
Example, using the sample data included in this repo:
python -m inflow_outflow_centrality.utilities both example/AirportNetwork.csvThis reproduces example/both_output.csv (comparable to the provided example/inflow_output.csv / example/outflow_output.csv).
| Function | Description |
|---|---|
flow_metric(interactions, features, flow_type) |
Core inflow/outflow centrality computation. Auto-detects an optional float weight column in interactions and, if present, also returns weight-based versions of the metric (WeightSum, WeightedInflowValue, WeightedOutflowValue). |
node_weighted_degree_centrality(interactions, features, f=lambda x: x) |
Node-weighted degree centrality baseline. f can transform feature values before aggregation. |
node_weighted_closeness_centrality(interactions, features, f=lambda x: x) |
Node-weighted closeness centrality baseline. |
read_interactions_csv(csv_path) |
Loads a CSV edge list into the DataFrame format expected by flow_metric. |
read_interactions_ea(ea_path) |
Loads a .ea or .ea.gz interaction file, keeping only rows with combi:all_all in the description and non-negative scores. |
interactions: apandas.DataFramewith two node-id columns (source, target) and an optional third float column for edge weight. Duplicate and self-interactions are automatically removed.features: adictmappingnode_id → feature_value. Values should roughly follow a normal distribution for the metric to behave well. In the example data this is provided as a pickled dict (example/population.pkl), loaded withpickle.load.
flow_metric returns a pandas.DataFrame:
flow_type="in"→Node, InflowValue, Degree(+WeightSum, WeightedInflowValueif weights were provided)flow_type="out"→Node, OutflowValue, Degree(+WeightSum, WeightedOutflowValueif weights were provided)flow_type="both"→Node, InflowValue, OutflowValue, Degree(+ weighted columns if weights were provided)
The example/ folder contains ready-to-use sample data:
AirportNetwork.csv— an airport interaction network4efm_intsc.ea— a residue interaction network in.eaformatpopulation.pkl— node features (population) for use with the airport networkinflow_output.csv,outflow_output.csv— precomputed results for reference/comparison