homophily
¶
homophily(
edge_index: array,
node_labels: array,
method: Literal["edge", "node"] = "edge",
) -> float
Computes the homophily of a graph: how often connected nodes share the same label.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge_index
|
array
|
a [2, num_edges] array representing the source and target nodes of each edge |
required |
node_labels
|
array
|
Array of shape |
required |
method
|
Literal['edge', 'node']
|
The homophily measure:
Default: |
'edge'
|
Returns:
| Type | Description |
|---|---|
float
|
The homophily ratio, between 0 and 1. It is |
float
|
(no edges for |
Example:
edge_index = mx.array([[0, 1, 2, 3], [1, 2, 0, 4]])
node_labels = mx.array([0, 0, 0, 0, 1])
homophily(edge_index, node_labels, method="edge")
# 0.75
homophily(edge_index, node_labels, method="node")
# 0.6
Source code in mlx_graphs/utils/laplacian.py
from mlx_graphs.utils import homophily · mlx_graphs/utils/laplacian.py