barabasi_albert_graph
¶
Returns the edges of a random Barabasi-Albert graph (preferential
attachment): each new node is connected to num_edges existing nodes,
chosen with a probability proportional to their degree.
Randomness comes from mx.random, so results are reproducible with
mx.random.seed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_nodes
|
int
|
Number of nodes. |
required |
num_edges
|
int
|
Number of edges added for each new node. |
required |
Returns:
| Type | Description |
|---|---|
array
|
The sorted, undirected int32 |
array
|
self-loops and duplicates. |
Example:
barabasi_albert_graph(5, 2)
# e.g. mx.array([[0, 0, 1, 1, 2, 2, 3, 3, 4, 4],
# [2, 3, 3, 4, 0, 4, 0, 1, 1, 2]])
Source code in mlx_graphs/utils/generators.py
from mlx_graphs.utils import barabasi_albert_graph · mlx_graphs/utils/generators.py