Egonets

The standard pipeline produces one embedding per graph. For node-level problems — like flagging anomalous nodes — NEExT decomposes each graph into one subgraph per node, called an egonet. Running the usual feature → embedding pipeline on that EgonetCollection then yields one embedding per node, where each embedding represents that node’s neighborhood.

k-hop egonets

compute_k_hop_egonets extracts each node’s k-hop neighborhood as its own graph.

khop.py
egonets = nxt.compute_k_hop_egonets(
  graph_collection=graphs,
  k_hop=2,
  egonet_feature_target="is_outlier",   # node attribute to carry as the egonet label
)

# From here it's the normal pipeline — but each row is now a node.
features = nxt.compute_node_features(egonets, feature_list=["all"])
embeddings = nxt.compute_graph_embeddings(
  egonets, features, embedding_algorithm="approx_wasserstein", embedding_dimension=16,
)
ParameterDefaultMeaning
k_hop1Number of hops in each node’s neighborhood
egonet_feature_targetNoneNode attribute to use as the egonet’s label
skip_featuresNoneNode features to exclude from egonets
nodes_to_sampleNoneDict mapping graph_id → node IDs to always include
sample_fraction1.0Fraction of nodes to build egonets for
random_seed13Seed for node sampling

egonet_feature_target lets each egonet inherit a per-node label (e.g. "is_outlier") so you can train a model on node-level targets — the anomaly-detection preset marks nodes with is_outlier.

Leiden community egonets

Instead of fixed-radius neighborhoods, compute_leiden_egonets builds egonets from communities found by the Leiden algorithm. This requires the iGraph backend (load with graph_type="igraph").

leiden.py
graphs = nxt.read_from_csv(
  edges_path="edges.csv",
  node_graph_mapping_path="node_graph_mapping.csv",
  graph_type="igraph",
)

egonets = nxt.compute_leiden_egonets(
  graph_collection=graphs,
  n_iterations=10,
  resolution=1.0,
)
ParameterDefaultMeaning
egonet_feature_targetNoneNode attribute to use as the egonet’s label
skip_featuresNoneNode features to exclude from egonets
n_iterations10Leiden iterations
resolution1.0Leiden resolution (higher → more, smaller communities)

Both methods return an EgonetCollection, which behaves like a GraphCollection for every downstream step.