Skip to content

Algorithms

nx-neptune algorithms map NetworkX calls to Amazon Neptune Analytics functions. For a complete listing of Neptune Analytics algorithms, see the Neptune Analytics documentation.

Iterate over edges in a breadth-first search starting at source.

@configure_if_nx_active()
def bfs_edges(
neptune_graph: NeptuneGraph,
source,
reverse=False,
depth_limit=None,
sort_neighbors=None,
vertex_label: Optional[str] = None,
edge_labels: Optional[List] = None,
concurrency: Optional[int] = None,
):
ParameterTypeDescription
sourcenodeStarting node for BFS
reverseboolTraverse directed graph in reverse
depth_limitintMaximum search depth
sort_neighborsfunction⚠️ Not supported in Neptune Analytics
vertex_labelstrVertex label filter
edge_labelslistEdge label filter
concurrencyintThread count (0 = all available)

Yields: Edges in the BFS starting from source.


Find all nodes at a given distance from a source node using BFS-Levels.

@configure_if_nx_active()
def descendants_at_distance(
neptune_graph: NeptuneGraph,
source,
distance: int,
edge_labels: Optional[List] = None,
vertex_label: Optional[str] = None,
traversal_direction: Optional[str] = None,
concurrency: Optional[int] = None,
):
ParameterTypeDescription
sourcenodeStarting node
distanceintDistance from source
edge_labelslistEdge label filter
vertex_labelstrVertex label filter
traversal_directionstr"outbound" or "inbound"
concurrencyintThread count

Returns: set() of descendants at the given distance.


Return all nodes grouped by their BFS level from the source.

@configure_if_nx_active()
def bfs_layers(
neptune_graph: NeptuneGraph,
sources,
edge_labels: Optional[List] = None,
vertex_label: Optional[str] = None,
traversal_direction: Optional[str] = None,
concurrency: Optional[int] = None,
):

Yields: Lists of nodes at the same distance from sources.


Execute the PageRank algorithm on the graph.

@configure_if_nx_active()
def pagerank(
neptune_graph: NeptuneGraph,
alpha: float,
personalization: Optional[Dict],
max_iter: int,
tol: float,
nstart: Optional[Dict],
weight: Optional[str] = None,
dangling: Optional[Dict] = None,
vertex_label: Optional[str] = None,
edge_labels: Optional[List] = None,
concurrency: Optional[int] = None,
traversal_direction: Optional[str] = None,
edge_weight_property: Optional[str] = None,
edge_weight_type: Optional[str] = None,
source_nodes: Optional[List] = None,
source_weights: Optional[List] = None,
write_property: Optional[str] = None,
):
ParameterTypeDescription
alphafloatDamping parameter
personalizationdict⚠️ Not supported in Neptune Analytics
max_iterintMaximum iterations
tolfloatConvergence tolerance
nstartdict⚠️ Not supported in Neptune Analytics
weightstr⚠️ Not supported in Neptune Analytics
danglingdict⚠️ Not supported in Neptune Analytics
vertex_labelstrVertex label filter
edge_labelslistEdge label filter
concurrencyintThread count
traversal_directionstr"outbound" or "inbound"
edge_weight_propertystrWeight property for weighted PageRank
edge_weight_typestr"int", "long", "float", "double"
source_nodeslistPersonalized source nodes
source_weightslistPersonalization weight list
write_propertystrPersist results as node property

Returns: Dictionary of {node_id: pagerank_score}, or empty dict when write_property is specified.


Compute degree centrality for nodes.

@configure_if_nx_active()
def degree_centrality(
neptune_graph: NeptuneGraph,
vertex_label: Optional[str] = None,
edge_labels: Optional[List] = None,
concurrency: Optional[int] = None,
write_property: Optional[str] = None,
):

Returns: Dictionary of {node_id: degree} pairs.

Variants: in_degree_centrality (inbound edges), out_degree_centrality (outbound edges) — same signature.


Compute closeness centrality for nodes.

@configure_if_nx_active()
def closeness_centrality(
neptune_graph: NeptuneGraph,
u=None,
distance=None,
wf_improved=True,
num_sources: Optional[int] = None,
edge_labels: Optional[List] = None,
vertex_label: Optional[str] = None,
traversal_direction: Optional[str] = None,
concurrency: Optional[int] = None,
write_property: Optional[str] = None,
):
ParameterTypeDescription
unodeLimit computation to a single node
distance⚠️ Not supported
wf_improvedboolUse Wasserman-Faust improved formula
num_sourcesintApproximate with N source nodes (omit for exact)
traversal_directionstr"outbound" or "inbound"

Returns: Dictionary of {node_id: closeness_score}.


Execute the Louvain community detection algorithm.

@configure_if_nx_active()
def louvain_communities(
neptune_graph: NeptuneGraph,
weight: str,
resolution: float,
threshold: float,
max_level: Optional[int],
seed: Optional[int],
edge_weight_property: Optional[str] = None,
edge_weight_type: Optional[str] = None,
edge_labels: Optional[List] = None,
max_iterations: Optional[int] = None,
concurrency: Optional[int] = None,
level_tolerance: Optional[float] = None,
write_property: Optional[str] = None,
):
ParameterTypeDescription
weightstrEdge weight attribute
resolutionfloat⚠️ Not supported in Neptune Analytics
thresholdfloatModularity gain threshold
max_levelintMaximum hierarchy levels
seedint⚠️ Not supported in Neptune Analytics
edge_weight_propertystrWeight property
edge_weight_typestr"int", "long", "float", "double"
max_iterationsintMaximum iterations
level_tolerancefloatMinimum modularity change per level

Returns: List of sets (communities).


Execute the Label Propagation community detection algorithm.

@configure_if_nx_active()
def label_propagation_communities(
neptune_graph: NeptuneGraph,
edge_labels: Optional[List] = None,
vertex_label: Optional[str] = None,
vertex_weight_property: Optional[str] = None,
vertex_weight_type: Optional[str] = None,
edge_weight_property: Optional[str] = None,
edge_weight_type: Optional[str] = None,
max_iterations: Optional[int] = None,
traversal_direction: Optional[str] = None,
concurrency: Optional[int] = None,
write_property: Optional[str] = None,
):

Returns: Dictionary of community items to members.

Variants: fast_label_propagation_communities, asyn_lpa_communities — same parameters plus weight and seed.