mindspore_gl.graph.norm
- mindspore_gl.graph.norm(edge_index, num_nodes, edge_weight=None, normalization='sym', lambda_max=None, batch=None)[source]
graph laplacian normalization.
- Parameters
edge_index (Tensor) – Edge index. The shape is \((2, N\_e)\) where \(N\_e\) is the number of edges.
num_nodes (int) – Number of nodes.
edge_weight (Tensor) – Edge weights. The shape is \((N\_e)\) where \(N\_e\) is the number of edges. Default:
None
.normalization (str) –
Normalization method. Default:
'sym'
. \((L)\) is normalized matrix, \((D)\) is degree matrix, \((A)\) is adjaceny matrix, \((I)\) is unit matrix.None
: No normalization \(\mathbf{L} = \mathbf{D} - \mathbf{A}\)'sym'
: Symmetric normalization \(\mathbf{L} = \mathbf{I} - \mathbf{D}^{-1/2} \mathbf{A} \mathbf{D}^{-1/2}\)'rw'
: Random-walk normalization \(\mathbf{L} = \mathbf{I} - \mathbf{D}^{-1} \mathbf{A}\)
lambda_max (int, float) – Lambda value of graph. Default:
None
.batch (Tensor) – Batch vector. Default:
None
.
- Returns
edge_index (Tensor) - normalized edge_index.
edge_weight (Tensor) - normalized edge_weight
- Raises
ValueError – if normalization not is
None
or'sym'
or'rw'
.
- Supported Platforms:
Ascend
GPU
Examples
>>> import mindspore as ms >>> from mindspore_gl.graph import norm >>> edge_index = [[1, 1, 2, 2], [0, 2, 0, 1]] >>> edge_index = ms.Tensor(edge_index, ms.int32) >>> num_nodes = 3 >>> edge_index, edge_weight = norm(edge_index, num_nodes) >>> print(edge_index) [[1 1 2 2 0 1 2] [0 2 0 1 0 1 2]] >>> print(edge_weight) [-0. -0.4999999 -0. -0.4999999 1. 1. 1. ]